From f8752360d705e56b4c7e20880cbb8bbbd00f29b6 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Sun, 15 Sep 2013 15:47:03 +0200 Subject: [PATCH] Moved getUserInfo() to diaspy.people.Me.getInfo(), regexps for extracting it were also moved --- Changelog.markdown | 10 +++++++++- diaspy/connection.py | 14 -------------- diaspy/people.py | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Changelog.markdown b/Changelog.markdown index 56322f0..909bf79 100644 --- a/Changelog.markdown +++ b/Changelog.markdown @@ -27,15 +27,23 @@ up-to-date than manual and if conflicts appear they should follow the order: ---- -#### Version `0.4.1` (2013-09-): +#### Version `0.4.2` (2013-09-): + +This version has some small incompatibilities with `0.4.1` so read Changelog carefully. * __new__: `diaspy.people.User._fetchstream()` method, +* __new__: `diaspy.people.Me()` object representing current user, +* __rem__: `diaspy.people.Me.getInfo()` (moved from `diaspy.connection.Connection.getUserInfo()`), + * __upd__: `diaspy.connection.Connection.login()` modifies connection object in-place **and** returns it (this allows more fluent API), * __upd__: `diaspy.connection.Connection.login()` no longer returns status code (if login was unsuccessful it'll raise an exception), * __upd__: `diaspy.connection.Connection._login()` no longer returns status code (if login was unsuccessful it'll raise an exception), +* __rem__: `diaspy.connection.Connection.getUserInfo()` moved to `diaspy.people.Me.getInfo()`, + + ---- #### Version `0.4.1` (2013-09-12): diff --git a/diaspy/connection.py b/diaspy/connection.py index 50b1d44..12c035a 100644 --- a/diaspy/connection.py +++ b/diaspy/connection.py @@ -20,8 +20,6 @@ class Connection(): """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 = ({.*})') - _userinfo_regex_2 = re.compile(r'gon.user=({.*});gon.preloads') def __init__(self, pod, username, password, schema='https'): """ @@ -173,18 +171,6 @@ class Connection(): self._setlogin(username, password) self._login() - def getUserInfo(self, fetch=False): - """This function returns the current user's attributes. - - :returns: dict -- json formatted user info. - """ - request = self.get('bookmarklet') - userdata = self._userinfo_regex.search(request.text) - if userdata is None: userdata = self._userinfo_regex_2.search(request.text) - if userdata is None: raise errors.DiaspyError('cannot find user data') - userdata = userdata.group(1) - return json.loads(userdata) - def _fetchtoken(self): """This method tries to get token string needed for authentication on D*. diff --git a/diaspy/people.py b/diaspy/people.py index 67404ef..76a1913 100644 --- a/diaspy/people.py +++ b/diaspy/people.py @@ -120,6 +120,29 @@ class User(): self.data = data +class Me(): + """Object represetnting current user. + """ + _userinfo_regex = re.compile(r'window.current_user_attributes = ({.*})') + _userinfo_regex_2 = re.compile(r'gon.user=({.*});gon.preloads') + + def __init__(self, connection): + self._connection = connection + + def getInfo(self, fetch=False): + """This function returns the current user's attributes. + + :returns: dict -- json formatted user info. + """ + request = self._connection.get('bookmarklet') + userdata = self._userinfo_regex.search(request.text) + if userdata is None: userdata = self._userinfo_regex_2.search(request.text) + if userdata is None: raise errors.DiaspyError('cannot find user data') + userdata = userdata.group(1) + return json.loads(userdata) + + + class Contacts(): """This class represents user's list of contacts. """ -- 2.25.1