Skip to content

Commit 74dbe1b

Browse files
CYBERDEViLNLCYBERDEViLNL
authored andcommitted
* do _fetchcookies() after the scheme check in diaspy.connection.Connection().
* cleanded the scheme check a bit in `diaspy.connection.Connection()`. * `diaspy.connection.Connection().podswitch()` has now a optional param `login` with as default set to `True`, if `False` it will only set the data and does not call `login()`.
1 parent ca24303 commit 74dbe1b

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

diaspy/connection.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,15 @@ def __init__(self, pod, username, password, schema='https'):
4242
self._userdata = {}
4343
self._token = ''
4444
self._diaspora_session = ''
45-
self._cookies = self._fetchcookies()
4645
self._fetch_token_from = 'stream'
47-
try:
48-
#self._setlogin(username, password)
49-
self._login_data = {'user[username]': username,
50-
'user[password]': password,
51-
'authenticity_token': self._fetchtoken()}
52-
success = True
46+
try: self._setlogin(username, password)
5347
except requests.exceptions.MissingSchema:
5448
self.pod = '{0}://{1}'.format(schema, self.pod)
5549
warnings.warn('schema was missing')
56-
success = False
57-
finally:
58-
pass
59-
try:
60-
if not success:
61-
self._login_data = {'user[username]': username,
62-
'user[password]': password,
63-
'authenticity_token': self._fetchtoken()}
64-
except Exception as e:
65-
raise errors.LoginError('cannot create login data (caused by: {0})'.format(e))
50+
try: self._setlogin(username, password)
51+
except Exception as e:
52+
raise errors.LoginError('cannot create login data (caused by: {0})'.format(e))
53+
self._cookies = self._fetchcookies()
6654

6755
def _fetchcookies(self):
6856
request = self.get('stream')
@@ -189,12 +177,12 @@ def logout(self):
189177
self.get('users/sign_out')
190178
self.token = ''
191179

192-
def podswitch(self, pod, username, password):
180+
def podswitch(self, pod, username, password, login=True):
193181
"""Switches pod from current to another one.
194182
"""
195183
self.pod = pod
196184
self._setlogin(username, password)
197-
self._login()
185+
if login: self._login()
198186

199187
def _fetchtoken(self):
200188
"""This method tries to get token string needed for authentication on D*.

0 commit comments

Comments
 (0)