From e21587b94aa4a8ca1e673fd73899cbabfeb35afe Mon Sep 17 00:00:00 2001 From: Faldrian Date: Sun, 12 Jan 2014 18:14:50 +0100 Subject: [PATCH] Fixed bugs with getting, showing and deleting users. Deleting users still does not work. --- diaspy/connection.py | 12 +++++++++--- diaspy/models.py | 2 +- diaspy/people.py | 11 ++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/diaspy/connection.py b/diaspy/connection.py index b591013..9ef2a89 100644 --- a/diaspy/connection.py +++ b/diaspy/connection.py @@ -24,6 +24,7 @@ class Connection(): _userinfo_regex = re.compile(r'window.current_user_attributes = ({.*})') # this is for older version of D* _userinfo_regex_2 = re.compile(r'gon.user=({.*});gon.preloads') + _verify_SSL = True def __init__(self, pod, username, password, schema='https'): """ @@ -87,7 +88,7 @@ class Connection(): """ if not direct: url = '{0}/{1}'.format(self.pod, string) else: url = string - return self._session.get(url, params=params, headers=headers, **kwargs) + return self._session.get(url, params=params, headers=headers, verify=self._verify_SSL, **kwargs) def post(self, string, data, headers={}, params={}, **kwargs): """This method posts data to session. @@ -105,7 +106,7 @@ class Connection(): :type params: dict """ string = '{0}/{1}'.format(self.pod, string) - request = self._session.post(string, data, headers=headers, params=params, **kwargs) + request = self._session.post(string, data, headers=headers, params=params, verify=self._verify_SSL, **kwargs) return request def put(self, string, data=None, headers={}, params={}, **kwargs): @@ -113,7 +114,7 @@ class Connection(): """ string = '{0}/{1}'.format(self.pod, string) if data is not None: request = self._session.put(string, data, headers=headers, params=params, **kwargs) - else: request = self._session.put(string, headers=headers, params=params, **kwargs) + else: request = self._session.put(string, headers=headers, params=params, verify=self._verify_SSL, **kwargs) return request def delete(self, string, data, headers={}, **kwargs): @@ -219,3 +220,8 @@ class Connection(): if userdata is None: raise errors.DiaspyError('cannot find user data') userdata = userdata.group(1) return json.loads(userdata) + + def set_verify_SSL(self, verify): + """Sets whether there should be an error if a SSL-Certificate could not be verified. + """ + self._verify_SSL = verify diff --git a/diaspy/models.py b/diaspy/models.py index 4d7b514..8c1d72d 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -138,7 +138,7 @@ class Aspect(): data = {'authenticity_token': repr(self._connection), 'aspect_id': self.id, 'person_id': user_id} - request = self.connection.delete('aspect_memberships/{0}.json'.format(self.id), data=data) + request = self._connection.delete('aspect_memberships/{0}.json'.format(self.id), data=data) if request.status_code != 200: raise errors.AspectError('cannot remove user from aspect: {0}'.format(request.status_code)) diff --git a/diaspy/people.py b/diaspy/people.py index 84e57b4..b48c600 100644 --- a/diaspy/people.py +++ b/diaspy/people.py @@ -57,7 +57,7 @@ class User(): return self['guid'] def __repr__(self): - return '{0} ({1})'.format(self['diaspora_name'], self['guid']) + return '{0} ({1})'.format(self['handle'], self['guid']) def _fetchstream(self): self.stream = Outer(self._connection, location='people/{0}.json'.format(self['guid'])) @@ -119,8 +119,13 @@ class User(): def fetchprofile(self): """Fetches user data. """ - data = search.Search(self._connection).user(self['handle'])[0] - self.data = data + result = search.Search(self._connection).user(self['handle']) + + # Check if there were any results at all + if len(result) < 1: + raise errors.UserError('could not fetch profile of user: {0}'.format(self['handle'])) + + self.data = result[0] def getHCard(self): """Returns XML string containing user HCard. -- 2.25.1