* do `_fetchcookies()` after the scheme check in `diaspy.connection.Connection()`.
authorCYBERDEViLNL <CYBERDEViLNL@github.com>
Thu, 8 Nov 2018 14:46:01 +0000 (15:46 +0100)
committerCYBERDEViLNL <CYBERDEViLNL@github.com>
Thu, 8 Nov 2018 14:46:01 +0000 (15:46 +0100)
* 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()`.

diaspy/connection.py

index 95597066b6c51f37059cf40163272324181bfa8d..2001c4543485aafe7797c6af5aee3fd80abb47c4 100644 (file)
@@ -42,27 +42,15 @@ class Connection():
                self._userdata = {}
                self._token = ''
                self._diaspora_session = ''
-               self._cookies = self._fetchcookies()
                self._fetch_token_from = 'stream'
-               try:
-                       #self._setlogin(username, password)
-                       self._login_data = {'user[username]': username,
-                                                               'user[password]': password,
-                                                               'authenticity_token': self._fetchtoken()}
-                       success = True
+               try: self._setlogin(username, password)
                except requests.exceptions.MissingSchema:
                        self.pod = '{0}://{1}'.format(schema, self.pod)
                        warnings.warn('schema was missing')
-                       success = False
-               finally:
-                       pass
-               try:
-                       if not success:
-                               self._login_data = {'user[username]': username,
-                                                                       'user[password]': password,
-                                                                       'authenticity_token': self._fetchtoken()}
-               except Exception as e:
-                       raise errors.LoginError('cannot create login data (caused by: {0})'.format(e))
+                       try: self._setlogin(username, password)
+                       except Exception as e:
+                               raise errors.LoginError('cannot create login data (caused by: {0})'.format(e))
+               self._cookies = self._fetchcookies()
 
        def _fetchcookies(self):
                request = self.get('stream')
@@ -189,12 +177,12 @@ class Connection():
                self.get('users/sign_out')
                self.token = ''
 
-       def podswitch(self, pod, username, password):
+       def podswitch(self, pod, username, password, login=True):
                """Switches pod from current to another one.
                """
                self.pod = pod
                self._setlogin(username, password)
-               self._login()
+               if login: self._login()
 
        def _fetchtoken(self):
                """This method tries to get token string needed for authentication on D*.