77"""
88import time
99
10- from .consts import API_PUBLIC_ENDPOINT , API_PRIVATE_ENDPOINT , USER_AGENT
11- from .transports import make_xml_rpc_api_call
12- from .auth import TokenAuthentication
13- from .config import get_client_settings
14-
10+ from SoftLayer import auth as slauth
11+ from SoftLayer import config
12+ from SoftLayer import consts
13+ from SoftLayer import transports
1514
15+ API_PUBLIC_ENDPOINT = consts .API_PUBLIC_ENDPOINT
16+ API_PRIVATE_ENDPOINT = consts .API_PRIVATE_ENDPOINT
1617__all__ = ['Client' , 'TimedClient' , 'API_PUBLIC_ENDPOINT' ,
1718 'API_PRIVATE_ENDPOINT' ]
1819
2930
3031
3132class Client (object ):
32- """ A SoftLayer API client.
33+ """A SoftLayer API client.
3334
3435 :param username: an optional API username if you wish to bypass the
3536 package's built-in username
@@ -58,13 +59,13 @@ class Client(object):
5859 def __init__ (self , username = None , api_key = None , endpoint_url = None ,
5960 timeout = None , auth = None , config_file = None , proxy = None ):
6061
61- settings = get_client_settings (username = username ,
62- api_key = api_key ,
63- endpoint_url = endpoint_url ,
64- timeout = timeout ,
65- auth = auth ,
66- proxy = proxy ,
67- config_file = config_file )
62+ settings = config . get_client_settings (username = username ,
63+ api_key = api_key ,
64+ endpoint_url = endpoint_url ,
65+ timeout = timeout ,
66+ auth = auth ,
67+ proxy = proxy ,
68+ config_file = config_file )
6869 self .auth = settings .get ('auth' )
6970 self .endpoint_url = (
7071 settings .get ('endpoint_url' ) or API_PUBLIC_ENDPOINT ).rstrip ('/' )
@@ -78,8 +79,7 @@ def __init__(self, username=None, api_key=None, endpoint_url=None,
7879 def authenticate_with_password (self , username , password ,
7980 security_question_id = None ,
8081 security_question_answer = None ):
81- """ Performs Username/Password Authentication and gives back an auth
82- handler to use to create a client that uses token-based auth.
82+ """Performs Username/Password Authentication
8383
8484 :param string username: your SoftLayer username
8585 :param string password: your SoftLayer password
@@ -94,11 +94,11 @@ def authenticate_with_password(self, username, password,
9494 password ,
9595 security_question_id ,
9696 security_question_answer )
97- self .auth = TokenAuthentication (res ['userId' ], res ['hash' ])
97+ self .auth = slauth . TokenAuthentication (res ['userId' ], res ['hash' ])
9898 return res ['userId' ], res ['hash' ]
9999
100100 def __getitem__ (self , name ):
101- """ Get a SoftLayer Service.
101+ """Get a SoftLayer Service.
102102
103103 :param name: The name of the service. E.G. Account
104104
@@ -112,7 +112,7 @@ def __getitem__(self, name):
112112 return Service (self , name )
113113
114114 def call (self , service , method , * args , ** kwargs ):
115- """ Make a SoftLayer API call
115+ """Make a SoftLayer API call
116116
117117 :param service: the name of the SoftLayer API service
118118 :param method: the method to call on the service
@@ -162,7 +162,7 @@ def call(self, service, method, *args, **kwargs):
162162 }
163163
164164 http_headers = {
165- 'User-Agent' : USER_AGENT ,
165+ 'User-Agent' : consts . USER_AGENT ,
166166 'Content-Type' : 'application/xml' ,
167167 }
168168
@@ -174,17 +174,17 @@ def call(self, service, method, *args, **kwargs):
174174 http_headers .update (kwargs .get ('raw_headers' ))
175175
176176 uri = '/' .join ([self .endpoint_url , service ])
177- return make_xml_rpc_api_call (uri , method , args ,
178- headers = headers ,
179- http_headers = http_headers ,
180- timeout = self .timeout ,
181- proxy = self .proxy )
177+ return transports . make_xml_rpc_api_call (uri , method , args ,
178+ headers = headers ,
179+ http_headers = http_headers ,
180+ timeout = self .timeout ,
181+ proxy = self .proxy )
182182
183183 __call__ = call
184184
185185 def iter_call (self , service , method ,
186186 chunk = 100 , limit = None , offset = 0 , * args , ** kwargs ):
187- """ A generator that deals with paginating through results.
187+ """A generator that deals with paginating through results.
188188
189189 :param service: the name of the SoftLayer API service
190190 :param method: the method to call on the service
@@ -234,7 +234,7 @@ def iter_call(self, service, method,
234234 break
235235
236236 def __format_object_mask (self , objectmask , service ):
237- """ Format new and old style object masks into proper headers.
237+ """Format new and old style object masks into proper headers.
238238
239239 :param objectmask: a string- or dict-based object mask
240240 :param service: a SoftLayer API service name
@@ -246,15 +246,15 @@ def __format_object_mask(self, objectmask, service):
246246 mheader = self ._prefix + 'ObjectMask'
247247
248248 objectmask = objectmask .strip ()
249- if not objectmask .startswith ('mask' ) \
250- and not objectmask .startswith ('[' ):
249+ if ( not objectmask .startswith ('mask' )
250+ and not objectmask .startswith ('[' )) :
251251 objectmask = "mask[%s]" % objectmask
252252
253253 return {mheader : {'mask' : objectmask }}
254254
255255 def __repr__ (self ):
256- return "<Client: endpoint=%s, user=%r>" \
257- % ( self . endpoint_url , self .auth )
256+ return "<Client: endpoint=%s, user=%r>" % ( self . endpoint_url ,
257+ self .auth )
258258
259259 __str__ = __repr__
260260
@@ -263,19 +263,20 @@ def __len__(self):
263263
264264
265265class TimedClient (Client ):
266- """ Subclass of Client()
266+ """Client that records API call timings.
267267
268268 Using this class will time every call to the API and store it in an
269269 internal list. This will have a slight impact on your client's memory
270270 usage and performance. You should only use this for debugging.
271+
271272 """
272273
273274 def __init__ (self , * args , ** kwargs ):
274275 self .last_calls = []
275276 super (TimedClient , self ).__init__ (* args , ** kwargs )
276277
277278 def call (self , service , method , * args , ** kwargs ):
278- """ See Client.call for documentation. """
279+ """See Client.call for documentation."""
279280 start_time = time .time ()
280281 result = super (TimedClient , self ).call (service , method , * args ,
281282 ** kwargs )
@@ -285,7 +286,7 @@ def call(self, service, method, *args, **kwargs):
285286 return result
286287
287288 def get_last_calls (self ):
288- """ Retrieves the last_calls property.
289+ """Retrieves the last_calls property.
289290
290291 This property will contain a list of tuples in the form
291292 ('SERVICE.METHOD', initiated_utc_timestamp, execution_time)
@@ -296,7 +297,8 @@ def get_last_calls(self):
296297
297298
298299class Service (object ):
299- """ A SoftLayer Service.
300+ """A SoftLayer Service.
301+
300302 :param client: A SoftLayer.API.Client instance
301303 :param name str: The service name
302304
@@ -306,7 +308,7 @@ def __init__(self, client, name):
306308 self .name = name
307309
308310 def call (self , name , * args , ** kwargs ):
309- """ Make a SoftLayer API call
311+ """Make a SoftLayer API call.
310312
311313 :param method: the method to call on the service
312314 :param \\ *args: (optional) arguments for the remote call
@@ -333,7 +335,7 @@ def call(self, name, *args, **kwargs):
333335 __call__ = call
334336
335337 def iter_call (self , name , * args , ** kwargs ):
336- """ A generator that deals with paginating through results.
338+ """A generator that deals with paginating through results.
337339
338340 :param method: the method to call on the service
339341 :param integer chunk: result size for each API call
0 commit comments