From: Marek Marecki Date: Tue, 20 Aug 2013 10:59:51 +0000 (+0200) Subject: Small changes in connection X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1cff2093455fbd5406a9d4fbf476802886bce356;p=diaspy.git Small changes in connection --- diff --git a/Changelog.markdown b/Changelog.markdown index 304079c..eeb9e77 100644 --- a/Changelog.markdown +++ b/Changelog.markdown @@ -19,6 +19,12 @@ up-to-date than manual and if conflicts appear they should follow the order: *docstrings* -> *docs/* -> *manual/* +---- + +Version `0.3.2` (2013-08-): + +* __upd__: `diaspy.connection.getUserData()` raises `DiaspyError` when it cannot find user data, + ---- Version `0.3.1` (2013-07-12): diff --git a/diaspy/connection.py b/diaspy/connection.py index 3c1a0be..8654b06 100644 --- a/diaspy/connection.py +++ b/diaspy/connection.py @@ -19,8 +19,7 @@ class TokenError(Exception): class Connection(): - """Object representing connection with the server. - It is pushed around internally and is considered private. + """Object representing connection with the pod. """ _token_regex = re.compile(r'content="(.*?)"\s+name="csrf-token') _userinfo_regex = re.compile(r'window.current_user_attributes = ({.*})') @@ -157,7 +156,10 @@ class Connection(): :returns: dict -- json formatted user info. """ request = self.get('bookmarklet') - userdata = json.loads(self._userinfo_regex.search(request.text).group(1)) + try: + userdata = json.loads(self._userinfo_regex.search(request.text).group(1)) + except AttributeError: + raise errors.DiaspyError('cannot find user data') return userdata def _fetchtoken(self): diff --git a/tests.py b/tests.py index a45be30..57fac86 100644 --- a/tests.py +++ b/tests.py @@ -114,7 +114,7 @@ class StreamTest(unittest.TestCase): stream = diaspy.streams.Stream(test_connection) try: stream.post(text=post_text, photo='test-image.png') - except (StreamError) as e: + except (diaspy.errors.StreamError) as e: warnings.warn('{0}') finally: pass