From 03ffc9ea490ec24b04d30ebf2f70bd030fb95398 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Sun, 5 Jan 2014 12:57:35 +0100 Subject: [PATCH] Fix for issue #10, updated language-list fetching regexp (fixes a bug where some languages were not fetched) --- Changelog.markdown | 10 ++++++++++ diaspy/people.py | 11 ++++++++--- diaspy/settings.py | 5 +++-- tests.py | 5 +++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Changelog.markdown b/Changelog.markdown index a22797c..4531320 100644 --- a/Changelog.markdown +++ b/Changelog.markdown @@ -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): diff --git a/diaspy/people.py b/diaspy/people.py index 84e57b4..a62ce0c 100644 --- a/diaspy/people.py +++ b/diaspy/people.py @@ -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. diff --git a/diaspy/settings.py b/diaspy/settings.py index cf86e59..c926efd 100644 --- a/diaspy/settings.py +++ b/diaspy/settings.py @@ -17,7 +17,7 @@ class Account(): """Provides interface to account settings. """ email_regexp = re.compile('(.*?)') + language_option_regexp = re.compile('') 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. diff --git a/tests.py b/tests.py index f0e8980..92d486c 100644 --- 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): -- 2.25.1