~sircmpwn/core.sr.ht

core.sr.ht/srht/flagtype.py -rw-r--r-- 447 bytes
b695e020Drew DeVault Add "internal_anon" path for internal auth tokens 3 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import sqlalchemy.types as types

class FlagType(types.TypeDecorator):
    """
    Encodes/decodes IntFlags on the fly
    """

    impl = types.Integer()
    cache_ok = True

    def __init__(self, enum):
        self.enum = enum

    def process_bind_param(self, value, dialect):
        return int(value) if value != None else None

    def process_result_value(self, value, dialect):
        return self.enum(value) if value != None else None