<s> import os <EOL> import sys <EOL> import copy <EOL> import requests <EOL> from abc import ABCMeta <EOL> from azure . common import ( <EOL> AzureException , <EOL> ) <EOL> from . _constants import ( <EOL> _USER_AGENT_STRING , <EOL> _SOCKET_TIMEOUT <EOL> ) <EOL> from . _http import HTTPError <EOL> from . _http . httpclient import _HTTPClient <EOL> from . _serialization import ( <EOL> _storage_error_handler , <EOL> _update_request , <EOL> ) <EOL> from . _error import ( <EOL> _ERROR_STORAGE_MISSING_INFO , <EOL> ) <EOL> class StorageClient ( object ) : <EOL> '''<STR_LIT>''' <EOL> __metaclass__ = ABCMeta <EOL> def __init__ ( self , connection_params ) : <EOL> '''<STR_LIT>''' <EOL> self . account_name = connection_params . account_name <EOL> self . account_key = connection_params . account_key <EOL> self . sas_token = connection_params . sas_token <EOL> self . protocol = connection_params . protocol <EOL> self . primary_endpoint = connection_params . primary_endpoint <EOL> self . secondary_endpoint = connection_params . secondary_endpoint <EOL> self . request_session = connection_params . request_session <EOL> self . _httpclient = _HTTPClient ( <EOL> service_instance = self , <EOL> protocol = self . protocol , <EOL> request_session = connection_params . request_session or requests . Session ( ) , <EOL> user_agent = _USER_AGENT_STRING , <EOL> timeout = _SOCKET_TIMEOUT , <EOL> ) <EOL> self . _filter = self . _perform_request_worker <EOL> def with_filter ( self , filter ) : <EOL> '''<STR_LIT>''' <EOL> res = copy . deepcopy ( self ) <EOL> old_filter = self . _filter <EOL> def new_filter ( request ) : <EOL> return filter ( request , old_filter ) <EOL> res . _filter = new_filter <EOL> return res <EOL> def set_proxy ( self , host , port , user = None , password = None ) : <EOL> '''<STR_LIT>''' <EOL> self . _httpclient . set_proxy ( host , port , user , password ) <EOL> def _get_host ( self ) : <EOL> return self . primary_endpoint <EOL> def _perform_request_worker ( self , request ) : <EOL> _update_request ( request ) <EOL> self . authentication . sign_request ( request ) <EOL> return self . _httpclient . perform_request ( request ) <EOL> def _perform_request ( self , request , encoding = '<STR_LIT:utf-8>' ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> resp = self . _filter ( request ) <EOL> if sys . version_info >= ( <NUM_LIT:3> , ) and isinstance ( resp , bytes ) and encoding : <EOL> resp = resp . decode ( encoding ) <EOL> except HTTPError as ex : <EOL> _storage_error_handler ( ex ) <EOL> except Exception as ex : <EOL> if sys . version_info >= ( <NUM_LIT:3> , ) : <EOL> raise AzureException <EOL> else : <EOL> raise AzureException ( '<STR_LIT>' . format ( ex . __class__ . __name__ , ex . args [ <NUM_LIT:0> ] ) ) <EOL> return resp </s>
