diff options
Diffstat (limited to 'src/mailman/model/messagestore.py')
| -rw-r--r-- | src/mailman/model/messagestore.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/mailman/model/messagestore.py b/src/mailman/model/messagestore.py index a4950e8c9..19fa8133f 100644 --- a/src/mailman/model/messagestore.py +++ b/src/mailman/model/messagestore.py @@ -54,12 +54,13 @@ class MessageStore: def add(self, store, message): # Ensure that the message has the requisite headers. message_ids = message.get_all('message-id', []) - if len(message_ids) <> 1: + if len(message_ids) != 1: raise ValueError('Exactly one Message-ID header required') # Calculate and insert the X-Message-ID-Hash. message_id = message_ids[0] # Complain if the Message-ID already exists in the storage. - existing = store.find(Message, Message.message_id == message_id).one() + existing = store.query(Message).filter( + Message.message_id == message_id).first() if existing is not None: raise ValueError( 'Message ID already exists in message store: {0}'.format( @@ -80,9 +81,9 @@ class MessageStore: # providing a unique serial number, but to get this information, we # have to use a straight insert instead of relying on Elixir to create # the object. - row = Message(message_id=message_id, - message_id_hash=hash32, - path=relpath) + Message(message_id=message_id, + message_id_hash=hash32, + path=relpath) # Now calculate the full file system path. path = os.path.join(config.MESSAGES_DIR, relpath) # Write the file to the path, but catch the appropriate exception in @@ -95,7 +96,7 @@ class MessageStore: pickle.dump(message, fp, -1) break except IOError as error: - if error.errno <> errno.ENOENT: + if error.errno != errno.ENOENT: raise makedirs(os.path.dirname(path)) return hash32 @@ -107,7 +108,7 @@ class MessageStore: @dbconnection def get_message_by_id(self, store, message_id): - row = store.find(Message, message_id=message_id).one() + row = store.query(Message).filter_by(message_id=message_id).first() if row is None: return None return self._get_message(row) @@ -116,11 +117,11 @@ class MessageStore: def get_message_by_hash(self, store, message_id_hash): # It's possible the hash came from a message header, in which case it # will be a Unicode. However when coming from source code, it may be - # an 8-string. Coerce to the latter if necessary; it must be - # US-ASCII. - if isinstance(message_id_hash, unicode): + # bytes object. Coerce to the latter if necessary; it must be ASCII. + if not isinstance(message_id_hash, bytes): message_id_hash = message_id_hash.encode('ascii') - row = store.find(Message, message_id_hash=message_id_hash).one() + row = store.query(Message).filter_by( + message_id_hash=message_id_hash).first() if row is None: return None return self._get_message(row) @@ -128,14 +129,14 @@ class MessageStore: @property @dbconnection def messages(self, store): - for row in store.find(Message): + for row in store.query(Message).all(): yield self._get_message(row) @dbconnection def delete_message(self, store, message_id): - row = store.find(Message, message_id=message_id).one() + row = store.query(Message).filter_by(message_id=message_id).first() if row is None: raise LookupError(message_id) path = os.path.join(config.MESSAGES_DIR, row.path) os.remove(path) - store.remove(row) + store.delete(row) |
