~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
catacomb/__init__.py: Implement equality and hashing for `KeyData' objects.
[catacomb-python]
/
catacomb
/
pwsafe.py
diff --git
a/catacomb/pwsafe.py
b/catacomb/pwsafe.py
index
23fcbb2
..
97ad354
100644
(file)
--- a/
catacomb/pwsafe.py
+++ b/
catacomb/pwsafe.py
@@
-28,6
+28,7
@@
from __future__ import with_statement
from __future__ import with_statement
+import binascii as _B
import errno as _E
import os as _OS
from cStringIO import StringIO as _StringIO
import errno as _E
import os as _OS
from cStringIO import StringIO as _StringIO
@@
-48,6
+49,10
@@
_NUL = _bin('\0')
_CIPHER = _bin('cipher:')
_MAC = _bin('mac:')
_CIPHER = _bin('cipher:')
_MAC = _bin('mac:')
+def _with_metaclass(meta, *supers):
+ return meta("#<anonymous base %s>" % meta.__name__,
+ supers or (object,), dict())
+
def _excval(): return SYS.exc_info()[1]
_M600 = int("600", 8)
def _excval(): return SYS.exc_info()[1]
_M600 = int("600", 8)
@@
-99,10
+104,10
@@
def _dec_metaname(name):
def _b64(s):
"""Encode S as base64, without newlines, and trimming `=' padding."""
def _b64(s):
"""Encode S as base64, without newlines, and trimming `=' padding."""
- return
s.encode('base64'
).replace('\n', '').rstrip('=')
+ return
_text(_B.b2a_base64(s)
).replace('\n', '').rstrip('=')
def _unb64(s):
"""Decode S as base64 with trimmed `=' padding."""
def _unb64(s):
"""Decode S as base64 with trimmed `=' padding."""
- return
(s + '='*((4 - len(s))%4)).decode('base64'
)
+ return
_B.a2b_base64(s + '='*((4 - len(s))%4)
)
def _enc_metaval(val):
"""Encode VAL as a metadata item value, returning the result."""
def _enc_metaval(val):
"""Encode VAL as a metadata item value, returning the result."""
@@
-231,9
+236,11
@@
class StorageBackendClass (type):
Register a new concrete StorageBackend subclass.
"""
super(StorageBackendClass, me).__init__(name, supers, dict)
Register a new concrete StorageBackend subclass.
"""
super(StorageBackendClass, me).__init__(name, supers, dict)
- if me.NAME is not None: StorageBackend.register_concrete_subclass(me)
+ try: name = me.NAME
+ except AttributeError: pass
+ else: StorageBackend.register_concrete_subclass(me)
-class StorageBackend (
object
):
+class StorageBackend (
_with_metaclass(StorageBackendClass)
):
"""
I provide basic protocol for password storage backends.
"""
I provide basic protocol for password storage backends.
@@
-301,8
+308,6
@@
class StorageBackend (object):
priority order when opening an existing database.
"""
priority order when opening an existing database.
"""
- __metaclass__ = StorageBackendClass
- NAME = None
PRIO = 10
## The registry of subclasses.
PRIO = 10
## The registry of subclasses.