summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2015-08-13 16:06:25 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2015-08-13 16:06:25 +0200
commita9aa9c2650e7a1bff48609706bc545afc6c7408e (patch)
treeb64bc476201e07906549242de6e5daa2402b99da /pykolab
parentf72c73ecd2b542d0b6e9fc70681410c957da930d (diff)
downloadpykolab-a9aa9c2650e7a1bff48609706bc545afc6c7408e.tar.gz
Modify the auth_cache to use proper encodings (#5174)
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/auth/ldap/auth_cache.py37
1 files changed, 16 insertions, 21 deletions
diff --git a/pykolab/auth/ldap/auth_cache.py b/pykolab/auth/ldap/auth_cache.py
index c410fe6..cd46a4c 100644
--- a/pykolab/auth/ldap/auth_cache.py
+++ b/pykolab/auth/ldap/auth_cache.py
@@ -30,6 +30,7 @@ from sqlalchemy import Text
from sqlalchemy import desc
from sqlalchemy import create_engine
+from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import mapper
try:
@@ -59,29 +60,23 @@ db = None
## Classes
##
-class Entry(object):
- def __init__(self, key, value):
- self.key = key
- self.value = value
+DeclarativeBase = declarative_base()
-##
-## Tables
-##
+class Entry(DeclarativeBase):
+ __tablename__ = 'entries'
-entry_table = Table(
- 'entries', metadata,
- Column('id', Integer, primary_key=True),
- Column('domain', String(256), index=True, nullable=True),
- Column('key', Text, index=True, nullable=False),
- Column('value', Text, nullable=False),
- Column('last_change', DateTime, nullable=False, default=datetime.datetime.now())
- )
+ id = Column(Integer, primary_key=True)
+ domain = Column(String(256), index=True, nullable=True)
+ key = Column(Text, index=True, nullable=False)
+ value = Column(Text, nullable=False)
+ last_change = Column(DateTime, nullable=False, default=datetime.datetime.now())
-##
-## Table <-> Class Mappers
-##
-
-mapper(Entry, entry_table)
+ def __init__(self, key, value):
+ self.key = key
+ if not isinstance(value, unicode):
+ self.value = unicode(value, 'utf-8')
+ else:
+ self.value = value
##
## Functions
@@ -121,7 +116,7 @@ def get_entry(key):
log.debug("Entry found: %r" % (_entries[0].__dict__))
log.debug("Returning: %r" % (_entries[0].value))
- return _entries[0].value
+ return _entries[0].value.encode('utf-8', 'latin1')
def set_entry(key, value):
db = init_db()