from peewee import ModelDescriptor # Hybrid methods/attributes, based on similar functionality in SQLAlchemy: # http://docs.sqlalchemy.org/en/improve_toc/orm/extensions/hybrid.html class hybrid_method(ModelDescriptor): def __init__(self, func, expr=None): self.func = func self.expr = expr or func def __get__(self, instance, instance_type): if instance is None: return self.expr.__get__(instance_type, instance_type.__class__) return self.func.__get__(instance, instance_type) def expression(self, expr): self.expr = expr return self class hybrid_property(ModelDescriptor): def __init__(self, fget, fset=None, fdel=None, expr=None): self.fget = fget self.fset = fset self.fdel = fdel self.expr = expr or fget def __get__(self, instance, instance_type): if instance is None: return self.expr(instance_type) return self.fget(instance) def __set__(self, instance, value): if self.fset is None: raise AttributeError('Cannot set attribute.') self.fset(instance, value) def __delete__(self, instance): if self.fdel is None: raise AttributeError('Cannot delete attribute.') self.fdel(instance) def setter(self, fset): self.fset = fset return self def deleter(self, fdel): self.fdel = fdel return self def expression(self, expr): self.expr = expr return self
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
__init__.py | File | 0 B | 0644 |
|
apsw_ext.py | File | 4.82 KB | 0644 |
|
cockroachdb.py | File | 9 KB | 0644 |
|
dataset.py | File | 14.09 KB | 0644 |
|
db_url.py | File | 4.15 KB | 0644 |
|
fields.py | File | 1.66 KB | 0644 |
|
flask_utils.py | File | 8 KB | 0644 |
|
hybrid.py | File | 1.49 KB | 0644 |
|
kv.py | File | 5.48 KB | 0644 |
|
migrate.py | File | 30.11 KB | 0644 |
|
mysql_ext.py | File | 3.17 KB | 0644 |
|
pool.py | File | 11.21 KB | 0644 |
|
postgres_ext.py | File | 14.41 KB | 0644 |
|
psycopg3_ext.py | File | 1.15 KB | 0644 |
|
reflection.py | File | 30.2 KB | 0644 |
|
shortcuts.py | File | 11.25 KB | 0644 |
|
signals.py | File | 2.46 KB | 0644 |
|
sqlcipher_ext.py | File | 3.55 KB | 0644 |
|
sqlite_changelog.py | File | 4.68 KB | 0644 |
|
sqlite_ext.py | File | 45.65 KB | 0644 |
|
sqlite_udf.py | File | 13.34 KB | 0644 |
|
sqliteq.py | File | 9.75 KB | 0644 |
|
test_utils.py | File | 1.81 KB | 0644 |
|