Fixed bugs with getting, showing and deleting users. Deleting users still does not...
authorFaldrian <faldrian@och-noe.de>
Sun, 12 Jan 2014 17:14:50 +0000 (18:14 +0100)
committerFaldrian <faldrian@och-noe.de>
Sun, 12 Jan 2014 17:14:50 +0000 (18:14 +0100)
diaspy/connection.py
diaspy/models.py
diaspy/people.py

index b5910131979b68f0fd344ebabbaefa6928ee8770..9ef2a89d36ba134d75816f49584471fccbf8a55a 100644 (file)
@@ -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
index 4d7b514d77256f037211b19269e0afc4ec8a1a89..8c1d72d9766b40c6705a909ae5cb64d101ae52f1 100644 (file)
@@ -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))
index 84e57b4ef08a76a998609b552e44cd77dd75d6aa..b48c600664349695194c4892d177a02fa174976e 100644 (file)
@@ -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.