Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 07C65431FD0 for ; Tue, 12 Jul 2011 13:37:19 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Aye4C-IQ6NgT for ; Tue, 12 Jul 2011 13:37:14 -0700 (PDT) Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 17D2C431FB6 for ; Tue, 12 Jul 2011 13:37:13 -0700 (PDT) Received: by wwj40 with SMTP id 40so3180396wwj.2 for ; Tue, 12 Jul 2011 13:37:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=Uj7EsxRFfmjAdr4s4Ul+N1q64Tnpqx6Go+yXMu4wKjE=; b=Z3QdImOVL73qyNVQQQyRF1m1MlQr5bSOO6YVogYl0pDz0cnRNxhnPQ6P+uCgeqYbr3 7YnxGm86S5itV4se0PYF9tbP1jnzxIhpXsjhuuZVHagATJDgXgg6j3+S6GX26NpEUNOO 4s7iIp9dDAdVpSFuWnXImS7j6s0k8DwAN0Sro= Received: by 10.217.6.81 with SMTP id x59mr301499wes.50.1310503032658; Tue, 12 Jul 2011 13:37:12 -0700 (PDT) Received: from brick.lan (cpc1-sgyl2-0-0-cust47.sgyl.cable.virginmedia.com [80.192.18.48]) by mx.google.com with ESMTPS id n17sm6361268wed.16.2011.07.12.13.37.08 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 12 Jul 2011 13:37:10 -0700 (PDT) Date: Tue, 12 Jul 2011 21:37:05 +0100 From: Patrick Totzke To: notmuch@notmuchmail.org Subject: [python] pep8 Message-ID: <20110712203705.GB28929@brick.lan> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="g7w8+K/95kPelPD2" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jul 2011 20:37:19 -0000 --g7w8+K/95kPelPD2 Content-Type: multipart/mixed; boundary="hYooF8G/hrfVAmum" Content-Disposition: inline --hYooF8G/hrfVAmum Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable hi all, I just read I'm a bit late with this as Sebastian is going on holiday for t= he=20 next couple of weeks, but here it is anyway. The attached patches make notmuch's python bindings pep8 compliant. most of it is just chopping down long lines and removin trailing whitespace= s. best, /p --hYooF8G/hrfVAmum Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0002-pep8-compliance-for-message.py.patch" Content-Transfer-Encoding: quoted-printable =46rom f1894462d690924c568213cd497d3546ea3fc362 Mon Sep 17 00:00:00 2001 =46rom: pazz Date: Tue, 12 Jul 2011 20:46:59 +0100 Subject: [PATCH 2/8] pep8 compliance for message.py --- bindings/python/notmuch/message.py | 129 +++++++++++++++++---------------= --- 1 files changed, 63 insertions(+), 66 deletions(-) diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/m= essage.py index 4a43a88..f5fd603 100644 --- a/bindings/python/notmuch/message.py +++ b/bindings/python/notmuch/message.py @@ -18,7 +18,7 @@ Copyright 2010 Sebastian Spaeth ' Jesse Rosenthal """ =20 - =20 + from ctypes import c_char_p, c_void_p, c_long, c_uint, c_int from datetime import date from notmuch.globals import nmlib, STATUS, NotmuchError, Enum @@ -31,7 +31,8 @@ try: import simplejson as json except ImportError: import json -#-------------------------------------------------------------------------= ----- + + class Messages(object): """Represents a list of notmuch messages =20 @@ -63,8 +64,8 @@ class Messages(object): # However it will be kept alive until all retrieved Message() # objects are also deleted. If you do e.g. an explicit del(msgs) # here, the following lines would fail. - =20 - # You can reiterate over *msglist* however as often as you want.=20 + + # You can reiterate over *msglist* however as often as you want. # It is simply a list with :class:`Message`s. =20 print (msglist[0].get_filename()) @@ -110,7 +111,7 @@ class Messages(object): (ie :class:`Query`) these tags are derived from. It saves a reference to it, so we can automatically delete the db object once all derived objects are dead. - :TODO: Make the iterator work more than once and cache the tags in= =20 + :TODO: Make the iterator work more than once and cache the tags in the Python object.(?) """ if msgs_p is None: @@ -133,7 +134,7 @@ class Messages(object): raise NotmuchError(STATUS.NOT_INITIALIZED) =20 # collect all tags (returns NULL on error) - tags_p =3D Messages._collect_tags (self._msgs) + tags_p =3D Messages._collect_tags(self._msgs) #reset _msgs as we iterated over it and can do so only once self._msgs =3D None =20 @@ -153,7 +154,7 @@ class Messages(object): self._msgs =3D None raise StopIteration =20 - msg =3D Message(Messages._get (self._msgs), self) + msg =3D Message(Messages._get(self._msgs), self) nmlib.notmuch_messages_move_to_next(self._msgs) return msg =20 @@ -167,14 +168,14 @@ class Messages(object): def __del__(self): """Close and free the notmuch Messages""" if self._msgs is not None: - nmlib.notmuch_messages_destroy (self._msgs) + nmlib.notmuch_messages_destroy(self._msgs) =20 def print_messages(self, format, indent=3D0, entire_thread=3DFalse): """Outputs messages as needed for 'notmuch show' to sys.stdout =20 :param format: A string of either 'text' or 'json'. :param indent: A number indicating the reply depth of these messag= es. - :param entire_thread: A bool, indicating whether we want to output= =20 + :param entire_thread: A bool, indicating whether we want to output whole threads or only the matching messages. """ if format.lower() =3D=3D "text": @@ -195,7 +196,7 @@ class Messages(object): # iterate through all toplevel messages in this thread for msg in self: # if not msg: - # break=20 + # break if not first_set: sys.stdout.write(set_sep) first_set =3D False @@ -222,7 +223,7 @@ class Messages(object): sys.stdout.write(set_end) sys.stdout.write(set_end) =20 -#-------------------------------------------------------------------------= ----- + class Message(object): """Represents a single Email message =20 @@ -236,7 +237,7 @@ class Message(object): =20 """notmuch_message_get_filename (notmuch_message_t *message)""" _get_filename =3D nmlib.notmuch_message_get_filename - _get_filename.restype =3D c_char_p=20 + _get_filename.restype =3D c_char_p =20 """return all filenames for a message""" _get_filenames =3D nmlib.notmuch_message_get_filenames @@ -248,7 +249,7 @@ class Message(object): =20 """notmuch_message_get_message_id (notmuch_message_t *message)""" _get_message_id =3D nmlib.notmuch_message_get_message_id - _get_message_id.restype =3D c_char_p=20 + _get_message_id.restype =3D c_char_p =20 """notmuch_message_get_thread_id""" _get_thread_id =3D nmlib.notmuch_message_get_thread_id @@ -296,12 +297,11 @@ class Message(object): #keep reference to parent, so we keep it alive self._parent =3D parent =20 - def get_message_id(self): """Returns the message ID - =20 + :returns: String with a message ID - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age is not initialized. """ if self._msg is None: @@ -311,23 +311,24 @@ class Message(object): def get_thread_id(self): """Returns the thread ID =20 - The returned string belongs to 'message' will only be valid for as= =20 + The returned string belongs to 'message' will only be valid for as long as the message is valid. =20 This function will not return `None` since Notmuch ensures that ev= ery message belongs to a single thread. =20 :returns: String with a thread ID - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age is not initialized. """ if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) =20 - return Message._get_thread_id (self._msg); + return Message._get_thread_id(self._msg) =20 def get_replies(self): - """Gets all direct replies to this message as :class:`Messages` it= erator + """Gets all direct replies to this message as :class:`Messages` + iterator =20 .. note:: This call only makes sense if 'message' was ultimately obtained from a :class:`Thread` object, (such as @@ -338,20 +339,20 @@ class Message(object): to :meth:`Query.search_messages`), then this function will return `None`. =20 - :returns: :class:`Messages` or `None` if there are no replies to= =20 + :returns: :class:`Messages` or `None` if there are no replies to this message. - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age is not initialized. """ if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) =20 - msgs_p =3D Message._get_replies(self._msg); + msgs_p =3D Message._get_replies(self._msg) =20 if msgs_p is None: return None =20 - return Messages(msgs_p,self) + return Messages(msgs_p, self) =20 def get_date(self): """Returns time_t of the message date @@ -362,7 +363,7 @@ class Message(object): =20 :returns: A time_t timestamp. :rtype: c_unit64 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age is not initialized. """ if self._msg is None: @@ -371,7 +372,7 @@ class Message(object): =20 def get_header(self, header): """Returns a message header - =20 + This returns any message header that is stored in the notmuch data= base. This is only a selected subset of headers, which is currently: =20 @@ -383,7 +384,7 @@ class Message(object): :returns: The header value as a unicode string :exception: :exc:`NotmuchError` =20 - * STATUS.NOT_INITIALIZED if the message=20 + * STATUS.NOT_INITIALIZED if the message is not initialized. * STATUS.NULL_POINTER, if no header was found """ @@ -393,7 +394,7 @@ class Message(object): raise NotmuchError(STATUS.NOT_INITIALIZED) =20 #Returns NULL if any error occurs. - header =3D Message._get_header (self._msg, header) + header =3D Message._get_header(self._msg, header) if header =3D=3D None: raise NotmuchError(STATUS.NULL_POINTER) return header.decode('utf-8') @@ -402,7 +403,7 @@ class Message(object): """Returns the file path of the message file =20 :returns: Absolute file path & name of the message file - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age is not initialized. """ if self._msg is None: @@ -417,7 +418,7 @@ class Message(object): not necessarily have identical content.""" if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) - =20 + files_p =3D Message._get_filenames(self._msg) =20 return Filenames(files_p, self).as_generator() @@ -429,10 +430,10 @@ class Message(object): *Message.FLAG.MATCH* for those messages that match the query. This method allows us to get the value of this flag. =20 - :param flag: One of the :attr:`Message.FLAG` values (currently onl= y=20 + :param flag: One of the :attr:`Message.FLAG` values (currently only *Message.FLAG.MATCH* :returns: An unsigned int (0/1), indicating whether the flag is se= t. - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age is not initialized. """ if self._msg is None: @@ -442,12 +443,12 @@ class Message(object): def set_flag(self, flag, value): """Sets/Unsets a specific flag for this message =20 - :param flag: One of the :attr:`Message.FLAG` values (currently onl= y=20 + :param flag: One of the :attr:`Message.FLAG` values (currently only *Message.FLAG.MATCH* :param value: A bool indicating whether to set or unset the flag. =20 :returns: Nothing - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age is not initialized. """ if self._msg is None: @@ -460,7 +461,7 @@ class Message(object): :returns: A :class:`Tags` iterator. :exception: :exc:`NotmuchError` =20 - * STATUS.NOT_INITIALIZED if the message=20 + * STATUS.NOT_INITIALIZED if the message is not initialized. * STATUS.NULL_POINTER, on error """ @@ -495,10 +496,10 @@ class Message(object): STATUS.NULL_POINTER The 'tag' argument is NULL STATUS.TAG_TOO_LONG - The length of 'tag' is too long=20 + The length of 'tag' is too long (exceeds Message.NOTMUCH_TAG_MAX) STATUS.READ_ONLY_DATABASE - Database was opened in read-only mode so message canno= t be=20 + Database was opened in read-only mode so message canno= t be modified. STATUS.NOT_INITIALIZED The message has not been initialized. @@ -506,7 +507,7 @@ class Message(object): if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) =20 - status =3D nmlib.notmuch_message_add_tag (self._msg, tag) + status =3D nmlib.notmuch_message_add_tag(self._msg, tag) =20 # bail out on failure if status !=3D STATUS.SUCCESS: @@ -531,7 +532,7 @@ class Message(object): that this will do nothing when a message is frozen, as tag changes will not be committed to the database yet. =20 - :returns: STATUS.SUCCESS if the tag was successfully removed or if= =20 + :returns: STATUS.SUCCESS if the tag was successfully removed or if the message had no such tag. Raises an exception otherwise. :exception: :exc:`NotmuchError`. They have the following meaning: @@ -542,7 +543,7 @@ class Message(object): The length of 'tag' is too long (exceeds NOTMUCH_TAG_MAX) STATUS.READ_ONLY_DATABASE - Database was opened in read-only mode so message cann= ot=20 + Database was opened in read-only mode so message cann= ot be modified. STATUS.NOT_INITIALIZED The message has not been initialized. @@ -559,8 +560,6 @@ class Message(object): self.tags_to_maildir_flags() return STATUS.SUCCESS =20 - - def remove_all_tags(self, sync_maildir_flags=3DFalse): """Removes all tags from the given message. =20 @@ -581,14 +580,14 @@ class Message(object): :exception: :exc:`NotmuchError`. They have the following meaning: =20 STATUS.READ_ONLY_DATABASE - Database was opened in read-only mode so message cann= ot=20 + Database was opened in read-only mode so message cann= ot be modified. STATUS.NOT_INITIALIZED The message has not been initialized. """ if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) -=20 + status =3D nmlib.notmuch_message_remove_all_tags(self._msg) =20 # bail out on error @@ -602,8 +601,8 @@ class Message(object): def freeze(self): """Freezes the current state of 'message' within the database =20 - This means that changes to the message state, (via :meth:`add_tag`= ,=20 - :meth:`remove_tag`, and :meth:`remove_all_tags`), will not be=20 + This means that changes to the message state, (via :meth:`add_tag`, + :meth:`remove_tag`, and :meth:`remove_all_tags`), will not be committed to the database until the message is :meth:`thaw`ed. =20 Multiple calls to freeze/thaw are valid and these calls will @@ -635,14 +634,14 @@ class Message(object): :exception: :exc:`NotmuchError`. They have the following meaning: =20 STATUS.READ_ONLY_DATABASE - Database was opened in read-only mode so message cann= ot=20 + Database was opened in read-only mode so message cann= ot be modified. STATUS.NOT_INITIALIZED The message has not been initialized. """ if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) -=20 + status =3D nmlib.notmuch_message_freeze(self._msg) =20 if STATUS.SUCCESS =3D=3D status: @@ -654,7 +653,7 @@ class Message(object): def thaw(self): """Thaws the current 'message' =20 - Thaw the current 'message', synchronizing any changes that may hav= e=20 + Thaw the current 'message', synchronizing any changes that may have occurred while 'message' was frozen into the notmuch database. =20 See :meth:`freeze` for an example of how to use this @@ -669,15 +668,15 @@ class Message(object): :exception: :exc:`NotmuchError`. They have the following meaning: =20 STATUS.UNBALANCED_FREEZE_THAW - An attempt was made to thaw an unfrozen message.=20 - That is, there have been an unbalanced number of call= s=20 + An attempt was made to thaw an unfrozen message. + That is, there have been an unbalanced number of calls to :meth:`freeze` and :meth:`thaw`. STATUS.NOT_INITIALIZED The message has not been initialized. """ if self._msg is None: raise NotmuchError(STATUS.NOT_INITIALIZED) -=20 + status =3D nmlib.notmuch_message_thaw(self._msg) =20 if STATUS.SUCCESS =3D=3D status: @@ -686,7 +685,6 @@ class Message(object): =20 raise NotmuchError(status) =20 - def is_match(self): """(Not implemented)""" return self.get_flag(Message.FLAG.MATCH) @@ -699,10 +697,10 @@ class Message(object): 'P' if the message has the "passed" tag 'R' if the message has the "replied" tag 'S' if the message does not have the "unread" tag - =20 + Any existing flags unmentioned in the list above will be preserved in the renaming. - =20 + Also, if this filename is in a directory named "new", rename it to be within the neighboring directory named "cur". =20 @@ -755,7 +753,6 @@ class Message(object): msg['date'] =3D date.fromtimestamp(self.get_date()) return "%(from)s (%(date)s) (%(tags)s)" % (msg) =20 - def get_message_parts(self): """Output like notmuch show""" fp =3D open(self.get_filename()) @@ -804,7 +801,7 @@ class Message(object): part_dict["content-type"] =3D cont_type # NOTE: # Now we emulate the current behaviour, where it ignores - # the html if there's a text representation.=20 + # the html if there's a text representation. # # This is being worked on, but it will be easier to fix # here in the future than to end up with another @@ -815,7 +812,7 @@ class Message(object): else: if cont_type.lower() =3D=3D "text/plain": part_dict["content"] =3D msg.get_payload() - elif (cont_type.lower() =3D=3D "text/html" and=20 + elif (cont_type.lower() =3D=3D "text/html" and i =3D=3D 0): part_dict["content"] =3D msg.get_payload() body.append(part_dict) @@ -860,18 +857,18 @@ class Message(object): parts =3D format["body"] parts.sort(key=3Dlambda x: x['id']) for p in parts: - if not p.has_key("filename"): + if not "filename" in p: output +=3D "\n\fpart{ " - output +=3D "ID: %d, Content-type: %s\n" % (p["id"],=20 - p["content-type"]) - if p.has_key("content"): + output +=3D "ID: %d, Content-type: %s\n" % (p["id"], + p["content-type"= ]) + if "content" in p: output +=3D "\n%s\n" % p["content"] else: output +=3D "Non-text part: %s\n" % p["content-type"] - output +=3D "\n\fpart}" =20 + output +=3D "\n\fpart}" else: output +=3D "\n\fattachment{ " - output +=3D "ID: %d, Content-type:%s\n" % (p["id"],=20 + output +=3D "ID: %d, Content-type:%s\n" % (p["id"], p["content-type"]) output +=3D "Attachment: %s\n" % p["filename"] output +=3D "\n\fattachment}\n" @@ -897,7 +894,7 @@ class Message(object): been added or removed, the same messages would not be considered equal (as they do not point to the same set of files any more).""" - res =3D cmp(self.get_message_id(), other.get_message_id()) + res =3D cmp(self.get_message_id(), other.get_message_id()) if res: res =3D cmp(list(self.get_filenames()), list(other.get_filenam= es())) return res @@ -905,4 +902,4 @@ class Message(object): def __del__(self): """Close and free the notmuch Message""" if self._msg is not None: - nmlib.notmuch_message_destroy (self._msg) + nmlib.notmuch_message_destroy(self._msg) --=20 1.7.4.1 --hYooF8G/hrfVAmum Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0003-pep8-compliance-for-database.py.patch" Content-Transfer-Encoding: quoted-printable =46rom 3cae17dfd64bc63ae89a2d95cd6ace7cc98807de Mon Sep 17 00:00:00 2001 =46rom: pazz Date: Tue, 12 Jul 2011 21:11:29 +0100 Subject: [PATCH 3/8] pep8 compliance for database.py --- bindings/python/notmuch/database.py | 160 +++++++++++++++++--------------= --- 1 files changed, 80 insertions(+), 80 deletions(-) diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/= database.py index 84cf79b..874087e 100644 --- a/bindings/python/notmuch/database.py +++ b/bindings/python/notmuch/database.py @@ -24,6 +24,7 @@ from notmuch.thread import Threads from notmuch.message import Messages, Message from notmuch.tag import Tags =20 + class Database(object): """Represents a notmuch database (wraps notmuch_database_t) =20 @@ -36,7 +37,7 @@ class Database(object): _std_db_path =3D None """Class attribute to cache user's default database""" =20 - MODE =3D Enum(['READ_ONLY','READ_WRITE']) + MODE =3D Enum(['READ_ONLY', 'READ_WRITE']) """Constants: Mode in which to open the database""" =20 """notmuch_database_get_directory""" @@ -52,7 +53,7 @@ class Database(object): _get_version.restype =3D c_uint =20 """notmuch_database_open""" - _open =3D nmlib.notmuch_database_open=20 + _open =3D nmlib.notmuch_database_open _open.restype =3D c_void_p =20 """notmuch_database_upgrade""" @@ -71,9 +72,9 @@ class Database(object): _create =3D nmlib.notmuch_database_create _create.restype =3D c_void_p =20 - def __init__(self, path=3DNone, create=3DFalse, mode=3D 0): - """If *path* is `None`, we will try to read a users notmuch=20 - configuration and use his configured database. The location of the= =20 + def __init__(self, path=3DNone, create=3DFalse, mode=3D0): + """If *path* is `None`, we will try to read a users notmuch + configuration and use his configured database. The location of the configuration file can be specified through the environment variab= le *NOTMUCH_CONFIG*, falling back to the default `~/.notmuch-config`. =20 @@ -84,9 +85,9 @@ class Database(object): above for behavior if `None`) :type path: `str` or `None` :param create: Pass `False` to open an existing, `True` to create = a new - database. =20 + database. :type create: bool - :param mode: Mode to open a database in. Is always=20 + :param mode: Mode to open a database in. Is always :attr:`MODE`.READ_WRITE when creating a new one. :type mode: :attr:`MODE` :returns: Nothing @@ -100,7 +101,7 @@ class Database(object): Database._std_db_path =3D self._get_user_default_db() path =3D Database._std_db_path =20 - assert isinstance(path, basestring), 'Path needs to be a string or= None.' + assert isinstance(path, basestring), 'Path must be a string or Non= e.' if create =3D=3D False: self.open(path, mode) else: @@ -109,7 +110,7 @@ class Database(object): def _verify_initialized_db(self): """Raises a NotmuchError in case self._db is still None""" if self._db is None: - raise NotmuchError(STATUS.NOT_INITIALIZED) =20 + raise NotmuchError(STATUS.NOT_INITIALIZED) =20 def create(self, path): """Creates a new notmuch database @@ -128,8 +129,8 @@ class Database(object): (after printing an error message on stderr). """ if self._db is not None: - raise NotmuchError( - message=3D"Cannot create db, this Database() already has an op= en one.") + raise NotmuchError(message=3D"Cannot create db, this Database(= ) " + "already has an open one.") =20 res =3D Database._create(path, Database.MODE.READ_WRITE) =20 @@ -138,7 +139,7 @@ class Database(object): message=3D"Could not create the specified database") self._db =3D res =20 - def open(self, path, mode=3D 0):=20 + def open(self, path, mode=3D0): """Opens an existing database =20 This function is used by __init__() and usually does not need @@ -146,7 +147,7 @@ class Database(object): *notmuch_database_open* function. =20 :param status: Open the database in read-only or read-write mode - :type status: :attr:`MODE`=20 + :type status: :attr:`MODE` :returns: Nothing :exception: Raises :exc:`NotmuchError` in case of any failure (after printing an error message on std= err). @@ -178,7 +179,7 @@ class Database(object): # Raise a NotmuchError if not initialized self._verify_initialized_db() =20 - return Database._get_version (self._db) + return Database._get_version(self._db) =20 def needs_upgrade(self): """Does this database need to be upgraded before writing to it? @@ -195,7 +196,7 @@ class Database(object): # Raise a NotmuchError if not initialized self._verify_initialized_db() =20 - return nmlib.notmuch_database_needs_upgrade(self._db)=20 + return nmlib.notmuch_database_needs_upgrade(self._db) =20 def upgrade(self): """Upgrades the current database @@ -207,7 +208,7 @@ class Database(object): NOT IMPLEMENTED: The optional progress_notify callback can be used by the caller to provide progress indication to the user. If non-NULL it will be called periodically with - 'progress' as a floating-point value in the range of [0.0..1.0]=20 + 'progress' as a floating-point value in the range of [0.0..1.0] indicating the progress made so far in the upgrade process. =20 :TODO: catch exceptions, document return values and etc... @@ -215,15 +216,15 @@ class Database(object): # Raise a NotmuchError if not initialized self._verify_initialized_db() =20 - status =3D Database._upgrade (self._db, None, None) + status =3D Database._upgrade(self._db, None, None) #TODO: catch exceptions, document return values and etc return status =20 def get_directory(self, path): - """Returns a :class:`Directory` of path,=20 + """Returns a :class:`Directory` of path, (creating it if it does not exist(?)) =20 - .. warning:: This call needs a writeable database in=20 + .. warning:: This call needs a writeable database in Database.MODE.READ_WRITE mode. The underlying library will exit= the program if this method is used on a read-only database! =20 @@ -233,11 +234,11 @@ class Database(object): :returns: :class:`Directory` or raises an exception. :exception: :exc:`NotmuchError` =20 - STATUS.NOT_INITIALIZED=20 + STATUS.NOT_INITIALIZED If the database was not intitialized. =20 STATUS.FILE_ERROR - If path is not relative database or absolute with init= ial=20 + If path is not relative database or absolute with init= ial components same as database. =20 """ @@ -249,14 +250,15 @@ class Database(object): # we got an absolute path if not path.startswith(self.get_path()): # but its initial components are not equal to the db path - raise NotmuchError(STATUS.FILE_ERROR,=20 - message=3D"Database().get_directory() c= alled with a wrong absolute path.") + raise NotmuchError(STATUS.FILE_ERROR, + message=3D"Database().get_directory() c= alled " + "with a wrong absolute path.") abs_dirpath =3D path else: #we got a relative path, make it absolute - abs_dirpath =3D os.path.abspath(os.path.join(self.get_path(),p= ath)) + abs_dirpath =3D os.path.abspath(os.path.join(self.get_path(), = path)) =20 - dir_p =3D Database._get_directory(self._db, path); + dir_p =3D Database._get_directory(self._db, path) =20 # return the Directory, init it with the absolute path return Directory(abs_dirpath, dir_p, self) @@ -281,7 +283,7 @@ class Database(object): API. You might want to look into the underlying method :meth:`Message.maildir_flags_to_tags`. =20 - :returns: On success, we return=20 + :returns: On success, we return =20 1) a :class:`Message` object that can be used for things such as adding tags to the just-added message. @@ -300,10 +302,11 @@ class Database(object): If such an exception occurs, nothing was added to the databa= se. =20 STATUS.FILE_ERROR - An error occurred trying to open the file, (such as= =20 + An error occurred trying to open the file, (such as permission denied, or file not found, etc.). STATUS.FILE_NOT_EMAIL - The contents of filename don't look like an email me= ssage. + The contents of filename don't look like an email + message. STATUS.READ_ONLY_DATABASE Database was opened in read-only mode so no message = can be added. @@ -317,7 +320,7 @@ class Database(object): status =3D nmlib.notmuch_database_add_message(self._db, filename, byref(msg_p)) -=20 + if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]: raise NotmuchError(status) =20 @@ -341,17 +344,18 @@ class Database(object): :returns: A STATUS value with the following meaning: =20 STATUS.SUCCESS - The last filename was removed and the message was removed= =20 + The last filename was removed and the message was removed from the database. STATUS.DUPLICATE_MESSAGE_ID - This filename was removed but the message persists in the= =20 + This filename was removed but the message persists in the database with at least one other filename. =20 :exception: Raises a :exc:`NotmuchError` with the following meanin= g. - If such an exception occurs, nothing was removed from the dat= abase. + If such an exception occurs, nothing was removed from the + database. =20 STATUS.READ_ONLY_DATABASE - Database was opened in read-only mode so no message can be= =20 + Database was opened in read-only mode so no message can be removed. STATUS.NOT_INITIALIZED The database has not been initialized. @@ -374,8 +378,8 @@ class Database(object): occurs. Do note that Xapian Exceptions include "Database modified" situations, e.g. when the notmuch database has been modified by - another program in the meantime. A return value of=20 - `None` is therefore no guarantee that the message=20 + another program in the meantime. A return value of + `None` is therefore no guarantee that the message does not exist. :exception: :exc:`NotmuchError` with STATUS.NOT_INITIALIZED if the database was not intitialized. @@ -397,7 +401,7 @@ class Database(object): # Raise a NotmuchError if not initialized self._verify_initialized_db() =20 - tags_p =3D Database._get_all_tags (self._db) + tags_p =3D Database._get_all_tags(self._db) if tags_p =3D=3D None: raise NotmuchError(STATUS.NULL_POINTER) return Tags(tags_p, self) @@ -442,10 +446,10 @@ class Database(object): conf_f =3D os.getenv('NOTMUCH_CONFIG', os.path.expanduser('~/.notmuch-config')) config.read(conf_f) - if not config.has_option('database','path'): - raise NotmuchError(message=3D - "No DB path specified and no user default f= ound") - return config.get('database','path') + if not config.has_option('database', 'path'): + raise NotmuchError(message=3D"No DB path specified" + " and no user default found") + return config.get('database', 'path') =20 @property def db_p(self): @@ -456,7 +460,7 @@ class Database(object): """ return self._db =20 -#-------------------------------------------------------------------------= ----- + class Query(object): """Represents a search query on an opened :class:`Database`. =20 @@ -476,7 +480,7 @@ class Query(object): other unexpected behavior. See above for more details. """ # constants - SORT =3D Enum(['OLDEST_FIRST','NEWEST_FIRST','MESSAGE_ID', 'UNSORTED']) + SORT =3D Enum(['OLDEST_FIRST', 'NEWEST_FIRST', 'MESSAGE_ID', 'UNSORTED= ']) """Constants: Sort order in which to return results""" =20 """notmuch_query_create""" @@ -491,7 +495,6 @@ class Query(object): _search_messages =3D nmlib.notmuch_query_search_messages _search_messages.restype =3D c_void_p =20 - """notmuch_query_count_messages""" _count_messages =3D nmlib.notmuch_query_count_messages _count_messages.restype =3D c_uint @@ -511,7 +514,7 @@ class Query(object): def create(self, db, querystr): """Creates a new query derived from a Database =20 - This function is utilized by __init__() and usually does not need = to=20 + This function is utilized by __init__() and usually does not need = to be called directly. =20 :param db: Database to create the query from. @@ -522,11 +525,11 @@ class Query(object): :exception: :exc:`NotmuchError` =20 * STATUS.NOT_INITIALIZED if db is not inited - * STATUS.NULL_POINTER if the query creation failed= =20 + * STATUS.NULL_POINTER if the query creation failed (too little memory) """ if db.db_p is None: - raise NotmuchError(STATUS.NOT_INITIALIZED) =20 + raise NotmuchError(STATUS.NOT_INITIALIZED) # create reference to parent db to keep it alive self._db =3D db if isinstance(querystr, unicode): @@ -545,7 +548,7 @@ class Query(object): =20 :param sort: Sort order (see :attr:`Query.SORT`) :returns: Nothing - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if query ha= s not=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if query ha= s not been initialized. """ if self._query is None: @@ -558,7 +561,7 @@ class Query(object): """Execute a query for threads =20 Execute a query for threads, returning a :class:`Threads` iterator. - The returned threads are owned by the query and as such, will only= be=20 + The returned threads are owned by the query and as such, will only= be valid until the Query is deleted. =20 The method sets :attr:`Message.FLAG`\.MATCH for those messages that @@ -572,17 +575,17 @@ class Query(object): :exception: :exc:`NotmuchError` =20 * STATUS.NOT_INITIALIZED if query is not inited - * STATUS.NULL_POINTER if search_threads failed=20 + * STATUS.NULL_POINTER if search_threads failed """ if self._query is None: - raise NotmuchError(STATUS.NOT_INITIALIZED) =20 + raise NotmuchError(STATUS.NOT_INITIALIZED) =20 threads_p =3D Query._search_threads(self._query) =20 if threads_p is None: NotmuchError(STATUS.NULL_POINTER) =20 - return Threads(threads_p,self) + return Threads(threads_p, self) =20 def search_messages(self): """Filter messages according to the query and return @@ -595,17 +598,17 @@ class Query(object): :exception: :exc:`NotmuchError` =20 * STATUS.NOT_INITIALIZED if query is not inited - * STATUS.NULL_POINTER if search_messages failed=20 + * STATUS.NULL_POINTER if search_messages failed """ if self._query is None: - raise NotmuchError(STATUS.NOT_INITIALIZED) =20 + raise NotmuchError(STATUS.NOT_INITIALIZED) =20 msgs_p =3D Query._search_messages(self._query) =20 if msgs_p is None: NotmuchError(STATUS.NULL_POINTER) =20 - return Messages(msgs_p,self) + return Messages(msgs_p, self) =20 def count_messages(self): """Estimate the number of messages matching the query @@ -623,17 +626,16 @@ class Query(object): * STATUS.NOT_INITIALIZED if query is not inited """ if self._query is None: - raise NotmuchError(STATUS.NOT_INITIALIZED) =20 + raise NotmuchError(STATUS.NOT_INITIALIZED) =20 return Query._count_messages(self._query) =20 def __del__(self): """Close and free the Query""" if self._query is not None: - nmlib.notmuch_query_destroy (self._query) + nmlib.notmuch_query_destroy(self._query) =20 =20 -#-------------------------------------------------------------------------= ----- class Directory(object): """Represents a directory entry in the notmuch directory =20 @@ -665,9 +667,9 @@ class Directory(object): _get_child_directories.restype =3D c_void_p =20 def _verify_dir_initialized(self): - """Raises a NotmuchError(STATUS.NOT_INITIALIZED) if the dir_p is N= one""" + """Raises a NotmuchError(STATUS.NOT_INITIALIZED) if dir_p is None"= "" if self._dir_p is None: - raise NotmuchError(STATUS.NOT_INITIALIZED) =20 + raise NotmuchError(STATUS.NOT_INITIALIZED) =20 def __init__(self, path, dir_p, parent): """ @@ -683,8 +685,7 @@ class Directory(object): self._dir_p =3D dir_p self._parent =3D parent =20 - - def set_mtime (self, mtime): + def set_mtime(self, mtime): """Sets the mtime value of this directory in the database =20 The intention is for the caller to use the mtime to allow efficient @@ -692,29 +693,29 @@ class Directory(object): recommended usage is as follows: =20 * Read the mtime of a directory from the filesystem -=20 + * Call :meth:`Database.add_message` for all mail files in the directory =20 - * Call notmuch_directory_set_mtime with the mtime read from the=20 + * Call notmuch_directory_set_mtime with the mtime read from the filesystem. Then, when wanting to check for updates to the directory in the future, the client can call :meth:`get_mtime` - and know that it only needs to add files if the mtime of the=20 + and know that it only needs to add files if the mtime of the directory and files are newer than the stored timestamp. =20 - .. note:: :meth:`get_mtime` function does not allow the caller= =20 + .. note:: :meth:`get_mtime` function does not allow the caller to distinguish a timestamp of 0 from a non-existent timestamp. So don't store a timestamp of 0 unless you are - comfortable with that. =20 + comfortable with that. =20 - :param mtime: A (time_t) timestamp=20 + :param mtime: A (time_t) timestamp :returns: Nothing on success, raising an exception on failure. :exception: :exc:`NotmuchError`: =20 STATUS.XAPIAN_EXCEPTION A Xapian exception occurred, mtime not stored. STATUS.READ_ONLY_DATABASE - Database was opened in read-only mode so directo= ry=20 + Database was opened in read-only mode so directo= ry mtime cannot be modified. STATUS.NOT_INITIALIZED The directory has not been initialized @@ -731,12 +732,12 @@ class Directory(object): #fail with Exception otherwise raise NotmuchError(status) =20 - def get_mtime (self): + def get_mtime(self): """Gets the mtime value of this directory in the database =20 Retrieves a previously stored mtime for this directory. =20 - :param mtime: A (time_t) timestamp=20 + :param mtime: A (time_t) timestamp :returns: Nothing on success, raising an exception on failure. :exception: :exc:`NotmuchError`: =20 @@ -746,19 +747,19 @@ class Directory(object): #Raise a NotmuchError(STATUS.NOT_INITIALIZED) if self.dir_p is None self._verify_dir_initialized() =20 - return Directory._get_mtime (self._dir_p) + return Directory._get_mtime(self._dir_p) =20 # Make mtime attribute a property of Directory() mtime =3D property(get_mtime, set_mtime, doc=3D"""Property that allows= getting and setting of the Directory *mtime* (read-write) =20 - See :meth:`get_mtime` and :meth:`set_mtime` for usage= and=20 + See :meth:`get_mtime` and :meth:`set_mtime` for usage= and possible exceptions.""") =20 def get_child_files(self): """Gets a Filenames iterator listing all the filenames of messages in the database within the given directory. -=20 + The returned filenames will be the basename-entries only (not complete paths. """ @@ -771,7 +772,7 @@ class Directory(object): def get_child_directories(self): """Gets a :class:`Filenames` iterator listing all the filenames of sub-directories in the database within the given directory - =20 + The returned filenames will be the basename-entries only (not complete paths. """ @@ -795,10 +796,9 @@ class Directory(object): if self._dir_p is not None: nmlib.notmuch_directory_destroy(self._dir_p) =20 -#-------------------------------------------------------------------------= ----- + class Filenames(object): - """An iterator over File- or Directory names that are stored in the da= tabase - """ + """An iterator over File- or Directory names stored in the database""" =20 #notmuch_filenames_get _get =3D nmlib.notmuch_filenames_get @@ -828,14 +828,14 @@ class Filenames(object): self._files_p =3D None raise StopIteration =20 - file =3D Filenames._get (self._files_p) + file =3D Filenames._get(self._files_p) nmlib.notmuch_filenames_move_to_next(self._files_p) return file =20 def __len__(self): """len(:class:`Filenames`) returns the number of contained files =20 - .. note:: As this iterates over the files, we will not be able to= =20 + .. note:: As this iterates over the files, we will not be able to iterate over them again! So this will fail:: =20 #THIS FAILS @@ -847,7 +847,7 @@ class Filenames(object): if self._files_p is None: raise NotmuchError(STATUS.NOT_INITIALIZED) =20 - i=3D0 + i =3D 0 while nmlib.notmuch_filenames_valid(self._files_p): nmlib.notmuch_filenames_move_to_next(self._files_p) i +=3D 1 --=20 1.7.4.1 --hYooF8G/hrfVAmum Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0004-pep8-compliance-for-filename.py.patch" Content-Transfer-Encoding: quoted-printable =46rom fcea6c05cd89e21bd0743445b69f89f92affbdd0 Mon Sep 17 00:00:00 2001 =46rom: pazz Date: Tue, 12 Jul 2011 21:13:57 +0100 Subject: [PATCH 4/8] pep8 compliance for filename.py --- bindings/python/notmuch/filename.py | 25 +++++++++++++------------ 1 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bindings/python/notmuch/filename.py b/bindings/python/notmuch/= filename.py index 20b90e9..630886d 100644 --- a/bindings/python/notmuch/filename.py +++ b/bindings/python/notmuch/filename.py @@ -19,19 +19,20 @@ Copyright 2010 Sebastian Spaeth ' from ctypes import c_char_p from notmuch.globals import nmlib, STATUS, NotmuchError =20 -#-------------------------------------------------------------------------= ----- + class Filenames(object): """Represents a list of filenames as returned by notmuch =20 - This object contains the Filenames iterator. The main function is as_g= enerator() which will return a generator so we can do a Filenamesth an iter= ator over a list of notmuch filenames. Do - note that the underlying library only provides a one-time iterator - (it cannot reset the iterator to the start). Thus iterating over - the function will "exhaust" the list of tags, and a subsequent - iteration attempt will raise a :exc:`NotmuchError` - STATUS.NOT_INITIALIZED. Also note, that any function that uses - iteration (nearly all) will also exhaust the tags. So both:: + This object contains the Filenames iterator. The main function is + as_generator() which will return a generator so we can do a Filenamest= h an + iterator over a list of notmuch filenames. Do note that the underlying + library only provides a one-time iterator (it cannot reset the iterato= r to + the start). Thus iterating over the function will "exhaust" the list of + tags, and a subsequent iteration attempt will raise a :exc:`NotmuchErr= or` + STATUS.NOT_INITIALIZED. Also note, that any function that uses iterati= on + (nearly all) will also exhaust the tags. So both:: =20 - for name in filenames: print name=20 + for name in filenames: print name =20 as well as:: =20 @@ -85,10 +86,10 @@ class Filenames(object): self._files =3D None return =20 - file =3D Filenames._get (self._files) + file =3D Filenames._get(self._files) nmlib.notmuch_filenames_move_to_next(self._files) yield file - =20 + def __str__(self): """Represent Filenames() as newline-separated list of full paths =20 @@ -105,4 +106,4 @@ class Filenames(object): def __del__(self): """Close and free the notmuch filenames""" if self._files is not None: - nmlib.notmuch_filenames_destroy (self._files) + nmlib.notmuch_filenames_destroy(self._files) --=20 1.7.4.1 --hYooF8G/hrfVAmum Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0005-pep8-compliance-for-globals.py.patch" Content-Transfer-Encoding: quoted-printable =46rom 224636cd6339ea02a4d304df7b0e3ff958ea7718 Mon Sep 17 00:00:00 2001 =46rom: pazz Date: Tue, 12 Jul 2011 21:16:04 +0100 Subject: [PATCH 5/8] pep8 compliance for globals.py --- bindings/python/notmuch/globals.py | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/g= lobals.py index c675d04..77f2905 100644 --- a/bindings/python/notmuch/globals.py +++ b/bindings/python/notmuch/globals.py @@ -27,14 +27,14 @@ try: except: raise ImportError("Could not find shared 'notmuch' library.") =20 -#-------------------------------------------------------------------------= ---- + class Enum(object): """Provides ENUMS as "code=3DEnum(['a','b','c'])" where code.a=3D0 etc= =2E..""" def __init__(self, names): for number, name in enumerate(names): setattr(self, name, number) =20 -#-------------------------------------------------------------------------= ---- + class Status(Enum): """Enum with a string representation of a notmuch_status_t value.""" _status2str =3D nmlib.notmuch_status_to_string @@ -49,10 +49,10 @@ class Status(Enum): =20 @classmethod def status2str(self, status): - """Get a string representation of a notmuch_status_t value.""" = =20 + """Get a string representation of a notmuch_status_t value.""" # define strings for custom error messages if status =3D=3D STATUS.NOT_INITIALIZED: - return "Operation on uninitialized object impossible." + return "Operation on uninitialized object impossible." return str(Status._status2str(status)) =20 STATUS =3D Status(['SUCCESS', @@ -66,7 +66,10 @@ STATUS =3D Status(['SUCCESS', 'TAG_TOO_LONG', 'UNBALANCED_FREEZE_THAW', 'NOT_INITIALIZED']) -"""STATUS is a class, whose attributes provide constants that serve as ret= urn indicators for notmuch functions. Currently the following ones are defi= ned. For possible return values and specific meaning for each method, see t= he method description. +"""STATUS is a class, whose attributes provide constants that serve as ret= urn +indicators for notmuch functions. Currently the following ones are defined= =2E For +possible return values and specific meaning for each method, see the method +description. =20 * SUCCESS * OUT_OF_MEMORY @@ -80,8 +83,10 @@ STATUS =3D Status(['SUCCESS', * UNBALANCED_FREEZE_THAW * NOT_INITIALIZED =20 - Invoke the class method `notmuch.STATUS.status2str` with a status value = as argument to receive a human readable string""" -STATUS.__name__ =3D 'STATUS'=20 +Invoke the class method `notmuch.STATUS.status2str` with a status value as +argument to receive a human readable string""" +STATUS.__name__ =3D 'STATUS' + =20 class NotmuchError(Exception): def __init__(self, status=3DNone, message=3DNone): @@ -89,6 +94,7 @@ class NotmuchError(Exception): super(NotmuchError, self).__init__(message, status) =20 def __str__(self): - if self.args[0] is not None: return self.args[0] - else: return STATUS.status2str(self.args[1]) - + if self.args[0] is not None: + return self.args[0] + else: + return STATUS.status2str(self.args[1]) --=20 1.7.4.1 --hYooF8G/hrfVAmum Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0006-pep8-compliance-for-tag.py.patch" Content-Transfer-Encoding: quoted-printable =46rom b257591409a6c5d5804b0e34a81bd95912a07c59 Mon Sep 17 00:00:00 2001 =46rom: pazz Date: Tue, 12 Jul 2011 21:17:03 +0100 Subject: [PATCH 6/8] pep8 compliance for tag.py --- bindings/python/notmuch/tag.py | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bindings/python/notmuch/tag.py b/bindings/python/notmuch/tag.py index 65a9118..a664578 100644 --- a/bindings/python/notmuch/tag.py +++ b/bindings/python/notmuch/tag.py @@ -19,12 +19,12 @@ Copyright 2010 Sebastian Spaeth ' from ctypes import c_char_p from notmuch.globals import nmlib, STATUS, NotmuchError =20 -#-------------------------------------------------------------------------= ----- + class Tags(object): """Represents a list of notmuch tags =20 This object provides an iterator over a list of notmuch tags (which - are unicode instances).=20 + are unicode instances). =20 Do note that the underlying library only provides a one-time iterator (it cannot reset the iterator to the start). Thus iterating @@ -33,7 +33,7 @@ class Tags(object): STATUS.NOT_INITIALIZED. Also note, that any function that uses iteration (nearly all) will also exhaust the tags. So both:: =20 - for tag in tags: print tag=20 + for tag in tags: print tag =20 as well as:: =20 @@ -62,7 +62,7 @@ class Tags(object): valid, we will raise an :exc:`NotmuchError` (STATUS.NULL_POINTER) if it is `None`. :type tags_p: :class:`ctypes.c_void_p` - :param parent: The parent object (ie :class:`Database` or=20 + :param parent: The parent object (ie :class:`Database` or :class:`Message` these tags are derived from, and saves a reference to it, so we can automatically delete the db object once all derived objects are dead. @@ -75,7 +75,7 @@ class Tags(object): self._tags =3D tags_p #save reference to parent object so we keep it alive self._parent =3D parent - =20 + def __iter__(self): """ Make Tags an iterator """ return self @@ -115,7 +115,7 @@ class Tags(object): if self._tags is None: raise NotmuchError(STATUS.NOT_INITIALIZED) =20 - i=3D0 + i =3D 0 while nmlib.notmuch_tags_valid(self._msgs): nmlib.notmuch_tags_move_to_next(self._msgs) i +=3D 1 @@ -136,4 +136,4 @@ class Tags(object): def __del__(self): """Close and free the notmuch tags""" if self._tags is not None: - nmlib.notmuch_tags_destroy (self._tags) + nmlib.notmuch_tags_destroy(self._tags) --=20 1.7.4.1 --hYooF8G/hrfVAmum Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0007-pep8-compliance-for-thread.py.patch" Content-Transfer-Encoding: quoted-printable =46rom 288f53704c95377f546a3b21651610a164c26950 Mon Sep 17 00:00:00 2001 =46rom: pazz Date: Tue, 12 Jul 2011 21:22:13 +0100 Subject: [PATCH 7/8] pep8 compliance for thread.py --- bindings/python/notmuch/thread.py | 65 ++++++++++++++++++++-------------= ---- 1 files changed, 35 insertions(+), 30 deletions(-) diff --git a/bindings/python/notmuch/thread.py b/bindings/python/notmuch/th= read.py index 2bb30b7..60f6c29 100644 --- a/bindings/python/notmuch/thread.py +++ b/bindings/python/notmuch/thread.py @@ -23,7 +23,7 @@ from notmuch.message import Messages from notmuch.tag import Tags from datetime import date =20 -#-------------------------------------------------------------------------= ----- + class Threads(object): """Represents a list of notmuch threads =20 @@ -59,13 +59,13 @@ class Threads(object): for thread in threads: threadlist.append(thread) =20 - # threads is "exhausted" now and even len(threads) will raise an=20 + # threads is "exhausted" now and even len(threads) will raise an # exception. # However it will be kept around until all retrieved Thread() object= s are - # also deleted. If you did e.g. an explicit del(threads) here, the= =20 + # also deleted. If you did e.g. an explicit del(threads) here, the # following lines would fail. - =20 - # You can reiterate over *threadlist* however as often as you want.= =20 + + # You can reiterate over *threadlist* however as often as you want. # It is simply a list with Thread objects. =20 print (threadlist[0].get_thread_id()) @@ -91,7 +91,7 @@ class Threads(object): (ie :class:`Query`) these tags are derived from. It saves a reference to it, so we can automatically delete the db object once all derived objects are dead. - :TODO: Make the iterator work more than once and cache the tags in= =20 + :TODO: Make the iterator work more than once and cache the tags in the Python object.(?) """ if threads_p is None: @@ -113,14 +113,14 @@ class Threads(object): self._threads =3D None raise StopIteration =20 - thread =3D Thread(Threads._get (self._threads), self) + thread =3D Thread(Threads._get(self._threads), self) nmlib.notmuch_threads_move_to_next(self._threads) return thread =20 def __len__(self): """len(:class:`Threads`) returns the number of contained Threads =20 - .. note:: As this iterates over the threads, we will not be able t= o=20 + .. note:: As this iterates over the threads, we will not be able to iterate over them again! So this will fail:: =20 #THIS FAILS @@ -132,7 +132,7 @@ class Threads(object): if self._threads is None: raise NotmuchError(STATUS.NOT_INITIALIZED) =20 - i=3D0 + i =3D 0 # returns 'bool'. On out-of-memory it returns None while nmlib.notmuch_threads_valid(self._threads): nmlib.notmuch_threads_move_to_next(self._threads) @@ -143,7 +143,7 @@ class Threads(object): =20 def __nonzero__(self): """Check if :class:`Threads` contains at least one more valid thre= ad - =20 + The existence of this function makes 'if Threads: foo' work, as that will implicitely call len() exhausting the iterator if __nonzero__ does not exist. This function makes `bool(Threads())` @@ -158,9 +158,9 @@ class Threads(object): def __del__(self): """Close and free the notmuch Threads""" if self._threads is not None: - nmlib.notmuch_messages_destroy (self._threads) + nmlib.notmuch_messages_destroy(self._threads) + =20 -#-------------------------------------------------------------------------= ----- class Thread(object): """Represents a single message thread.""" =20 @@ -218,7 +218,7 @@ class Thread(object): for as long as the thread is valid. =20 :returns: String with a message ID - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thre= ad=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thre= ad is not initialized. """ if self._thread is None: @@ -231,14 +231,13 @@ class Thread(object): :returns: The number of all messages in the database belonging to this thread. Contrast with :meth:`get_matched_messages`. - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thre= ad=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thre= ad is not initialized. """ if self._thread is None: raise NotmuchError(STATUS.NOT_INITIALIZED) return nmlib.notmuch_thread_get_total_messages(self._thread) =20 - def get_toplevel_messages(self): """Returns a :class:`Messages` iterator for the top-level messages= in 'thread' @@ -246,7 +245,7 @@ class Thread(object): This iterator will not necessarily iterate over all of the mess= ages in the thread. It will only iterate over the messages in the th= read which are not replies to other messages in the thread. -=20 + To iterate over all messages in the thread, the caller will nee= d to iterate over the result of :meth:`Message.get_replies` for each top-level message (and do that recursively for the resulting @@ -256,7 +255,7 @@ class Thread(object): :exception: :exc:`NotmuchError` =20 * STATUS.NOT_INITIALIZED if query is not inited - * STATUS.NULL_POINTER if search_messages failed=20 + * STATUS.NULL_POINTER if search_messages failed """ if self._thread is None: raise NotmuchError(STATUS.NOT_INITIALIZED) @@ -266,15 +265,15 @@ class Thread(object): if msgs_p is None: NotmuchError(STATUS.NULL_POINTER) =20 - return Messages(msgs_p,self) + return Messages(msgs_p, self) =20 def get_matched_messages(self): """Returns the number of messages in 'thread' that matched the que= ry =20 - :returns: The number of all messages belonging to this thread that= =20 + :returns: The number of all messages belonging to this thread that matched the :class:`Query`from which this thread was cre= ated. Contrast with :meth:`get_total_messages`. - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thre= ad=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thre= ad is not initialized. """ if self._thread is None: @@ -288,7 +287,7 @@ class Thread(object): authors of mail messages in the query results that belong to this thread. =20 - The returned string belongs to 'thread' and will only be valid for= =20 + The returned string belongs to 'thread' and will only be valid for as long as this Thread() is not deleted. """ if self._thread is None: @@ -298,7 +297,7 @@ class Thread(object): def get_subject(self): """Returns the Subject of 'thread' =20 - The returned string belongs to 'thread' and will only be valid for= =20 + The returned string belongs to 'thread' and will only be valid for as long as this Thread() is not deleted. """ if self._thread is None: @@ -310,7 +309,7 @@ class Thread(object): =20 :returns: A time_t timestamp. :rtype: c_unit64 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age is not initialized. """ if self._thread is None: @@ -322,7 +321,7 @@ class Thread(object): =20 :returns: A time_t timestamp. :rtype: c_unit64 - :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age=20 + :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the mess= age is not initialized. """ if self._thread is None: @@ -337,14 +336,14 @@ class Thread(object): tags of the messages which matched the search and which belong to this thread. =20 - The :class:`Tags` object is owned by the thread and as such, will = only=20 - be valid for as long as this :class:`Thread` is valid (e.g. until = the=20 + The :class:`Tags` object is owned by the thread and as such, will = only + be valid for as long as this :class:`Thread` is valid (e.g. until = the query from which it derived is explicitely deleted). =20 :returns: A :class:`Tags` iterator. :exception: :exc:`NotmuchError` =20 - * STATUS.NOT_INITIALIZED if the thread=20 + * STATUS.NOT_INITIALIZED if the thread is not initialized. * STATUS.NULL_POINTER, on error """ @@ -355,7 +354,7 @@ class Thread(object): if tags_p =3D=3D None: raise NotmuchError(STATUS.NULL_POINTER) return Tags(tags_p, self) -=20 + def __str__(self): """A str(Thread()) is represented by a 1-line summary""" thread =3D {} @@ -374,9 +373,15 @@ class Thread(object): thread['subject'] =3D self.get_subject() thread['tags'] =3D self.get_tags() =20 - return "thread:%(id)s %(date)12s [%(matched)d/%(total)d] %(authors= )s; %(subject)s (%(tags)s)" % (thread) + return "thread:%s %12s [%d/%d] %s; %s (%s)" % (thread['id'], + thread['date'], + thread['matched'], + thread['total'], + thread['authors'], + thread['subject'], + thread['tags']) =20 def __del__(self): """Close and free the notmuch Thread""" if self._thread is not None: - nmlib.notmuch_thread_destroy (self._thread) + nmlib.notmuch_thread_destroy(self._thread) --=20 1.7.4.1 --hYooF8G/hrfVAmum Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0008-pep8-compliance-for-__init__.py.patch" Content-Transfer-Encoding: quoted-printable =46rom 3acb98be0151a6c7e310a4e6334d069a383a4459 Mon Sep 17 00:00:00 2001 =46rom: pazz Date: Tue, 12 Jul 2011 21:23:37 +0100 Subject: [PATCH 8/8] pep8 compliance for __init__.py --- bindings/python/notmuch/__init__.py | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bindings/python/notmuch/__init__.py b/bindings/python/notmuch/= __init__.py index 4331d9d..cb64f3c 100644 --- a/bindings/python/notmuch/__init__.py +++ b/bindings/python/notmuch/__init__.py @@ -1,9 +1,10 @@ -"""The :mod:`notmuch` module provides most of the functionality that a use= r is likely to need. +"""The :mod:`notmuch` module provides most of the functionality that a use= r is +likely to need. =20 .. note:: The underlying notmuch library is build on a hierarchical memory allocator called talloc. All objects derive from a top-level :class:`Database` object. - =20 + This means that as soon as an object is deleted, all underlying derived objects such as Queries, Messages, Message, and Tags will be freed by the underlying library as well. Accessing these @@ -56,6 +57,6 @@ from notmuch.message import Messages, Message from notmuch.thread import Threads, Thread from notmuch.tag import Tags from notmuch.globals import nmlib, STATUS, NotmuchError -__LICENSE__=3D"GPL v3+" -__VERSION__=3D'0.6' -__AUTHOR__ =3D'Sebastian Spaeth ' +__LICENSE__ =3D "GPL v3+" +__VERSION__ =3D '0.6' +__AUTHOR__ =3D 'Sebastian Spaeth ' --=20 1.7.4.1 --hYooF8G/hrfVAmum-- --g7w8+K/95kPelPD2 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk4csHEACgkQlDQDZ9fWxarsoQCdGVgyr1+euBL93S84tpt4LWTp cmgAoJmUYNDV52WRfj3Gz77IhxuduLvP =wITe -----END PGP SIGNATURE----- --g7w8+K/95kPelPD2--