1717A client library for Google's discovery based APIs.
1818"""
1919from __future__ import absolute_import
20- import six
2120
2221__author__ = "[email protected] (Joe Gregorio)" 2322__all__ = ["build" , "build_from_document" , "fix_method_name" , "key2param" ]
2423
25- from six .moves import http_client
26- from six .moves .urllib .parse import urljoin
27-
28-
2924# Standard library imports
3025import copy
3126from collections import OrderedDict
32-
33- try :
34- from email .generator import BytesGenerator
35- except ImportError :
36- from email .generator import Generator as BytesGenerator
27+ import collections .abc
28+ from email .generator import BytesGenerator
3729from email .mime .multipart import MIMEMultipart
3830from email .mime .nonmultipart import MIMENonMultipart
31+ import http .client as http_client
32+ import io
3933import json
4034import keyword
4135import logging
4236import mimetypes
4337import os
4438import re
39+ import urllib
4540
4641# Third-party imports
4742import httplib2
@@ -506,7 +501,7 @@ def build_from_document(
506501
507502 if client_options is None :
508503 client_options = google .api_core .client_options .ClientOptions ()
509- if isinstance (client_options , six . moves . collections_abc .Mapping ):
504+ if isinstance (client_options , collections . abc .Mapping ):
510505 client_options = google .api_core .client_options .from_dict (client_options )
511506
512507 if http is not None :
@@ -519,9 +514,9 @@ def build_from_document(
519514 if option is not None :
520515 raise ValueError ("Arguments http and {} are mutually exclusive" .format (name ))
521516
522- if isinstance (service , six . string_types ):
517+ if isinstance (service , str ):
523518 service = json .loads (service )
524- elif isinstance (service , six . binary_type ):
519+ elif isinstance (service , bytes ):
525520 service = json .loads (service .decode ("utf-8" ))
526521
527522 if "rootUrl" not in service and isinstance (http , (HttpMock , HttpMockSequence )):
@@ -534,7 +529,7 @@ def build_from_document(
534529 raise InvalidJsonError ()
535530
536531 # If an API Endpoint is provided on client options, use that as the base URL
537- base = urljoin (service ["rootUrl" ], service ["servicePath" ])
532+ base = urllib . parse . urljoin (service ["rootUrl" ], service ["servicePath" ])
538533 if client_options .api_endpoint :
539534 base = client_options .api_endpoint
540535
@@ -630,7 +625,7 @@ def build_from_document(
630625 if "mtlsRootUrl" in service and (
631626 not client_options or not client_options .api_endpoint
632627 ):
633- mtls_endpoint = urljoin (service ["mtlsRootUrl" ], service ["servicePath" ])
628+ mtls_endpoint = urllib . parse . urljoin (service ["mtlsRootUrl" ], service ["servicePath" ])
634629 use_mtls_endpoint = os .getenv (GOOGLE_API_USE_MTLS_ENDPOINT , "auto" )
635630
636631 if not use_mtls_endpoint in ("never" , "auto" , "always" ):
@@ -759,7 +754,7 @@ def _fix_up_parameters(method_desc, root_desc, http_method, schema):
759754 parameters = method_desc .setdefault ("parameters" , {})
760755
761756 # Add in the parameters common to all methods.
762- for name , description in six . iteritems ( root_desc .get ("parameters" , {})):
757+ for name , description in root_desc .get ("parameters" , {}). items ( ):
763758 parameters [name ] = description
764759
765760 # Add in undocumented query parameters.
@@ -875,7 +870,7 @@ def _urljoin(base, url):
875870 # exception here is the case of media uploads, where url will be an
876871 # absolute url.
877872 if url .startswith ("http://" ) or url .startswith ("https://" ):
878- return urljoin (base , url )
873+ return urllib . parse . urljoin (base , url )
879874 new_base = base if base .endswith ("/" ) else base + "/"
880875 new_url = url [1 :] if url .startswith ("/" ) else url
881876 return new_base + new_url
@@ -943,7 +938,7 @@ def set_parameters(self, method_desc):
943938 """
944939 parameters = method_desc .get ("parameters" , {})
945940 sorted_parameters = OrderedDict (sorted (parameters .items ()))
946- for arg , desc in six . iteritems ( sorted_parameters ):
941+ for arg , desc in sorted_parameters . items ( ):
947942 param = key2param (arg )
948943 self .argmap [param ] = arg
949944
@@ -997,9 +992,9 @@ def createMethod(methodName, methodDesc, rootDesc, schema):
997992 def method (self , ** kwargs ):
998993 # Don't bother with doc string, it will be over-written by createMethod.
999994
1000- for name in six . iterkeys ( kwargs ) :
995+ for name in kwargs :
1001996 if name not in parameters .argmap :
1002- raise TypeError ('Got an unexpected keyword argument "%s"' % name )
997+ raise TypeError ('Got an unexpected keyword argument {}' . format ( name ) )
1003998
1004999 # Remove args that have a value of None.
10051000 keys = list (kwargs .keys ())
@@ -1016,9 +1011,9 @@ def method(self, **kwargs):
10161011 ):
10171012 raise TypeError ('Missing required parameter "%s"' % name )
10181013
1019- for name , regex in six . iteritems ( parameters .pattern_params ):
1014+ for name , regex in parameters .pattern_params . items ( ):
10201015 if name in kwargs :
1021- if isinstance (kwargs [name ], six . string_types ):
1016+ if isinstance (kwargs [name ], str ):
10221017 pvalues = [kwargs [name ]]
10231018 else :
10241019 pvalues = kwargs [name ]
@@ -1029,13 +1024,13 @@ def method(self, **kwargs):
10291024 % (name , pvalue , regex )
10301025 )
10311026
1032- for name , enums in six . iteritems ( parameters .enum_params ):
1027+ for name , enums in parameters .enum_params . items ( ):
10331028 if name in kwargs :
10341029 # We need to handle the case of a repeated enum
10351030 # name differently, since we want to handle both
10361031 # arg='value' and arg=['value1', 'value2']
10371032 if name in parameters .repeated_params and not isinstance (
1038- kwargs [name ], six . string_types
1033+ kwargs [name ], str
10391034 ):
10401035 values = kwargs [name ]
10411036 else :
@@ -1049,7 +1044,7 @@ def method(self, **kwargs):
10491044
10501045 actual_query_params = {}
10511046 actual_path_params = {}
1052- for key , value in six . iteritems ( kwargs ):
1047+ for key , value in kwargs . items ( ):
10531048 to_type = parameters .param_types .get (key , "string" )
10541049 # For repeated parameters we cast each member of the list.
10551050 if key in parameters .repeated_params and type (value ) == type ([]):
@@ -1086,7 +1081,7 @@ def method(self, **kwargs):
10861081
10871082 if media_filename :
10881083 # Ensure we end up with a valid MediaUpload object.
1089- if isinstance (media_filename , six . string_types ):
1084+ if isinstance (media_filename , str ):
10901085 if media_mime_type is None :
10911086 logger .warning (
10921087 "media_mime_type argument not specified: trying to auto-detect for %s" ,
@@ -1144,7 +1139,7 @@ def method(self, **kwargs):
11441139 msgRoot .attach (msg )
11451140 # encode the body: note that we can't use `as_string`, because
11461141 # it plays games with `From ` lines.
1147- fp = six .BytesIO ()
1142+ fp = io .BytesIO ()
11481143 g = _BytesGenerator (fp , mangle_from_ = False )
11491144 g .flatten (msgRoot , unixfrom = False )
11501145 body = fp .getvalue ()
@@ -1218,7 +1213,7 @@ def method(self, **kwargs):
12181213 enumDesc = paramdesc .get ("enumDescriptions" , [])
12191214 if enum and enumDesc :
12201215 docs .append (" Allowed values\n " )
1221- for (name , desc ) in six . moves . zip (enum , enumDesc ):
1216+ for (name , desc ) in zip (enum , enumDesc ):
12221217 docs .append (" %s - %s\n " % (name , desc ))
12231218 if "response" in methodDesc :
12241219 if methodName .endswith ("_media" ):
@@ -1415,7 +1410,7 @@ def new_batch_http_request(callback=None):
14151410
14161411 # Add basic methods to Resource
14171412 if "methods" in resourceDesc :
1418- for methodName , methodDesc in six . iteritems ( resourceDesc ["methods" ]):
1413+ for methodName , methodDesc in resourceDesc ["methods" ]. items ( ):
14191414 fixedMethodName , method = createMethod (
14201415 methodName , methodDesc , rootDesc , schema
14211416 )
@@ -1463,7 +1458,7 @@ def methodResource(self):
14631458
14641459 return (methodName , methodResource )
14651460
1466- for methodName , methodDesc in six . iteritems ( resourceDesc ["resources" ]):
1461+ for methodName , methodDesc in resourceDesc ["resources" ]. items ( ):
14671462 fixedMethodName , method = createResourceMethod (methodName , methodDesc )
14681463 self ._set_dynamic_attr (
14691464 fixedMethodName , method .__get__ (self , self .__class__ )
@@ -1475,7 +1470,7 @@ def _add_next_methods(self, resourceDesc, schema):
14751470 # type either the method's request (query parameters) or request body.
14761471 if "methods" not in resourceDesc :
14771472 return
1478- for methodName , methodDesc in six . iteritems ( resourceDesc ["methods" ]):
1473+ for methodName , methodDesc in resourceDesc ["methods" ]. items ( ):
14791474 nextPageTokenName = _findPageTokenName (
14801475 _methodProperties (methodDesc , schema , "response" )
14811476 )
0 commit comments