Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,40 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
from typing import List
import importlib
import urllib.parse
from ._recovery_services_backup_client import RecoveryServicesBackupClient as RecoveryServicesBackupClientGenerated
from azure.core.pipeline.policies import SansIOHTTPPolicy

class RemoveDuplicateParamsPolicy(SansIOHTTPPolicy):
def __init__(self, duplicate_param_names):
# type: (List[str]) -> None
self.duplicate_param_names = duplicate_param_names

def on_request(self, request):
parsed_url = urllib.parse.urlparse(request.http_request.url)
query_params = urllib.parse.parse_qs(parsed_url.query)
filtered_query_params = {
k: v[-1:] if k in self.duplicate_param_names else v
for k, v in query_params.items()
}
request.http_request.url = request.http_request.url.replace(parsed_url.query, "") + urllib.parse.urlencode(filtered_query_params, doseq=True)
return super().on_request(request)

DUPLICATE_PARAMS_POLICY = RemoveDuplicateParamsPolicy(duplicate_param_names=["$filter", "$skiptoken", "api-version"])

class RecoveryServicesBackupClient(RecoveryServicesBackupClientGenerated):
def __init__(self, credential, *args, **kwargs):
Comment thread
msyyc marked this conversation as resolved.
Outdated
per_call_policies = kwargs.pop("per_call_policies", [])
try:
per_call_policies.append(DUPLICATE_PARAMS_POLICY)
except AttributeError:
per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY]
super().__init__(credential, *args, per_call_policies=per_call_policies, **kwargs)

# This file is used for handwritten extensions to the generated code. Example:
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
def patch_sdk():
pass
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.activestamp")
curr_package.RecoveryServicesBackupClient = RecoveryServicesBackupClient
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
import importlib
from .._patch import DUPLICATE_PARAMS_POLICY
from ._recovery_services_backup_client import RecoveryServicesBackupClient as RecoveryServicesBackupClientGenerated

class RecoveryServicesBackupClient(RecoveryServicesBackupClientGenerated):
def __init__(self, credential, *args, **kwargs):
per_call_policies = kwargs.pop("per_call_policies", [])
try:
per_call_policies.append(DUPLICATE_PARAMS_POLICY)
except AttributeError:
per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY]
super().__init__(credential, *args, per_call_policies=per_call_policies, **kwargs)

# This file is used for handwritten extensions to the generated code. Example:
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
def patch_sdk():
pass
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.activestamp.aio")
curr_package.RecoveryServicesBackupClient = RecoveryServicesBackupClient
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,40 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
from typing import List
import importlib
import urllib.parse
from ._recovery_services_backup_passive_client import RecoveryServicesBackupPassiveClient as RecoveryServicesBackupPassiveClientGenerated
from azure.core.pipeline.policies import SansIOHTTPPolicy

class RemoveDuplicateParamsPolicy(SansIOHTTPPolicy):
def __init__(self, duplicate_param_names):
# type: (List[str]) -> None
self.duplicate_param_names = duplicate_param_names

def on_request(self, request):
parsed_url = urllib.parse.urlparse(request.http_request.url)
query_params = urllib.parse.parse_qs(parsed_url.query)
filtered_query_params = {
k: v[-1:] if k in self.duplicate_param_names else v
for k, v in query_params.items()
}
request.http_request.url = request.http_request.url.replace(parsed_url.query, "") + urllib.parse.urlencode(filtered_query_params, doseq=True)
return super().on_request(request)

DUPLICATE_PARAMS_POLICY = RemoveDuplicateParamsPolicy(duplicate_param_names=["$filter", "$skiptoken", "api-version"])

class RecoveryServicesBackupPassiveClient(RecoveryServicesBackupPassiveClientGenerated):
def __init__(self, *args, **kwargs):
per_call_policies = kwargs.pop("per_call_policies", [])
try:
per_call_policies.append(DUPLICATE_PARAMS_POLICY)
except AttributeError:
per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY]
super().__init__(*args, per_call_policies=per_call_policies, **kwargs)

# This file is used for handwritten extensions to the generated code. Example:
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
def patch_sdk():
pass
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.passivestamp")
curr_package.RecoveryServicesBackupPassiveClient = RecoveryServicesBackupPassiveClient
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
import importlib
from .._patch import DUPLICATE_PARAMS_POLICY
from ._recovery_services_backup_passive_client import RecoveryServicesBackupPassiveClient as RecoveryServicesBackupPassiveClientGenerated

class RecoveryServicesBackupPassiveClient(RecoveryServicesBackupPassiveClientGenerated):
def __init__(self, *args, **kwargs):
per_call_policies = kwargs.pop("per_call_policies", [])
try:
per_call_policies.append(DUPLICATE_PARAMS_POLICY)
except AttributeError:
per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY]
super().__init__(*args, per_call_policies=per_call_policies, **kwargs)

# This file is used for handwritten extensions to the generated code. Example:
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
def patch_sdk():
pass
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.passivestamp.aio")
curr_package.RecoveryServicesBackupPassiveClient = RecoveryServicesBackupPassiveClient