@@ -102,25 +102,22 @@ def authorize(self, login, password, scopes=None, note='', note_url='',
102102 """
103103json = None
104104# TODO: Break this behaviour in 1.0 (Don't rely on self._session.auth)
105- auth = self ._session .auth or (login and password )
105+ auth = None
106+ if self ._session .auth :
107+ auth = self ._session .auth
108+ elif login and password :
109+ auth = (login ,password )
110+
106111if auth :
107112url = self ._build_url ('authorizations' )
108113data = {'note' :note ,'note_url' :note_url ,
109114'client_id' :client_id ,'client_secret' :client_secret }
110115if scopes :
111116data ['scopes' ]= scopes
112- # TODO: Unconditionally use the login and password, e.g.,
113- # old_auth = self._session.auth
114- # self.login(login, password)
115- # json = self._json(...)
116- # self._session.auth = old_auth
117- do_logout = False
118- if not self ._session .auth :
119- do_logout = True
120- self .login (login ,password )
121- json = self ._json (self ._post (url ,data = data ),201 )
122- if do_logout :
123- self ._session .auth = None
117+
118+ with self ._session .temporary_basic_auth (* auth ):
119+ json = self ._json (self ._post (url ,data = data ),201 )
120+
124121return Authorization (json ,self )if json else None
125122
126123def check_authorization (self ,access_token ):