Fix for issue #10, updated language-list fetching regexp (fixes a bug where some...
authorMarek Marecki <marekjm@taistelu.com>
Sun, 5 Jan 2014 11:57:35 +0000 (12:57 +0100)
committerMarek Marecki <marekjm@taistelu.com>
Sun, 5 Jan 2014 11:57:35 +0000 (12:57 +0100)
Changelog.markdown
diaspy/people.py
diaspy/settings.py
tests.py

index a22797c9c2410145f41dc89ecbf237252e9526a5..45313202732817a0f6d07cb2969fc42f7dcd4be7 100644 (file)
@@ -25,6 +25,16 @@ up-to-date than manual and if conflicts appear they should follow the order:
 * __bug__:  `diaspy` has problems/can't connect to pods using SNI (this is an issue with requests/urllib3/python),
 
 
+----
+
+#### Version `0.4.3`:
+
+* __new__:  `people.User().fetchprofile()` will issue a warning when user cannot be found on current pod,
+* __new__:  `settings.Profile` is now loaded during initialization (can be switched off),
+
+* __fix__:  fixed a bug in `__repr__()` method in `people.User()` object,
+
+
 ----
 
 #### Version `0.4.2` (2013-12-19):
index 84e57b4ef08a76a998609b552e44cd77dd75d6aa..a62ce0c685b32377b00138bcf0fc52ab7fdbbc0e 100644 (file)
@@ -2,6 +2,8 @@
 
 import json
 import re
+import warnings
+
 from diaspy.streams import Outer
 from diaspy.models import Aspect
 from diaspy import errors
@@ -57,7 +59,7 @@ class User():
         return self['guid']
 
     def __repr__(self):
-        return '{0} ({1})'.format(self['diaspora_name'], self['guid'])
+        return '{0} ({1})'.format(self['name'], self['guid'])
 
     def _fetchstream(self):
         self.stream = Outer(self._connection, location='people/{0}.json'.format(self['guid']))
@@ -119,8 +121,11 @@ class User():
     def fetchprofile(self):
         """Fetches user data.
         """
-        data = search.Search(self._connection).user(self['handle'])[0]
-        self.data = data
+        data = search.Search(self._connection).user(self['handle'])
+        if not data:
+            warnings.warn('user with handle "{0}" has not been found on pod "{1}"'.format(self['handle'], self._connection.pod))
+        else:
+            self.data = data[0]
 
     def getHCard(self):
         """Returns XML string containing user HCard.
index cf86e598ac672dd5fd4ddafdb70de892c67fa5fc..c926efdfa01bd21781ee04769f61b8243e934887 100644 (file)
@@ -17,7 +17,7 @@ class Account():
     """Provides interface to account settings.
     """
     email_regexp = re.compile('<input id="user_email" name="user\[email\]" size="30" type="text" value="(.+?)"')
-    language_option_regexp = re.compile('<option value="([-_a-z]+)">(.*?)</option>')
+    language_option_regexp = re.compile('<option value="([_a-zA-Z-]+)"(?: selected="selected")?>(.*?)</option>')
 
     def __init__(self, connection):
         self._connection = connection
@@ -136,7 +136,7 @@ class Profile():
     is_searchable_regexp = re.compile('checked="checked" id="profile_searchable" name="profile\[searchable\]" type="checkbox" value="(.*?)" />')
     is_nsfw_regexp = re.compile('checked="checked" id="profile_nsfw" name="profile\[nsfw\]" type="checkbox" value="(.*?)" />')
 
-    def __init__(self, connection):
+    def __init__(self, connection, no_load=False):
         self._connection = connection
         self.data = {'utf-8': '✓',
                      '_method': 'put',
@@ -154,6 +154,7 @@ class Profile():
                      }
         self._html = self._fetchhtml()
         self._loaded = False
+        if not no_load: self.load()
 
     def _fetchhtml(self):
         """Fetches html that will be used to extract data.
index f0e89809a0798d0921a4ed1259b05152dc790548..92d486c619efe06058f439abffbafe9f7470a48f 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -180,6 +180,11 @@ class UserTests(unittest.TestCase):
         self.assertIn('avatar', user.data)
         self.assertEqual(type(user.stream), diaspy.streams.Outer)
 
+    def testReprMethod(self):
+        user = diaspy.people.User(test_connection, guid=testconf.guid)
+        repr(user)
+        print(user)
+
 
 class ContactsTest(unittest.TestCase):
     def testGetOnlySharing(self):