diff options
| author | Abhilash Raj | 2014-09-25 18:36:24 +0530 |
|---|---|---|
| committer | Abhilash Raj | 2014-09-25 18:36:24 +0530 |
| commit | 95fc64b4894e5985bb8d0e5e944b2cda38c9a58c (patch) | |
| tree | 697f18eb33eddc8a16e2b09f4b4be4aaf0cf0dbe | |
| parent | f2c619de76bd1614a6609f1a61e34ecf8a4344fc (diff) | |
| download | mailman-95fc64b4894e5985bb8d0e5e944b2cda38c9a58c.tar.gz mailman-95fc64b4894e5985bb8d0e5e944b2cda38c9a58c.tar.zst mailman-95fc64b4894e5985bb8d0e5e944b2cda38c9a58c.zip | |
| -rw-r--r-- | src/mailman/database/model.py | 2 | ||||
| -rw-r--r-- | src/mailman/database/postgresql.py | 9 | ||||
| -rw-r--r-- | src/mailman/database/types.py | 3 | ||||
| -rw-r--r-- | src/mailman/model/docs/messagestore.rst | 5 | ||||
| -rw-r--r-- | src/mailman/model/message.py | 4 | ||||
| -rw-r--r-- | src/mailman/model/messagestore.py | 10 | ||||
| -rw-r--r-- | src/mailman/model/pending.py | 2 | ||||
| -rw-r--r-- | src/mailman/styles/base.py | 4 | ||||
| -rw-r--r-- | src/mailman/testing/testing.cfg | 6 | ||||
| -rw-r--r-- | src/mailman/utilities/importer.py | 9 |
10 files changed, 33 insertions, 21 deletions
diff --git a/src/mailman/database/model.py b/src/mailman/database/model.py index 06705dfe9..b65d7d5eb 100644 --- a/src/mailman/database/model.py +++ b/src/mailman/database/model.py @@ -49,7 +49,7 @@ class ModelMeta: for table in reversed(Model.metadata.sorted_tables): connection.execute(table.delete()) except: - transaction.abort() + transaction.rollback() raise else: transaction.commit() diff --git a/src/mailman/database/postgresql.py b/src/mailman/database/postgresql.py index 59fff0865..ca1068302 100644 --- a/src/mailman/database/postgresql.py +++ b/src/mailman/database/postgresql.py @@ -40,15 +40,14 @@ class PostgreSQLDatabase(SABaseDatabase): restart from zero for new tests. """ super(PostgreSQLDatabase, self)._post_reset(store) - from mailman.database.model import ModelMeta - classes = sorted(ModelMeta._class_registry, - key=attrgetter('__storm_table__')) + from mailman.database.model import Model + tables = reversed(Model.metadata.sorted_tables) # Recipe adapted from # http://stackoverflow.com/questions/544791/ # django-postgresql-how-to-reset-primary-key - for model_class in classes: + for table in tables: store.execute("""\ SELECT setval('"{0}_id_seq"', coalesce(max("id"), 1), max("id") IS NOT null) FROM "{0}"; - """.format(model_class.__storm_table__)) + """.format(table)) diff --git a/src/mailman/database/types.py b/src/mailman/database/types.py index 641e065ba..eec6df6d5 100644 --- a/src/mailman/database/types.py +++ b/src/mailman/database/types.py @@ -30,6 +30,7 @@ import uuid from sqlalchemy import Integer from sqlalchemy.types import TypeDecorator, CHAR +from sqlalchemy.dialects import postgresql @@ -68,7 +69,7 @@ class UUID(TypeDecorator): def load_dialect_impl(self, dialect): if dialect.name == 'postgresql': - return dialect.type_descriptor(UUID()) + return dialect.type_descriptor(postgresql.UUID()) else: return dialect.type_descriptor(CHAR(32)) diff --git a/src/mailman/model/docs/messagestore.rst b/src/mailman/model/docs/messagestore.rst index f2f2ca9d2..bb853e575 100644 --- a/src/mailman/model/docs/messagestore.rst +++ b/src/mailman/model/docs/messagestore.rst @@ -28,9 +28,8 @@ header, you will get an exception. However, if the message has a ``Message-ID`` header, it can be stored. >>> msg['Message-ID'] = '<87myycy5eh.fsf@uwakimon.sk.tsukuba.ac.jp>' - >>> x_message_id_hash = message_store.add(msg) - >>> print(x_message_id_hash) - AGDWSNXXKCWEILKKNYTBOHRDQGOX3Y35 + >>> message_store.add(msg) + 'AGDWSNXXKCWEILKKNYTBOHRDQGOX3Y35' >>> print(msg.as_string()) Subject: An important message Message-ID: <87myycy5eh.fsf@uwakimon.sk.tsukuba.ac.jp> diff --git a/src/mailman/model/message.py b/src/mailman/model/message.py index 74a76ac30..c03d4bbd6 100644 --- a/src/mailman/model/message.py +++ b/src/mailman/model/message.py @@ -41,8 +41,8 @@ class Message(Model): id = Column(Integer, primary_key=True) message_id = Column(Unicode) - message_id_hash = Column(Unicode) - path = Column(LargeBinary) # TODO : was RawStr() + message_id_hash = Column(LargeBinary) + path = Column(LargeBinary) # This is a Messge-ID field representation, not a database row id. @dbconnection diff --git a/src/mailman/model/messagestore.py b/src/mailman/model/messagestore.py index 225d3d1ce..0b8a0ac78 100644 --- a/src/mailman/model/messagestore.py +++ b/src/mailman/model/messagestore.py @@ -66,7 +66,7 @@ class MessageStore: 'Message ID already exists in message store: {0}'.format( message_id)) shaobj = hashlib.sha1(message_id) - hash32 = base64.b32encode(shaobj.digest()).decode('ascii') + hash32 = base64.b32encode(shaobj.digest()) del message['X-Message-ID-Hash'] message['X-Message-ID-Hash'] = hash32 # Calculate the path on disk where we're going to store this message @@ -115,8 +115,12 @@ class MessageStore: @dbconnection def get_message_by_hash(self, store, message_id_hash): - if isinstance(message_id_hash, bytes): - message_id_hash = message_id_hash.decode('utf-8') + # 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): + message_id_hash = message_id_hash.encode('ascii') row = store.query(Message).filter_by( message_id_hash=message_id_hash).first() if row is None: diff --git a/src/mailman/model/pending.py b/src/mailman/model/pending.py index 68a8cd63e..691e94fd9 100644 --- a/src/mailman/model/pending.py +++ b/src/mailman/model/pending.py @@ -71,7 +71,7 @@ class Pended(Model): __tablename__ = 'pended' id = Column(Integer, primary_key=True) - token = Column(LargeBinary) # TODO : was RawStr() + token = Column(LargeBinary) expiration_date = Column(DateTime) key_values = relationship('PendedKeyValue') diff --git a/src/mailman/styles/base.py b/src/mailman/styles/base.py index d83b2e2a5..4f051c13c 100644 --- a/src/mailman/styles/base.py +++ b/src/mailman/styles/base.py @@ -67,9 +67,9 @@ class Identity: # Set this to Never if the list's preferred language uses us-ascii, # otherwise set it to As Needed. if mlist.preferred_language.charset == 'us-ascii': - mlist.encode_ascii_prefixes = 0 + mlist.encode_ascii_prefixes = False else: - mlist.encode_ascii_prefixes = 2 + mlist.encode_ascii_prefixes = True diff --git a/src/mailman/testing/testing.cfg b/src/mailman/testing/testing.cfg index fc76aa361..eb9de5513 100644 --- a/src/mailman/testing/testing.cfg +++ b/src/mailman/testing/testing.cfg @@ -18,9 +18,9 @@ # A testing configuration. # For testing against PostgreSQL. -# [database] -# class: mailman.database.postgresql.PostgreSQLDatabase -# url: postgres://barry:barry@localhost/mailman +[database] +class: mailman.database.postgresql.PostgreSQLDatabase +url: postgresql://maxking:maxking@localhost/mailman_test [mailman] site_owner: noreply@example.com diff --git a/src/mailman/utilities/importer.py b/src/mailman/utilities/importer.py index 26b7261e3..99531194f 100644 --- a/src/mailman/utilities/importer.py +++ b/src/mailman/utilities/importer.py @@ -128,6 +128,12 @@ def nonmember_action_mapping(value): }[value] +def int_to_bool(value): + if value: + return True + else: + return False + def check_language_code(code): if code is None: @@ -172,6 +178,9 @@ TYPES = dict( personalize=Personalization, preferred_language=check_language_code, reply_goes_to_list=ReplyToMunging, + allow_list_posts=int_to_bool, + include_rfc2369_headers=int_to_bool, + nntp_prefix_subject_too=int_to_bool, ) |
