From d458a0565bdb65ee93b93e101e1e22e6142faf80 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Mon, 25 Mar 2013 17:16:38 +0100 Subject: [PATCH] Fixed list generation in diaspy/client.py --- diaspy/client.py | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/diaspy/client.py b/diaspy/client.py index 2dc088e..0ec0074 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -20,6 +20,7 @@ class Client: """ self._token_regex = re.compile(r'content="(.*?)"\s+name="csrf-token') self.pod = pod + self.logged_in = False self.session = requests.Session() self._setlogindata(username, password) @@ -56,6 +57,7 @@ class Client: headers={'accept': 'application/json'}) if r.status_code != 201: raise Exception('{0}: Login failed.'.format(r.status_code)) + else: self.logged_in = True def post(self, text, aspect_id='public', photos=None): """This function sends a post to an aspect @@ -127,11 +129,7 @@ class Client: raise Exception('wrong status code: {0}'.format(r.status_code)) stream = r.json() - - posts = [] - - for post in stream: - posts.append(diaspy.models.Post(str(post['id']), self)) + posts = [ diaspy.models.Post(str(post['id']), self) for post in stream ] return posts @@ -166,11 +164,7 @@ class Client: raise Exception('wrong status code: {0}'.format(r.status_code)) mentions = r.json() - - posts = [] - - for post in mentions: - posts.append(diaspy.models.Post(str(post['id']), self)) + posts = [ diaspy.models.Post(str(post['id']), self) for post in mentions ] return posts @@ -190,11 +184,7 @@ class Client: raise Exception('wrong status code: {0}'.format(r.status_code)) tagged_posts = r.json() - - posts = [] - - for post in tagged_posts: - posts.append(diaspy.models.Post(str(post['id']), self)) + posts = [ diaspy.models.Post(str(post['id']), self) for post in tagged_posts ] return posts @@ -281,11 +271,7 @@ class Client: raise Exception('wrong status code: {0}'.format(r.status_code)) mailbox = r.json() - - conversations = [] - - for conversation in mailbox: - conversations.append(diaspy.conversations.Conversation(str(conversation['conversation']['id']), self)) + conversations = [ diaspy.conversations.Conversation(str(conversation['conversation']['id']), self) for conversation in mailbox ] return conversations -- 2.25.1