-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1632 from microsoft/feature/field-deserializers-s…
…implification-python Feature/field deserializers simplification python
- Loading branch information
Showing
12 changed files
with
138 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .middleware import MiddlewarePipeline | ||
from .parameters_name_decoding_handler import ParametersNameDecodingHandler | ||
from .retry_handler import RetryHandler |
1 change: 1 addition & 0 deletions
1
http/python/requests/http_requests/middleware/options/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .parameters_name_decoding_options import ParametersNameDecodingHandlerOption | ||
from .retry_handler_option import RetryHandlerOptions |
22 changes: 22 additions & 0 deletions
22
http/python/requests/http_requests/middleware/options/parameters_name_decoding_options.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import List | ||
from kiota.abstractions.request_option import RequestOption | ||
|
||
class ParametersNameDecodingHandlerOption(RequestOption): | ||
"""The ParametersNameDecodingOptions request class | ||
""" | ||
|
||
parameters_name_decoding_handler_options_key = "ParametersNameDecodingOptionKey" | ||
|
||
def __init__(self, enable: bool = True, characters_to_decode: List[str] = [".", "-", "~", "$"]) -> None: | ||
"""To create an instance of ParametersNameDecodingHandlerOptions | ||
Args: | ||
enable (bool, optional): - Whether to decode the specified characters in the request query parameters names. | ||
Defaults to True. | ||
characters_to_decode (List[str], optional):- The characters to decode. Defaults to [".", "-", "~", "$"]. | ||
""" | ||
self.enable = enable | ||
self.characters_to_decode = characters_to_decode | ||
|
||
def get_key(self) -> str: | ||
return self.parameters_name_decoding_handler_options_key |
45 changes: 45 additions & 0 deletions
45
http/python/requests/http_requests/middleware/parameters_name_decoding_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Dict | ||
from kiota.abstractions.request_option import RequestOption | ||
from requests import PreparedRequest, Response | ||
|
||
from .middleware import BaseMiddleware | ||
from .options import ParametersNameDecodingHandlerOption | ||
|
||
class ParametersNameDecodingHandler(BaseMiddleware): | ||
|
||
def __init__(self, options: ParametersNameDecodingHandlerOption = ParametersNameDecodingHandlerOption(), **kwargs): | ||
"""Create an instance of ParametersNameDecodingHandler | ||
Args: | ||
options (ParametersNameDecodingHandlerOption, optional): The parameters name decoding handler options value. | ||
Defaults to ParametersNameDecodingHandlerOption | ||
""" | ||
if not options: | ||
raise Exception("The options parameter is required.") | ||
|
||
self.options = options | ||
|
||
def send(self, request: PreparedRequest, request_options: Dict[str, RequestOption], **kwargs) -> Response: | ||
"""To execute the current middleware | ||
Args: | ||
request (PreparedRequest): The prepared request object | ||
request_options (Dict[str, RequestOption]): The request options | ||
Returns: | ||
Response: The response object. | ||
""" | ||
current_options = self.options | ||
options_key = ParametersNameDecodingHandlerOption.parameters_name_decoding_handler_options_key | ||
if request_options and options_key in request_options.keys(): | ||
current_options = request_options[options_key] | ||
|
||
updated_url = request.url | ||
if current_options and current_options.enable and '%' in updated_url and current_options.characters_to_decode: | ||
for char in current_options.characters_to_decode: | ||
encoding = f"{ord(f'{char}:X')}" | ||
updated_url = updated_url.replace(f'%{encoding}', char) | ||
|
||
request.url = updated_url | ||
response = super().send(request, **kwargs) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters