Skip to content

Commit

Permalink
More text comparison fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey committed Oct 10, 2020
1 parent e8c2058 commit 16bae21
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions axiom/attributes.py
Expand Up @@ -984,13 +984,13 @@ def outfilter(self, dbval, oself):


class textlist(text):
delimiter = '\u001f'
delimiter = u'\u001f'

# Once upon a time, textlist encoded the list in such a way that caused []
# to be indistinguishable from [u'']. This value is now used as a
# placeholder at the head of the list, to avoid this problem in a way that
# is almost completely backwards-compatible with older databases.
guard = '\u0002'
guard = u'\u0002'

def outfilter(self, dbval, oself):
unicodeString = super(textlist, self).outfilter(dbval, oself)
Expand Down
4 changes: 2 additions & 2 deletions axiom/batch.py
Expand Up @@ -110,7 +110,7 @@ class BatchProcessingError(item.Item):
The item which actually failed to be processed.
""")

error = attributes.bytes(doc="""
error = attributes.text(doc="""
The error message which was associated with this failure.
""")

Expand Down Expand Up @@ -504,7 +504,7 @@ def __init__(self, *a, **kw):
""", default=None),

# MAGIC NUMBERS AREN'T THEY WONDERFUL?
'busyInterval': attributes.integer(doc="", default=MILLI / 10),
'busyInterval': attributes.integer(doc="", default=MILLI // 10),
}
_processors[forType] = processor = item.MetaItem(
attrs['__name__'],
Expand Down
4 changes: 2 additions & 2 deletions axiom/dependency.py
Expand Up @@ -14,8 +14,8 @@
from axiom.item import Item
from axiom.attributes import reference, boolean, AND
from axiom.errors import ItemNotFound, DependencyError, UnsatisfiedRequirement
from six.moves import map
from six.moves import zip
import six
from six.moves import map, zip

#There is probably a cleaner way to do this.
_globalDependencyMap = {}
Expand Down
9 changes: 8 additions & 1 deletion axiom/item.py
Expand Up @@ -25,6 +25,7 @@
reference, text, integer, AND, _cascadingDeletes, _disallows)
import six
from six.moves import zip
from functools import total_ordering

_typeNameToMostRecentClass = WeakValueDictionary()

Expand All @@ -48,6 +49,7 @@ class CantInstantiateItem(RuntimeError):
"""You can't instantiate Item directly. Make a subclass.
"""

@total_ordering
class MetaItem(slotmachine.SchemaMetaMachine):
"""Simple metaclass for Item that adds Item (and its subclasses) to
_typeNameToMostRecentClass mapping.
Expand Down Expand Up @@ -99,11 +101,16 @@ def __cmp__(self, other):
in SQL generation, which is beneficial for debugging and performance
purposes.
"""
if isinstance(other, MetaItem):
# cmp is only available on Python 2
if six.PY2 and isinstance(other, MetaItem):
return cmp((self.typeName, self.schemaVersion),
(other.typeName, other.schemaVersion))
return NotImplemented

def __lt__(self, other):
# This plus total_ordering gets us comparisons in Python 3
return (self.typeName, self.schemaVersion) < (other.typeName, other.schemaVersion)


def noop():
pass
Expand Down
2 changes: 1 addition & 1 deletion axiom/test/test_axiomatic.py
Expand Up @@ -510,4 +510,4 @@ def test_journalMode(self):
options = axiomatic.Options()
options['dbdir'] = self.mktemp()
options['journal-mode'] = 'WAL'
self.assertEqual(options.getStore().journalMode, 'WAL')
self.assertEqual(options.getStore().journalMode, u'WAL')
10 changes: 5 additions & 5 deletions axiom/userbase.py
Expand Up @@ -591,13 +591,13 @@ def addAccount(self, username, domain, password, avatars=None,

# unicode(None) == u'None', kids.
if username is not None:
username = six.ensure_str(username)
username = six.ensure_text(username)
if domain is not None:
domain = six.ensure_str(domain)
domain = six.ensure_text(domain)
if password is None:
passwordHash = None
else:
password = six.ensure_str(password)
password = six.ensure_text(password)
passwordHash = six.ensure_str(_globalCC.hash(password))

if self.accountByAddress(username, domain) is not None:
Expand Down Expand Up @@ -664,8 +664,8 @@ def verified(result):
self.failedLogins += 1
raise MissingDomainPart(credentials.username)

username = six.ensure_str(username)
domain = six.ensure_str(domain)
username = six.ensure_text(username)
domain = six.ensure_text(domain)

acct = self.accountByAddress(username, domain)
if acct is not None:
Expand Down

0 comments on commit 16bae21

Please sign in to comment.