@@ -177,7 +177,7 @@ def parse_interfaces(interfaces):
177
177
return dict (parsed_interfaces )
178
178
179
179
180
- class InterfaceNotDefined ( NotImplementedError ):
180
+ class ConfigurationError ( Exception ):
181
181
pass
182
182
183
183
@@ -190,10 +190,6 @@ def __str__(self):
190
190
return '%s: %s' % (self .code , self .message )
191
191
192
192
193
- class InvalidAccessToken (APIError ):
194
- pass
195
-
196
-
197
193
class Result (MutableMapping ):
198
194
def __init__ (self , response ):
199
195
self .response = response
@@ -323,19 +319,19 @@ class Phabricator(Resource):
323
319
def __init__ (self , username = None , certificate = None , host = None ,
324
320
timeout = 5 , response_format = 'json' , token = None , ** kwargs ):
325
321
326
- # Set values in ~/.arcrc as defaults
327
- if ARCRC :
328
- self . host = host if host else ARCRC [ 'hosts' ]. keys ()[ 0 ]
329
- if token or 'token' in ARCRC [ 'hosts' ][ self . host ]:
330
- self . token = token if token else ARCRC [ 'hosts' ][ self . host ][ 'token' ]
331
- else :
332
- self . username = username if username else ARCRC [ 'hosts' ][ self . host ][ 'user' ]
333
- self . certificate = certificate if certificate else ARCRC [ 'hosts' ][ self .host ][ 'cert' ]
334
- else :
335
- self . host = host
336
- self .token = token
337
- self .username = username
338
- self .certificate = certificate
322
+ defined_hosts = ARCRC . get ( 'hosts' , {})
323
+
324
+ try :
325
+ self . host = host if host else defined_hosts . keys ()[ 0 ]
326
+ except IndexError :
327
+ raise ConfigurationError ( "No host found or provided." )
328
+
329
+ current_host_config = defined_hosts . get ( self .host , {})
330
+ self . token = token if token else current_host_config . get ( 'token' )
331
+
332
+ if self .token is None :
333
+ self .username = username if username else current_host_config . get ( 'user' )
334
+ self .certificate = certificate if certificate else current_host_config . get ( 'cert' )
339
335
340
336
self .timeout = timeout
341
337
self .response_format = response_format
0 commit comments