3333import functools
3434import logging
3535from datetime import datetime
36+ from functools import wraps
3637
3738from contextlib import contextmanager
3839
5556DEFAULT_PORT = "8089"
5657DEFAULT_SCHEME = "https"
5758
58- def log_duration (f ):
59+ def _log_duration (f ):
60+ @wraps (f )
5961 def new_f (* args , ** kwargs ):
6062 start_time = datetime .now ()
6163 val = f (* args , ** kwargs )
@@ -132,7 +134,7 @@ def __add__(self, other):
132134 def __radd__ (self , other ):
133135 """other + self
134136
135- If *other* is not a ``UrlEncoded``, URL encode it before
137+ If *other* is not a ``UrlEncoded``, URL _encode it before
136138 adding it.
137139 """
138140 if isinstance (other , UrlEncoded ):
@@ -210,7 +212,7 @@ def f():
210212 return 42
211213 print _authentication(f)
212214 """
213- @functools . wraps (request_fun )
215+ @wraps (request_fun )
214216 def wrapper (self , * args , ** kwargs ):
215217 if self .token is NoAuthenticationToken :
216218 # Not yet logged in.
@@ -443,7 +445,7 @@ def connect(self):
443445 return sock
444446
445447 @_authentication
446- @log_duration
448+ @_log_duration
447449 def delete (self , path_segment , owner = None , app = None , sharing = None , ** query ):
448450 """DELETE at *path_segment* with the given namespace and query.
449451
@@ -493,7 +495,7 @@ def delete(self, path_segment, owner=None, app=None, sharing=None, **query):
493495 return response
494496
495497 @_authentication
496- @log_duration
498+ @_log_duration
497499 def get (self , path_segment , owner = None , app = None , sharing = None , ** query ):
498500 """GET from *path_segment* with the given namespace and query.
499501
@@ -543,7 +545,7 @@ def get(self, path_segment, owner=None, app=None, sharing=None, **query):
543545 return response
544546
545547 @_authentication
546- @log_duration
548+ @_log_duration
547549 def post (self , path_segment , owner = None , app = None , sharing = None , headers = [], ** query ):
548550 """POST to *path_segment* with the given namespace and query.
549551
@@ -612,7 +614,7 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=[], **q
612614 return response
613615
614616 @_authentication
615- @log_duration
617+ @_log_duration
616618 def request (self , path_segment , method = "GET" , headers = [], body = "" ,
617619 owner = None , app = None , sharing = None ):
618620 """Issue an arbitrary HTTP request to *path_segment*.
@@ -868,11 +870,11 @@ def __init__(self, response):
868870# }
869871#
870872
871- # Encode the given kwargs as a query string. This wrapper will also encode
873+ # Encode the given kwargs as a query string. This wrapper will also _encode
872874# a list value as a sequence of assignemnts to the corresponding arg name,
873875# for example an argument such as 'foo=[1,2,3]' will be encoded as
874876# 'foo=1&foo=2&foo=3'.
875- def encode (** kwargs ):
877+ def _encode (** kwargs ):
876878 items = []
877879 for key , value in kwargs .iteritems ():
878880 if isinstance (value , list ):
@@ -882,7 +884,7 @@ def encode(**kwargs):
882884 return urllib .urlencode (items )
883885
884886# Crack the given url into (scheme, host, port, path)
885- def spliturl (url ):
887+ def _spliturl (url ):
886888 scheme , opaque = urllib .splittype (url )
887889 netloc , path = urllib .splithost (opaque )
888890 host , port = urllib .splitport (netloc )
@@ -903,7 +905,7 @@ def delete(self, url, headers=None, **kwargs):
903905 # url is already a UrlEncoded. We have to manually declare
904906 # the query to be encoded or it will get automatically URL
905907 # encoded by being appended to url.
906- url = url + UrlEncoded ('?' + encode (** kwargs ), skip_encode = True )
908+ url = url + UrlEncoded ('?' + _encode (** kwargs ), skip_encode = True )
907909 message = {
908910 'method' : "DELETE" ,
909911 'headers' : headers ,
@@ -916,7 +918,7 @@ def get(self, url, headers=None, **kwargs):
916918 # url is already a UrlEncoded. We have to manually declare
917919 # the query to be encoded or it will get automatically URL
918920 # encoded by being appended to url.
919- url = url + UrlEncoded ('?' + encode (** kwargs ), skip_encode = True )
921+ url = url + UrlEncoded ('?' + _encode (** kwargs ), skip_encode = True )
920922 return self .request (url , { 'method' : "GET" , 'headers' : headers })
921923
922924 def post (self , url , headers = None , ** kwargs ):
@@ -927,9 +929,9 @@ def post(self, url, headers=None, **kwargs):
927929 if 'body' in kwargs :
928930 body = kwargs .pop ('body' )
929931 if len (kwargs ) > 0 :
930- url = url + UrlEncoded ('?' + encode (** kwargs ), skip_encode = True )
932+ url = url + UrlEncoded ('?' + _encode (** kwargs ), skip_encode = True )
931933 else :
932- body = encode (** kwargs )
934+ body = _encode (** kwargs )
933935 message = {
934936 'method' : "POST" ,
935937 'headers' : headers ,
@@ -1015,7 +1017,7 @@ def connect(scheme, host, port):
10151017 raise ValueError ("unsupported scheme: %s" % scheme )
10161018
10171019 def request (url , message , ** kwargs ):
1018- scheme , host , port , path = spliturl (url )
1020+ scheme , host , port , path = _spliturl (url )
10191021 body = message .get ("body" , "" )
10201022 head = {
10211023 "Content-Length" : str (len (body )),
0 commit comments