Skip to content

Commit

Permalink
Merge pull request #115 from jignesh-crest/extract-safe-chars
Browse files Browse the repository at this point in the history
Extract safe-characters for each param
  • Loading branch information
omarryhan authored Jan 11, 2023
2 parents e3ebcba + 9f8a1ee commit bf33581
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aiogoogle/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__about__ = "Async Google API client"
__description__ = __about__
__url__ = "https://github.com/omarryhan/aiogoogle"
__version_info__ = ("5", "0", "0")
__version_info__ = ("5", "1", "0")
__version__ = ".".join(__version_info__)
__author__ = "Omar Ryhan"
__author_email__ = "[email protected]"
Expand Down
15 changes: 12 additions & 3 deletions aiogoogle/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def __call__(
download_file=None,
pipe_to=None,
timeout=None,
path_params_safe_chars={},
**uri_params,
) -> Request:
"""
Expand Down Expand Up @@ -429,6 +430,8 @@ def __call__(
timeout (str): total timeout for this request
path_params_safe_chars (dict): Dictionary of safe characters for each path parameter.
**uri_params (dict): path and query, required and optional parameters
Returns:
Expand Down Expand Up @@ -461,7 +464,7 @@ def __call__(

# Build full url minus query & fragment
url = self._build_url(
base_url=base_url, uri_params=uri_params.copy(), validate=validate
base_url=base_url, uri_params=uri_params.copy(), validate=validate, path_params_safe_chars=path_params_safe_chars
)

# Filter out query parameters from all uri_params that were passed to this method
Expand Down Expand Up @@ -610,7 +613,7 @@ def __call__(
callback=lambda res: res, # TODO: get rid of this sorcery.
)

def _build_url(self, base_url, uri_params, validate):
def _build_url(self, base_url, uri_params, validate, path_params_safe_chars):
if self.path_parameters:
# sort path params as sepcified in method_specs.parameterOrder
sorted_required_path_params = (
Expand All @@ -627,7 +630,13 @@ def _build_url(self, base_url, uri_params, validate):
self._validate_url(sorted_required_path_params)

for k, v in sorted_required_path_params.items():
sorted_required_path_params[k] = quote(str(v))
if path_params_safe_chars.get(k):
sorted_required_path_params[k] = quote(
str(v),
safe=path_params_safe_chars[k]
)
else:
sorted_required_path_params[k] = quote(str(v))

# Build full path
# replace named placeholders with empty ones. e.g. {param} --> {}
Expand Down

0 comments on commit bf33581

Please sign in to comment.