Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return sf
if isinstance(value, list):
# transform a list to List/Slots
sf = SlotList(name=name)
for i, v in enumerate(value):
sl = slot(parent=sf, name=str(i), value=v)
sl.parent = sf
return sf
raise ValueError("Cannot handle type of '{}'".format(value))
class SlotNumeric(Slot):
__mapper_args__ = {
'polymorphic_identity': KVP_Type.KVP_TYPE_NUMERIC
}
_python_type = (tuple, decimal.Decimal)
_numeric_val_num = Column('numeric_val_num', BIGINT(), nullable=True, default=0)
_numeric_val_denom = Column('numeric_val_denom', BIGINT(), nullable=True, default=1)
value = hybrid_property_gncnumeric(_numeric_val_num, _numeric_val_denom)
SlotDate = define_simpleslot(postfix="Date",
pytype=(datetime.date,),
KVPtype=KVP_Type.KVP_TYPE_GDATE,
field="gdate_val",
col_type=_Date(),
col_default=None,
)
def value(self):
# convert to dict
return {sl.name: sl.value for sl in self.slots}
@value.setter
def value(self, value):
self.slots = [slot(parent=self, name=k, value=v) for k, v in value.items()]
def __init__(self, **kwargs):
self.guid_val = uuid.uuid4().hex
super(SlotFrame, self).__init__(**kwargs)
class SlotList(SlotFrame):
__mapper_args__ = {
'polymorphic_identity': KVP_Type.KVP_TYPE_GLIST
}
_python_type = (list,)
@property
def value(self):
# convert to dict
return [sl.value for sl in self.slots]
@value.setter
def value(self, value):
self.slots = [slot(parent=self, name=str(i), value=v) for i, v in enumerate(value)]
def __init__(self, **kwargs):
self.guid_val = uuid.uuid4().hex
super(SlotFrame, self).__init__(**kwargs)
field="double_val",
col_type=REAL(),
col_default=0,
)
SlotTime = define_simpleslot(postfix="Time",
pytype=(datetime.time,),
KVPtype=KVP_Type.KVP_TYPE_TIMESPEC,
field="timespec_val",
col_type=_DateTime(),
col_default=None,
)
class SlotFrame(DictWrapper, Slot):
__mapper_args__ = {
'polymorphic_identity': KVP_Type.KVP_TYPE_FRAME
}
_python_type = (dict,)
guid_val = Column('guid_val', VARCHAR(length=32))
slots = relation('Slot',
primaryjoin=foreign(Slot.obj_guid) == guid_val,
cascade='all, delete-orphan',
collection_class=CallableList,
single_parent=True,
backref=backref("parent", remote_side=guid_val),
)
@property
def value(self):
pytype=(str,),
KVPtype=KVP_Type.KVP_TYPE_STRING,
field="string_val",
col_type=VARCHAR(length=4096),
col_default=None,
)
SlotDouble = define_simpleslot(postfix="Double",
pytype=(float,),
KVPtype=KVP_Type.KVP_TYPE_DOUBLE,
field="double_val",
col_type=REAL(),
col_default=0,
)
SlotTime = define_simpleslot(postfix="Time",
pytype=(datetime.time,),
KVPtype=KVP_Type.KVP_TYPE_TIMESPEC,
field="timespec_val",
col_type=_DateTime(),
col_default=None,
)
class SlotFrame(DictWrapper, Slot):
__mapper_args__ = {
'polymorphic_identity': KVP_Type.KVP_TYPE_FRAME
}
_python_type = (dict,)
guid_val = Column('guid_val', VARCHAR(length=32))
slots = relation('Slot',
primaryjoin=foreign(Slot.obj_guid) == guid_val,
pytype=(int,),
KVPtype=KVP_Type.KVP_TYPE_GINT64,
field="int64_val",
col_type=BIGINT(),
col_default=0,
)
SlotString = define_simpleslot(postfix="String",
pytype=(str,),
KVPtype=KVP_Type.KVP_TYPE_STRING,
field="string_val",
col_type=VARCHAR(length=4096),
col_default=None,
)
SlotDouble = define_simpleslot(postfix="Double",
pytype=(float,),
KVPtype=KVP_Type.KVP_TYPE_DOUBLE,
field="double_val",
col_type=REAL(),
col_default=0,
)
SlotTime = define_simpleslot(postfix="Time",
pytype=(datetime.time,),
KVPtype=KVP_Type.KVP_TYPE_TIMESPEC,
field="timespec_val",
col_type=_DateTime(),
col_default=None,
)
class SlotFrame(DictWrapper, Slot):
__mapper_args__ = {
'polymorphic_identity': KVP_Type.KVP_TYPE_FRAME
def process_result_value(self, value, dialect):
if value is not None:
return KVP_Type(value)
pytype_KVPtype = {
int: KVP_Type.KVP_TYPE_GINT64,
float: KVP_Type.KVP_TYPE_DOUBLE,
decimal.Decimal: KVP_Type.KVP_TYPE_NUMERIC,
dict: KVP_Type.KVP_TYPE_FRAME,
list: KVP_Type.KVP_TYPE_GLIST,
# to fill
}
KVPtype_fields = {
KVP_Type.KVP_TYPE_GINT64: 'int64_val',
KVP_Type.KVP_TYPE_DOUBLE: 'double_val',
KVP_Type.KVP_TYPE_STRING: 'string_val',
KVP_Type.KVP_TYPE_GUID: 'guid_val',
KVP_Type.KVP_TYPE_TIMESPEC: 'timespec_val',
KVP_Type.KVP_TYPE_GDATE: 'gdate_val',
KVP_Type.KVP_TYPE_NUMERIC: ('numeric_val_num', 'numeric_val_denom'),
KVP_Type.KVP_TYPE_FRAME: 'guid',
KVP_Type.KVP_TYPE_GLIST: 'guid',
}
class SlotType(types.TypeDecorator):
"""Used to customise the DateTime type for sqlite (ie without the separators as in gnucash
"""
impl = INTEGER
def process_bind_param(self, value, dialect):
if value is not None:
return value.value
class KVP_Type(Enum):
KVP_TYPE_INVALID = -1
KVP_TYPE_GINT64 = 1
KVP_TYPE_DOUBLE = 2
KVP_TYPE_NUMERIC = 3
KVP_TYPE_STRING = 4
KVP_TYPE_GUID = 5
KVP_TYPE_TIMESPEC = 6
KVP_TYPE_BINARY = 7
KVP_TYPE_GLIST = 8
KVP_TYPE_FRAME = 9
KVP_TYPE_GDATE = 10
pytype_KVPtype = {
int: KVP_Type.KVP_TYPE_GINT64,
float: KVP_Type.KVP_TYPE_DOUBLE,
decimal.Decimal: KVP_Type.KVP_TYPE_NUMERIC,
dict: KVP_Type.KVP_TYPE_FRAME,
list: KVP_Type.KVP_TYPE_GLIST,
# to fill
}
KVPtype_fields = {
KVP_Type.KVP_TYPE_GINT64: 'int64_val',
KVP_Type.KVP_TYPE_DOUBLE: 'double_val',
KVP_Type.KVP_TYPE_STRING: 'string_val',
KVP_Type.KVP_TYPE_GUID: 'guid_val',
KVP_Type.KVP_TYPE_TIMESPEC: 'timespec_val',
KVP_Type.KVP_TYPE_GDATE: 'gdate_val',
KVP_Type.KVP_TYPE_NUMERIC: ('numeric_val_num', 'numeric_val_denom'),
KVP_Type.KVP_TYPE_FRAME: 'guid',
class SlotNumeric(Slot):
__mapper_args__ = {
'polymorphic_identity': KVP_Type.KVP_TYPE_NUMERIC
}
_python_type = (tuple, decimal.Decimal)
_numeric_val_num = Column('numeric_val_num', BIGINT(), nullable=True, default=0)
_numeric_val_denom = Column('numeric_val_denom', BIGINT(), nullable=True, default=1)
value = hybrid_property_gncnumeric(_numeric_val_num, _numeric_val_denom)
SlotDate = define_simpleslot(postfix="Date",
pytype=(datetime.date,),
KVPtype=KVP_Type.KVP_TYPE_GDATE,
field="gdate_val",
col_type=_Date(),
col_default=None,
)
"_python_type": pytype,
}
)
return cls
SlotInt = define_simpleslot(postfix="Int",
pytype=(int,),
KVPtype=KVP_Type.KVP_TYPE_GINT64,
field="int64_val",
col_type=BIGINT(),
col_default=0,
)
SlotString = define_simpleslot(postfix="String",
pytype=(str,),
KVPtype=KVP_Type.KVP_TYPE_STRING,
field="string_val",
col_type=VARCHAR(length=4096),
col_default=None,
)
SlotDouble = define_simpleslot(postfix="Double",
pytype=(float,),
KVPtype=KVP_Type.KVP_TYPE_DOUBLE,
field="double_val",
col_type=REAL(),
col_default=0,
)
SlotTime = define_simpleslot(postfix="Time",
pytype=(datetime.time,),
KVPtype=KVP_Type.KVP_TYPE_TIMESPEC,
field="timespec_val",
col_type=_DateTime(),