def _to_safe_path_param_name(matched_parameter):
"""Creates a safe string to be used as a regex group name.
Only alphanumeric characters and underscore are allowed in variable name
tokens, and numeric are not allowed as the first character.
We cast the matched_parameter to base32 (since the alphabet is safe),
strip the padding (= not safe) and prepend with _, since we know a token
can begin with underscore.
Args:
matched_parameter: A string containing the parameter matched from the URL
template.
Returns:
A string that's safe to be used as a regex group name.
"""
return '_' + base64.b32encode(matched_parameter).rstrip('=')
评论列表
文章目录