* [python] pep8
@ 2011-07-12 20:37 Patrick Totzke
0 siblings, 0 replies; only message in thread
From: Patrick Totzke @ 2011-07-12 20:37 UTC (permalink / raw)
To: notmuch
[-- Attachment #1.1: Type: text/plain, Size: 294 bytes --]
hi all,
I just read I'm a bit late with this as Sebastian is going on holiday for the
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 whitespaces.
best,
/p
[-- Attachment #1.2: 0002-pep8-compliance-for-message.py.patch --]
[-- Type: text/x-diff, Size: 21046 bytes --]
From f1894462d690924c568213cd497d3546ea3fc362 Mon Sep 17 00:00:00 2001
From: pazz <patricktotzke@gmail.com>
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/message.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 <Sebastian@SSpaeth.de>'
Jesse Rosenthal <jrosenthal@jhu.edu>
"""
-
+
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
@@ -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.
-
- # You can reiterate over *msglist* however as often as you want.
+
+ # You can reiterate over *msglist* however as often as you want.
# It is simply a list with :class:`Message`s.
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
+ :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)
# collect all tags (returns NULL on error)
- tags_p = Messages._collect_tags (self._msgs)
+ tags_p = Messages._collect_tags(self._msgs)
#reset _msgs as we iterated over it and can do so only once
self._msgs = None
@@ -153,7 +154,7 @@ class Messages(object):
self._msgs = None
raise StopIteration
- msg = Message(Messages._get (self._msgs), self)
+ msg = Message(Messages._get(self._msgs), self)
nmlib.notmuch_messages_move_to_next(self._msgs)
return msg
@@ -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)
def print_messages(self, format, indent=0, entire_thread=False):
"""Outputs messages as needed for 'notmuch show' to sys.stdout
:param format: A string of either 'text' or 'json'.
:param indent: A number indicating the reply depth of these messages.
- :param entire_thread: A bool, indicating whether we want to output
+ :param entire_thread: A bool, indicating whether we want to output
whole threads or only the matching messages.
"""
if format.lower() == "text":
@@ -195,7 +196,7 @@ class Messages(object):
# iterate through all toplevel messages in this thread
for msg in self:
# if not msg:
- # break
+ # break
if not first_set:
sys.stdout.write(set_sep)
first_set = False
@@ -222,7 +223,7 @@ class Messages(object):
sys.stdout.write(set_end)
sys.stdout.write(set_end)
-#------------------------------------------------------------------------------
+
class Message(object):
"""Represents a single Email message
@@ -236,7 +237,7 @@ class Message(object):
"""notmuch_message_get_filename (notmuch_message_t *message)"""
_get_filename = nmlib.notmuch_message_get_filename
- _get_filename.restype = c_char_p
+ _get_filename.restype = c_char_p
"""return all filenames for a message"""
_get_filenames = nmlib.notmuch_message_get_filenames
@@ -248,7 +249,7 @@ class Message(object):
"""notmuch_message_get_message_id (notmuch_message_t *message)"""
_get_message_id = nmlib.notmuch_message_get_message_id
- _get_message_id.restype = c_char_p
+ _get_message_id.restype = c_char_p
"""notmuch_message_get_thread_id"""
_get_thread_id = nmlib.notmuch_message_get_thread_id
@@ -296,12 +297,11 @@ class Message(object):
#keep reference to parent, so we keep it alive
self._parent = parent
-
def get_message_id(self):
"""Returns the message ID
-
+
:returns: String with a message ID
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
if self._msg is None:
@@ -311,23 +311,24 @@ class Message(object):
def get_thread_id(self):
"""Returns the thread ID
- The returned string belongs to 'message' will only be valid for as
+ The returned string belongs to 'message' will only be valid for as
long as the message is valid.
This function will not return `None` since Notmuch ensures that every
message belongs to a single thread.
:returns: String with a thread ID
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
if self._msg is None:
raise NotmuchError(STATUS.NOT_INITIALIZED)
- return Message._get_thread_id (self._msg);
+ return Message._get_thread_id(self._msg)
def get_replies(self):
- """Gets all direct replies to this message as :class:`Messages` iterator
+ """Gets all direct replies to this message as :class:`Messages`
+ iterator
.. 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`.
- :returns: :class:`Messages` or `None` if there are no replies to
+ :returns: :class:`Messages` or `None` if there are no replies to
this message.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
if self._msg is None:
raise NotmuchError(STATUS.NOT_INITIALIZED)
- msgs_p = Message._get_replies(self._msg);
+ msgs_p = Message._get_replies(self._msg)
if msgs_p is None:
return None
- return Messages(msgs_p,self)
+ return Messages(msgs_p, self)
def get_date(self):
"""Returns time_t of the message date
@@ -362,7 +363,7 @@ class Message(object):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
if self._msg is None:
@@ -371,7 +372,7 @@ class Message(object):
def get_header(self, header):
"""Returns a message header
-
+
This returns any message header that is stored in the notmuch database.
This is only a selected subset of headers, which is currently:
@@ -383,7 +384,7 @@ class Message(object):
:returns: The header value as a unicode string
:exception: :exc:`NotmuchError`
- * STATUS.NOT_INITIALIZED if the message
+ * 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)
#Returns NULL if any error occurs.
- header = Message._get_header (self._msg, header)
+ header = Message._get_header(self._msg, header)
if header == 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
:returns: Absolute file path & name of the message file
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
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)
-
+
files_p = Message._get_filenames(self._msg)
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.
- :param flag: One of the :attr:`Message.FLAG` values (currently only
+ :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 set.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
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
- :param flag: One of the :attr:`Message.FLAG` values (currently only
+ :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.
:returns: Nothing
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
if self._msg is None:
@@ -460,7 +461,7 @@ class Message(object):
:returns: A :class:`Tags` iterator.
:exception: :exc:`NotmuchError`
- * STATUS.NOT_INITIALIZED if the message
+ * 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
+ 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 cannot be
+ Database was opened in read-only mode so message cannot 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)
- status = nmlib.notmuch_message_add_tag (self._msg, tag)
+ status = nmlib.notmuch_message_add_tag(self._msg, tag)
# bail out on failure
if status != 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.
- :returns: STATUS.SUCCESS if the tag was successfully removed or if
+ :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 cannot
+ Database was opened in read-only mode so message cannot
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
-
-
def remove_all_tags(self, sync_maildir_flags=False):
"""Removes all tags from the given message.
@@ -581,14 +580,14 @@ class Message(object):
:exception: :exc:`NotmuchError`. They have the following meaning:
STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot
+ Database was opened in read-only mode so message cannot
be modified.
STATUS.NOT_INITIALIZED
The message has not been initialized.
"""
if self._msg is None:
raise NotmuchError(STATUS.NOT_INITIALIZED)
-
+
status = nmlib.notmuch_message_remove_all_tags(self._msg)
# bail out on error
@@ -602,8 +601,8 @@ class Message(object):
def freeze(self):
"""Freezes the current state of 'message' within the database
- This means that changes to the message state, (via :meth:`add_tag`,
- :meth:`remove_tag`, and :meth:`remove_all_tags`), will not be
+ 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.
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:
STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so message cannot
+ Database was opened in read-only mode so message cannot
be modified.
STATUS.NOT_INITIALIZED
The message has not been initialized.
"""
if self._msg is None:
raise NotmuchError(STATUS.NOT_INITIALIZED)
-
+
status = nmlib.notmuch_message_freeze(self._msg)
if STATUS.SUCCESS == status:
@@ -654,7 +653,7 @@ class Message(object):
def thaw(self):
"""Thaws the current 'message'
- Thaw the current 'message', synchronizing any changes that may have
+ Thaw the current 'message', synchronizing any changes that may have
occurred while 'message' was frozen into the notmuch database.
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:
STATUS.UNBALANCED_FREEZE_THAW
- An attempt was made to thaw an unfrozen message.
- That is, there have been an unbalanced number of calls
+ 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)
-
+
status = nmlib.notmuch_message_thaw(self._msg)
if STATUS.SUCCESS == status:
@@ -686,7 +685,6 @@ class Message(object):
raise NotmuchError(status)
-
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
-
+
Any existing flags unmentioned in the list above will be
preserved in the renaming.
-
+
Also, if this filename is in a directory named "new", rename it
to be within the neighboring directory named "cur".
@@ -755,7 +753,6 @@ class Message(object):
msg['date'] = date.fromtimestamp(self.get_date())
return "%(from)s (%(date)s) (%(tags)s)" % (msg)
-
def get_message_parts(self):
"""Output like notmuch show"""
fp = open(self.get_filename())
@@ -804,7 +801,7 @@ class Message(object):
part_dict["content-type"] = cont_type
# NOTE:
# Now we emulate the current behaviour, where it ignores
- # the html if there's a text representation.
+ # 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() == "text/plain":
part_dict["content"] = msg.get_payload()
- elif (cont_type.lower() == "text/html" and
+ elif (cont_type.lower() == "text/html" and
i == 0):
part_dict["content"] = msg.get_payload()
body.append(part_dict)
@@ -860,18 +857,18 @@ class Message(object):
parts = format["body"]
parts.sort(key=lambda x: x['id'])
for p in parts:
- if not p.has_key("filename"):
+ if not "filename" in p:
output += "\n\fpart{ "
- output += "ID: %d, Content-type: %s\n" % (p["id"],
- p["content-type"])
- if p.has_key("content"):
+ output += "ID: %d, Content-type: %s\n" % (p["id"],
+ p["content-type"])
+ if "content" in p:
output += "\n%s\n" % p["content"]
else:
output += "Non-text part: %s\n" % p["content-type"]
- output += "\n\fpart}"
+ output += "\n\fpart}"
else:
output += "\n\fattachment{ "
- output += "ID: %d, Content-type:%s\n" % (p["id"],
+ output += "ID: %d, Content-type:%s\n" % (p["id"],
p["content-type"])
output += "Attachment: %s\n" % p["filename"]
output += "\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 = cmp(self.get_message_id(), other.get_message_id())
+ res = cmp(self.get_message_id(), other.get_message_id())
if res:
res = cmp(list(self.get_filenames()), list(other.get_filenames()))
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)
--
1.7.4.1
[-- Attachment #1.3: 0003-pep8-compliance-for-database.py.patch --]
[-- Type: text/x-diff, Size: 24160 bytes --]
From 3cae17dfd64bc63ae89a2d95cd6ace7cc98807de Mon Sep 17 00:00:00 2001
From: pazz <patricktotzke@gmail.com>
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
+
class Database(object):
"""Represents a notmuch database (wraps notmuch_database_t)
@@ -36,7 +37,7 @@ class Database(object):
_std_db_path = None
"""Class attribute to cache user's default database"""
- MODE = Enum(['READ_ONLY','READ_WRITE'])
+ MODE = Enum(['READ_ONLY', 'READ_WRITE'])
"""Constants: Mode in which to open the database"""
"""notmuch_database_get_directory"""
@@ -52,7 +53,7 @@ class Database(object):
_get_version.restype = c_uint
"""notmuch_database_open"""
- _open = nmlib.notmuch_database_open
+ _open = nmlib.notmuch_database_open
_open.restype = c_void_p
"""notmuch_database_upgrade"""
@@ -71,9 +72,9 @@ class Database(object):
_create = nmlib.notmuch_database_create
_create.restype = c_void_p
- def __init__(self, path=None, create=False, mode= 0):
- """If *path* is `None`, we will try to read a users notmuch
- configuration and use his configured database. The location of the
+ def __init__(self, path=None, create=False, mode=0):
+ """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 variable
*NOTMUCH_CONFIG*, falling back to the default `~/.notmuch-config`.
@@ -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.
+ database.
:type create: bool
- :param mode: Mode to open a database in. Is always
+ :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 = self._get_user_default_db()
path = Database._std_db_path
- assert isinstance(path, basestring), 'Path needs to be a string or None.'
+ assert isinstance(path, basestring), 'Path must be a string or None.'
if create == 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)
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
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="Cannot create db, this Database() already has an open one.")
+ raise NotmuchError(message="Cannot create db, this Database() "
+ "already has an open one.")
res = Database._create(path, Database.MODE.READ_WRITE)
@@ -138,7 +139,7 @@ class Database(object):
message="Could not create the specified database")
self._db = res
- def open(self, path, mode= 0):
+ def open(self, path, mode=0):
"""Opens an existing database
This function is used by __init__() and usually does not need
@@ -146,7 +147,7 @@ class Database(object):
*notmuch_database_open* function.
:param status: Open the database in read-only or read-write mode
- :type status: :attr:`MODE`
+ :type status: :attr:`MODE`
:returns: Nothing
:exception: Raises :exc:`NotmuchError` in case
of any failure (after printing an error message on stderr).
@@ -178,7 +179,7 @@ class Database(object):
# Raise a NotmuchError if not initialized
self._verify_initialized_db()
- return Database._get_version (self._db)
+ return Database._get_version(self._db)
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()
- return nmlib.notmuch_database_needs_upgrade(self._db)
+ return nmlib.notmuch_database_needs_upgrade(self._db)
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]
+ 'progress' as a floating-point value in the range of [0.0..1.0]
indicating the progress made so far in the upgrade process.
: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()
- status = Database._upgrade (self._db, None, None)
+ status = Database._upgrade(self._db, None, None)
#TODO: catch exceptions, document return values and etc
return status
def get_directory(self, path):
- """Returns a :class:`Directory` of path,
+ """Returns a :class:`Directory` of path,
(creating it if it does not exist(?))
- .. warning:: This call needs a writeable database in
+ .. 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!
@@ -233,11 +234,11 @@ class Database(object):
:returns: :class:`Directory` or raises an exception.
:exception: :exc:`NotmuchError`
- STATUS.NOT_INITIALIZED
+ STATUS.NOT_INITIALIZED
If the database was not intitialized.
STATUS.FILE_ERROR
- If path is not relative database or absolute with initial
+ If path is not relative database or absolute with initial
components same as database.
"""
@@ -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,
- message="Database().get_directory() called with a wrong absolute path.")
+ raise NotmuchError(STATUS.FILE_ERROR,
+ message="Database().get_directory() called "
+ "with a wrong absolute path.")
abs_dirpath = path
else:
#we got a relative path, make it absolute
- abs_dirpath = os.path.abspath(os.path.join(self.get_path(),path))
+ abs_dirpath = os.path.abspath(os.path.join(self.get_path(), path))
- dir_p = Database._get_directory(self._db, path);
+ dir_p = Database._get_directory(self._db, path)
# 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`.
- :returns: On success, we return
+ :returns: On success, we return
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 database.
STATUS.FILE_ERROR
- An error occurred trying to open the file, (such as
+ 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 message.
+ 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 = nmlib.notmuch_database_add_message(self._db,
filename,
byref(msg_p))
-
+
if not status in [STATUS.SUCCESS, STATUS.DUPLICATE_MESSAGE_ID]:
raise NotmuchError(status)
@@ -341,17 +344,18 @@ class Database(object):
:returns: A STATUS value with the following meaning:
STATUS.SUCCESS
- The last filename was removed and the message was removed
+ 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
+ This filename was removed but the message persists in the
database with at least one other filename.
:exception: Raises a :exc:`NotmuchError` with the following meaning.
- If such an exception occurs, nothing was removed from the database.
+ If such an exception occurs, nothing was removed from the
+ database.
STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so no message can be
+ 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
- `None` is therefore no guarantee that the message
+ 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()
- tags_p = Database._get_all_tags (self._db)
+ tags_p = Database._get_all_tags(self._db)
if tags_p == None:
raise NotmuchError(STATUS.NULL_POINTER)
return Tags(tags_p, self)
@@ -442,10 +446,10 @@ class Database(object):
conf_f = os.getenv('NOTMUCH_CONFIG',
os.path.expanduser('~/.notmuch-config'))
config.read(conf_f)
- if not config.has_option('database','path'):
- raise NotmuchError(message=
- "No DB path specified and no user default found")
- return config.get('database','path')
+ if not config.has_option('database', 'path'):
+ raise NotmuchError(message="No DB path specified"
+ " and no user default found")
+ return config.get('database', 'path')
@property
def db_p(self):
@@ -456,7 +460,7 @@ class Database(object):
"""
return self._db
-#------------------------------------------------------------------------------
+
class Query(object):
"""Represents a search query on an opened :class:`Database`.
@@ -476,7 +480,7 @@ class Query(object):
other unexpected behavior. See above for more details.
"""
# constants
- SORT = Enum(['OLDEST_FIRST','NEWEST_FIRST','MESSAGE_ID', 'UNSORTED'])
+ SORT = Enum(['OLDEST_FIRST', 'NEWEST_FIRST', 'MESSAGE_ID', 'UNSORTED'])
"""Constants: Sort order in which to return results"""
"""notmuch_query_create"""
@@ -491,7 +495,6 @@ class Query(object):
_search_messages = nmlib.notmuch_query_search_messages
_search_messages.restype = c_void_p
-
"""notmuch_query_count_messages"""
_count_messages = nmlib.notmuch_query_count_messages
_count_messages.restype = c_uint
@@ -511,7 +514,7 @@ class Query(object):
def create(self, db, querystr):
"""Creates a new query derived from a Database
- This function is utilized by __init__() and usually does not need to
+ This function is utilized by __init__() and usually does not need to
be called directly.
:param db: Database to create the query from.
@@ -522,11 +525,11 @@ class Query(object):
:exception: :exc:`NotmuchError`
* STATUS.NOT_INITIALIZED if db is not inited
- * STATUS.NULL_POINTER if the query creation failed
+ * STATUS.NULL_POINTER if the query creation failed
(too little memory)
"""
if db.db_p is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
# create reference to parent db to keep it alive
self._db = db
if isinstance(querystr, unicode):
@@ -545,7 +548,7 @@ class Query(object):
:param sort: Sort order (see :attr:`Query.SORT`)
:returns: Nothing
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if query has not
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if query has not
been initialized.
"""
if self._query is None:
@@ -558,7 +561,7 @@ class Query(object):
"""Execute a query for threads
Execute a query for threads, returning a :class:`Threads` iterator.
- The returned threads are owned by the query and as such, will only be
+ The returned threads are owned by the query and as such, will only be
valid until the Query is deleted.
The method sets :attr:`Message.FLAG`\.MATCH for those messages that
@@ -572,17 +575,17 @@ class Query(object):
:exception: :exc:`NotmuchError`
* STATUS.NOT_INITIALIZED if query is not inited
- * STATUS.NULL_POINTER if search_threads failed
+ * STATUS.NULL_POINTER if search_threads failed
"""
if self._query is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
threads_p = Query._search_threads(self._query)
if threads_p is None:
NotmuchError(STATUS.NULL_POINTER)
- return Threads(threads_p,self)
+ return Threads(threads_p, self)
def search_messages(self):
"""Filter messages according to the query and return
@@ -595,17 +598,17 @@ class Query(object):
:exception: :exc:`NotmuchError`
* STATUS.NOT_INITIALIZED if query is not inited
- * STATUS.NULL_POINTER if search_messages failed
+ * STATUS.NULL_POINTER if search_messages failed
"""
if self._query is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
msgs_p = Query._search_messages(self._query)
if msgs_p is None:
NotmuchError(STATUS.NULL_POINTER)
- return Messages(msgs_p,self)
+ return Messages(msgs_p, self)
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)
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
return Query._count_messages(self._query)
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)
-#------------------------------------------------------------------------------
class Directory(object):
"""Represents a directory entry in the notmuch directory
@@ -665,9 +667,9 @@ class Directory(object):
_get_child_directories.restype = c_void_p
def _verify_dir_initialized(self):
- """Raises a NotmuchError(STATUS.NOT_INITIALIZED) if the dir_p is None"""
+ """Raises a NotmuchError(STATUS.NOT_INITIALIZED) if dir_p is None"""
if self._dir_p is None:
- raise NotmuchError(STATUS.NOT_INITIALIZED)
+ raise NotmuchError(STATUS.NOT_INITIALIZED)
def __init__(self, path, dir_p, parent):
"""
@@ -683,8 +685,7 @@ class Directory(object):
self._dir_p = dir_p
self._parent = parent
-
- def set_mtime (self, mtime):
+ def set_mtime(self, mtime):
"""Sets the mtime value of this directory in the database
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:
* Read the mtime of a directory from the filesystem
-
+
* Call :meth:`Database.add_message` for all mail files in
the directory
- * Call notmuch_directory_set_mtime with the mtime read from the
+ * 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
+ and know that it only needs to add files if the mtime of the
directory and files are newer than the stored timestamp.
- .. note:: :meth:`get_mtime` function does not allow the caller
+ .. 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.
+ comfortable with that.
- :param mtime: A (time_t) timestamp
+ :param mtime: A (time_t) timestamp
:returns: Nothing on success, raising an exception on failure.
:exception: :exc:`NotmuchError`:
STATUS.XAPIAN_EXCEPTION
A Xapian exception occurred, mtime not stored.
STATUS.READ_ONLY_DATABASE
- Database was opened in read-only mode so directory
+ Database was opened in read-only mode so directory
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)
- def get_mtime (self):
+ def get_mtime(self):
"""Gets the mtime value of this directory in the database
Retrieves a previously stored mtime for this directory.
- :param mtime: A (time_t) timestamp
+ :param mtime: A (time_t) timestamp
:returns: Nothing on success, raising an exception on failure.
:exception: :exc:`NotmuchError`:
@@ -746,19 +747,19 @@ class Directory(object):
#Raise a NotmuchError(STATUS.NOT_INITIALIZED) if self.dir_p is None
self._verify_dir_initialized()
- return Directory._get_mtime (self._dir_p)
+ return Directory._get_mtime(self._dir_p)
# Make mtime attribute a property of Directory()
mtime = property(get_mtime, set_mtime, doc="""Property that allows getting
and setting of the Directory *mtime* (read-write)
- See :meth:`get_mtime` and :meth:`set_mtime` for usage and
+ See :meth:`get_mtime` and :meth:`set_mtime` for usage and
possible exceptions.""")
def get_child_files(self):
"""Gets a Filenames iterator listing all the filenames of
messages in the database within the given directory.
-
+
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
-
+
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)
-#------------------------------------------------------------------------------
+
class Filenames(object):
- """An iterator over File- or Directory names that are stored in the database
- """
+ """An iterator over File- or Directory names stored in the database"""
#notmuch_filenames_get
_get = nmlib.notmuch_filenames_get
@@ -828,14 +828,14 @@ class Filenames(object):
self._files_p = None
raise StopIteration
- file = Filenames._get (self._files_p)
+ file = Filenames._get(self._files_p)
nmlib.notmuch_filenames_move_to_next(self._files_p)
return file
def __len__(self):
"""len(:class:`Filenames`) returns the number of contained files
- .. note:: As this iterates over the files, we will not be able to
+ .. note:: As this iterates over the files, we will not be able to
iterate over them again! So this will fail::
#THIS FAILS
@@ -847,7 +847,7 @@ class Filenames(object):
if self._files_p is None:
raise NotmuchError(STATUS.NOT_INITIALIZED)
- i=0
+ i = 0
while nmlib.notmuch_filenames_valid(self._files_p):
nmlib.notmuch_filenames_move_to_next(self._files_p)
i += 1
--
1.7.4.1
[-- Attachment #1.4: 0004-pep8-compliance-for-filename.py.patch --]
[-- Type: text/x-diff, Size: 2893 bytes --]
From fcea6c05cd89e21bd0743445b69f89f92affbdd0 Mon Sep 17 00:00:00 2001
From: pazz <patricktotzke@gmail.com>
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 <Sebastian@SSpaeth.de>'
from ctypes import c_char_p
from notmuch.globals import nmlib, STATUS, NotmuchError
-#------------------------------------------------------------------------------
+
class Filenames(object):
"""Represents a list of filenames as returned by notmuch
- This object contains the Filenames iterator. The main function is as_generator() which will return a generator so we can do a Filenamesth an iterator 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 Filenamesth an
+ iterator 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::
- for name in filenames: print name
+ for name in filenames: print name
as well as::
@@ -85,10 +86,10 @@ class Filenames(object):
self._files = None
return
- file = Filenames._get (self._files)
+ file = Filenames._get(self._files)
nmlib.notmuch_filenames_move_to_next(self._files)
yield file
-
+
def __str__(self):
"""Represent Filenames() as newline-separated list of full paths
@@ -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)
--
1.7.4.1
[-- Attachment #1.5: 0005-pep8-compliance-for-globals.py.patch --]
[-- Type: text/x-diff, Size: 3335 bytes --]
From 224636cd6339ea02a4d304df7b0e3ff958ea7718 Mon Sep 17 00:00:00 2001
From: pazz <patricktotzke@gmail.com>
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/globals.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.")
-#-----------------------------------------------------------------------------
+
class Enum(object):
"""Provides ENUMS as "code=Enum(['a','b','c'])" where code.a=0 etc..."""
def __init__(self, names):
for number, name in enumerate(names):
setattr(self, name, number)
-#-----------------------------------------------------------------------------
+
class Status(Enum):
"""Enum with a string representation of a notmuch_status_t value."""
_status2str = nmlib.notmuch_status_to_string
@@ -49,10 +49,10 @@ class Status(Enum):
@classmethod
def status2str(self, status):
- """Get a string representation of a notmuch_status_t value."""
+ """Get a string representation of a notmuch_status_t value."""
# define strings for custom error messages
if status == STATUS.NOT_INITIALIZED:
- return "Operation on uninitialized object impossible."
+ return "Operation on uninitialized object impossible."
return str(Status._status2str(status))
STATUS = Status(['SUCCESS',
@@ -66,7 +66,10 @@ STATUS = Status(['SUCCESS',
'TAG_TOO_LONG',
'UNBALANCED_FREEZE_THAW',
'NOT_INITIALIZED'])
-"""STATUS is a class, whose attributes provide constants that serve as return indicators for notmuch functions. Currently the following ones are defined. For possible return values and specific meaning for each method, see the method description.
+"""STATUS is a class, whose attributes provide constants that serve as return
+indicators for notmuch functions. Currently the following ones are defined. For
+possible return values and specific meaning for each method, see the method
+description.
* SUCCESS
* OUT_OF_MEMORY
@@ -80,8 +83,10 @@ STATUS = Status(['SUCCESS',
* UNBALANCED_FREEZE_THAW
* NOT_INITIALIZED
- Invoke the class method `notmuch.STATUS.status2str` with a status value as argument to receive a human readable string"""
-STATUS.__name__ = 'STATUS'
+Invoke the class method `notmuch.STATUS.status2str` with a status value as
+argument to receive a human readable string"""
+STATUS.__name__ = 'STATUS'
+
class NotmuchError(Exception):
def __init__(self, status=None, message=None):
@@ -89,6 +94,7 @@ class NotmuchError(Exception):
super(NotmuchError, self).__init__(message, status)
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])
--
1.7.4.1
[-- Attachment #1.6: 0006-pep8-compliance-for-tag.py.patch --]
[-- Type: text/x-diff, Size: 2744 bytes --]
From b257591409a6c5d5804b0e34a81bd95912a07c59 Mon Sep 17 00:00:00 2001
From: pazz <patricktotzke@gmail.com>
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 <Sebastian@SSpaeth.de>'
from ctypes import c_char_p
from notmuch.globals import nmlib, STATUS, NotmuchError
-#------------------------------------------------------------------------------
+
class Tags(object):
"""Represents a list of notmuch tags
This object provides an iterator over a list of notmuch tags (which
- are unicode instances).
+ are unicode instances).
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::
- for tag in tags: print tag
+ for tag in tags: print tag
as well as::
@@ -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
+ :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 = tags_p
#save reference to parent object so we keep it alive
self._parent = parent
-
+
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)
- i=0
+ i = 0
while nmlib.notmuch_tags_valid(self._msgs):
nmlib.notmuch_tags_move_to_next(self._msgs)
i += 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)
--
1.7.4.1
[-- Attachment #1.7: 0007-pep8-compliance-for-thread.py.patch --]
[-- Type: text/x-diff, Size: 10597 bytes --]
From 288f53704c95377f546a3b21651610a164c26950 Mon Sep 17 00:00:00 2001
From: pazz <patricktotzke@gmail.com>
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/thread.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
-#------------------------------------------------------------------------------
+
class Threads(object):
"""Represents a list of notmuch threads
@@ -59,13 +59,13 @@ class Threads(object):
for thread in threads:
threadlist.append(thread)
- # threads is "exhausted" now and even len(threads) will raise an
+ # threads is "exhausted" now and even len(threads) will raise an
# exception.
# However it will be kept around until all retrieved Thread() objects are
- # also deleted. If you did e.g. an explicit del(threads) here, the
+ # also deleted. If you did e.g. an explicit del(threads) here, the
# following lines would fail.
-
- # You can reiterate over *threadlist* however as often as you want.
+
+ # You can reiterate over *threadlist* however as often as you want.
# It is simply a list with Thread objects.
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
+ :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 = None
raise StopIteration
- thread = Thread(Threads._get (self._threads), self)
+ thread = Thread(Threads._get(self._threads), self)
nmlib.notmuch_threads_move_to_next(self._threads)
return thread
def __len__(self):
"""len(:class:`Threads`) returns the number of contained Threads
- .. note:: As this iterates over the threads, we will not be able to
+ .. note:: As this iterates over the threads, we will not be able to
iterate over them again! So this will fail::
#THIS FAILS
@@ -132,7 +132,7 @@ class Threads(object):
if self._threads is None:
raise NotmuchError(STATUS.NOT_INITIALIZED)
- i=0
+ i = 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):
def __nonzero__(self):
"""Check if :class:`Threads` contains at least one more valid thread
-
+
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)
+
-#------------------------------------------------------------------------------
class Thread(object):
"""Represents a single message thread."""
@@ -218,7 +218,7 @@ class Thread(object):
for as long as the thread is valid.
:returns: String with a message ID
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
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 thread
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
is not initialized.
"""
if self._thread is None:
raise NotmuchError(STATUS.NOT_INITIALIZED)
return nmlib.notmuch_thread_get_total_messages(self._thread)
-
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 messages
in the thread. It will only iterate over the messages in the thread
which are not replies to other messages in the thread.
-
+
To iterate over all messages in the thread, the caller will need 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`
* STATUS.NOT_INITIALIZED if query is not inited
- * STATUS.NULL_POINTER if search_messages failed
+ * 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)
- return Messages(msgs_p,self)
+ return Messages(msgs_p, self)
def get_matched_messages(self):
"""Returns the number of messages in 'thread' that matched the query
- :returns: The number of all messages belonging to this thread that
+ :returns: The number of all messages belonging to this thread that
matched the :class:`Query`from which this thread was created.
Contrast with :meth:`get_total_messages`.
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the thread
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.
- The returned string belongs to 'thread' and will only be valid for
+ 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'
- The returned string belongs to 'thread' and will only be valid for
+ 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):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
is not initialized.
"""
if self._thread is None:
@@ -322,7 +321,7 @@ class Thread(object):
:returns: A time_t timestamp.
:rtype: c_unit64
- :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
+ :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message
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.
- 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
+ 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).
:returns: A :class:`Tags` iterator.
:exception: :exc:`NotmuchError`
- * STATUS.NOT_INITIALIZED if the thread
+ * STATUS.NOT_INITIALIZED if the thread
is not initialized.
* STATUS.NULL_POINTER, on error
"""
@@ -355,7 +354,7 @@ class Thread(object):
if tags_p == None:
raise NotmuchError(STATUS.NULL_POINTER)
return Tags(tags_p, self)
-
+
def __str__(self):
"""A str(Thread()) is represented by a 1-line summary"""
thread = {}
@@ -374,9 +373,15 @@ class Thread(object):
thread['subject'] = self.get_subject()
thread['tags'] = self.get_tags()
- 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'])
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)
--
1.7.4.1
[-- Attachment #1.8: 0008-pep8-compliance-for-__init__.py.patch --]
[-- Type: text/x-diff, Size: 1556 bytes --]
From 3acb98be0151a6c7e310a4e6334d069a383a4459 Mon Sep 17 00:00:00 2001
From: pazz <patricktotzke@gmail.com>
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 user is likely to need.
+"""The :mod:`notmuch` module provides most of the functionality that a user is
+likely to need.
.. note:: The underlying notmuch library is build on a hierarchical
memory allocator called talloc. All objects derive from a
top-level :class:`Database` object.
-
+
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__="GPL v3+"
-__VERSION__='0.6'
-__AUTHOR__ ='Sebastian Spaeth <Sebastian@SSpaeth.de>'
+__LICENSE__ = "GPL v3+"
+__VERSION__ = '0.6'
+__AUTHOR__ = 'Sebastian Spaeth <Sebastian@SSpaeth.de>'
--
1.7.4.1
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2011-07-12 20:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-12 20:37 [python] pep8 Patrick Totzke
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).