Changeset View
Changeset View
Standalone View
Standalone View
pykolab/auth/ldap/auth_cache.py
Show All 19 Lines | |||||
import os | import os | ||||
import sqlalchemy | import sqlalchemy | ||||
from sqlalchemy import Column | from sqlalchemy import Column | ||||
from sqlalchemy import DateTime | from sqlalchemy import DateTime | ||||
from sqlalchemy import Integer | from sqlalchemy import Integer | ||||
from sqlalchemy import MetaData | from sqlalchemy import MetaData | ||||
from sqlalchemy import String | from sqlalchemy import Unicode | ||||
from sqlalchemy import Text | from sqlalchemy import UnicodeText | ||||
from sqlalchemy import create_engine | from sqlalchemy import create_engine | ||||
from sqlalchemy.ext.declarative import declarative_base | from sqlalchemy.ext.declarative import declarative_base | ||||
from sqlalchemy.orm import sessionmaker | from sqlalchemy.orm import sessionmaker | ||||
import pykolab | import pykolab | ||||
Show All 19 Lines | |||||
DeclarativeBase = declarative_base() | DeclarativeBase = declarative_base() | ||||
# pylint: disable=too-few-public-methods | # pylint: disable=too-few-public-methods | ||||
class Entry(DeclarativeBase): | class Entry(DeclarativeBase): | ||||
__tablename__ = 'entries' | __tablename__ = 'entries' | ||||
id = Column(Integer, primary_key=True) | id = Column(Integer, primary_key=True) | ||||
domain = Column(String(256), index=True, nullable=True) | domain = Column(Unicode(256), index=True, nullable=True) | ||||
key = Column(Text, index=True, nullable=False) | key = Column(UnicodeText, index=True, nullable=False) | ||||
value = Column(Text, nullable=False) | value = Column(UnicodeText, nullable=False) | ||||
last_change = Column(DateTime, nullable=False, default=datetime.datetime.now()) | last_change = Column(DateTime, nullable=False, default=datetime.datetime.now()) | ||||
def __init__(self, key, value): | def __init__(self, key, value): | ||||
self.key = key | self.key = key | ||||
if not isinstance(value, unicode): | if not isinstance(value, unicode): | ||||
self.value = unicode(value, 'utf-8') | self.value = unicode(value, 'utf-8') | ||||
else: | else: | ||||
self.value = value | self.value = value | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | for __entry in _entries: | ||||
__entries.append(__entry) | __entries.append(__entry) | ||||
if len(__entries) != 1: | if len(__entries) != 1: | ||||
return None | return None | ||||
log.debug("Entry found: %r" % (__entries[0].__dict__)) | log.debug("Entry found: %r" % (__entries[0].__dict__)) | ||||
log.debug("Returning: %r" % (__entries[0].value)) | log.debug("Returning: %r" % (__entries[0].value)) | ||||
return __entries[0].value.encode('utf-8', 'latin1') | return __entries[0].value | ||||
sicherha: I know it's already present in the original code, but the second argument to `encode()` looks… | |||||
def set_entry(key, value): | def set_entry(key, value): | ||||
# pylint: disable=global-statement | # pylint: disable=global-statement | ||||
global db | global db | ||||
db = init_db() | db = init_db() | ||||
if db is None: | if db is None: | ||||
return | return | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |
I know it's already present in the original code, but the second argument to encode() looks strange to me. Isn't that argument supposed to be a string describing the error-handling scheme? The value 'latin1' wouldn't make any sense in that case.