def coerce(cls, key, value): if not isinstance(value, MutationList): if isinstance(value, list): return cls(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): if not isinstance(value, MutationDict): if isinstance(value, dict): return cls(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): if not isinstance(value, MutableList): if isinstance(value, list): return MutableList(value) value = Mutable.coerce(key, value) return value
def coerce(cls, key, value): if isinstance(value, MutableDict): return value elif isinstance(value, dict): return MutableDict(value) else: return Mutable.coerce(key, value)
def coerce(cls, key, value): if not isinstance(value, MutationList): if isinstance(value, list): return MutationList(value) return Mutable.coerce(key, value) # pragma: no cover else: return value
def coerce(cls, key, value): if not isinstance(value, cls): if isinstance(value, int): return SessionRecord(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): if not isinstance(value, cls): if isinstance(value, dict): return cls(value) return Mutable.coerce(key, value) # Raises ValueError for us else: return value
def coerce(cls, key, value): if not isinstance(value, MutableDict): if isinstance(value, dict): return MutableDict(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): """Convert plain list to MutationList""" if not isinstance(value, MutableList): if isinstance(value, list): return MutableList(value) return Mutable.coerce(key, value) return value
def coerce(cls, key, value): if not isinstance(value, BitFlag): if isinstance(value, int): return BitFlag(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): "Convert plain dictionaries to MutableDict." if not isinstance(value, MutableDict): if isinstance(value, dict): return MutableDict(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): if isinstance(value, JsonEncodedList): return value else: if isinstance(value, list): return JsonEncodedList(value) else: return Mutable.coerce(key, value)
def coerce(cls, key, value): """Convert plain dictionary to JSONMutableDict.""" if not isinstance(value, JSONMutableDict): if isinstance(value, dict): return JSONMutableDict(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): """Convert plain dictionary to MutationDict.""" if not isinstance(value, MutationDict): if isinstance(value, dict): return MutationDict(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): """Convert plain dictionaries to Features.""" if not isinstance(value, cls): if isinstance(value, list): return cls(value) return Mutable.coerce(key, value) # this will raise an error else: return value
def coerce(cls, index, value): """Convert plain list to instance of this class.""" if not isinstance(value, cls): if isinstance(value, list): return cls(value) return Mutable.coerce(index, value) else: return value
def coerce(cls, key, value): if not isinstance(value, MutationDict): if isinstance(value, dict): return MutationDict(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): "Convert plain dictionaries to MutationDict." if not isinstance(value, MutationDict): if isinstance(value, dict): return MutationDict(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): "Convert plain list to MutationList." if not isinstance(value, MutationList): if isinstance(value, list): return MutationList(value) # this call will raise ValueError return Mutable.coerce(key, value) # pragma: no cover else: return value
def coerce(cls, key, value): "Convert plain dictionaries to MutableDict." if not isinstance(value, MutableList): if isinstance(value, list): return MutableList(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): if not isinstance(value, _JSONEncodeDictMutabilize): if isinstance(value, dict): return _JSONEncodeDictMutabilize(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): if not isinstance(value, ConfigurationContainer): if isinstance(value, dict): return ConfigurationContainer(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): """Automatically coerce any ``dict`` to a :class:`~pywebtools.sqlalchemy.MutableDict`. Used by SQLAlchemy. """ if not isinstance(value, MutableDict): if isinstance(value, dict): return MutableDict(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): if not isinstance(value, MutationList): if isinstance(value, list): return cls(value) try: return Mutable.coerce(key, value) except ValueError as e: import pdb ; pdb.set_trace() else: return value
def coerce(cls, key, value): if not isinstance(value, MutableList): if isinstance(value, list): return MutableList(value) return Mutable.coerce(key, value) else: return value # https://docs.sqlalchemy.org/en/latest/orm/extensions/mutable.html#module-sqlalchemy.ext.mutable
def coerce(cls, key, value): """Convert list to MutationList.""" if not isinstance(value, MutationList): if isinstance(value, list): return MutationList(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key: str, value: Dict) -> "MutationDict": """Convert plain dictionaries to MutationDict.""" if not isinstance(value, MutationDict): if isinstance(value, dict): return MutationDict(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): # @ReservedAssignment """Convert plain dictionaries to MutationDict.""" if not isinstance(value, MutationDict): if isinstance(value, dict): return MutationDict(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): if not isinstance(value, MutationList): if isinstance(value, list): return cls(value) try: return Mutable.coerce(key, value) except ValueError as e: import pdb pdb.set_trace() else: return value
def coerce(cls, key, value): """Convert plain numpy arrays to MutableNdarray.""" if not isinstance(value, MutableNdarray): if isinstance(value, np.ndarray): mutable_array = value.view(MutableNdarray) return mutable_array # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): """Convert plain dictionaries to MutableDict.""" if value is None: value = {} if not isinstance(value, MutableDict): if isinstance(value, dict): return MutableDict(value) # This call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): """Convert plain dictionaries to MutableDict. :param key: string name of the ORM-mapped attribute being set. :param value: the incoming value. :return: the method should return the coerced value """ if not isinstance(value, cls): if isinstance(value, dict): return cls(value) # this call will raise ValueError return MutableBase.coerce(key, value) return value
def coerce(cls, key, value): """ Convert plain sets to MutableSet. """ if not isinstance(value, MutableSet): if isinstance(value, set): return MutableSet(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): "Convert plain dictionaries to StateMutationDict." if not isinstance(value, StateMutationDict): if isinstance(value, dict): return StateMutationDict(value) elif isinstance(value, basestring): return StateMutationDict({ 'current': value, '1': simplejson.dumps([value, ''])}) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def _coerce(cls, key, value, coerce_type): """Convert plain dictionaries to MutableDict. :param key: string name of the ORM-mapped attribute being set. :param value: the incoming value. :param coerce_type: type, that should be coerced :return: the method should return the coerced value :raises ValueError: if the coercion cannot be completed. """ if not isinstance(value, cls): if isinstance(value, coerce_type): return cls(value) # this call will raise ValueError return MutableBase.coerce(key, value) return value
def coerce(cls, key, value): """ Re-define the coerce. Ensures that a class deriving from Mutable is always returned :param key: :param value: :return: """ if not isinstance(value, MutableList): if isinstance(value, list): return MutableList(value) return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): """ Convert plain dictionaries to MutableDict """ # If it isn't a MutableDict already we conver it if not isinstance(value, MutableDict): # If it is a dictionary we can convert it if isinstance(value, dict): return MutableDict(value) # Try to coerce but it will probably return a ValueError return Mutable.coerce(key, value) else: # Since we already have a MutableDict we can just return it return value
def coerce(cls, key, value): """Convert plain dictionaries to MutableDict.""" if not isinstance(value, MutableDict): if isinstance(value, dict): return MutableDict(value) elif isinstance(value, basestring): # Assume JSON string if value: return MutableDict(simplejson.loads(value, use_decimal=True)) else: return MutableDict() # Empty value is an empty dict # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): """Convert plain lists to MutableList. :param key: string name of the ORM-mapped attribute being set. :param value: the incoming value. :return: the method should return the coerced value :raises ValueError: if the coercion cannot be completed. """ if not isinstance(value, MutableList): if isinstance(value, list): return MutableList(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
def coerce(cls, key, value): "Convert plain dictionaries to MutableDict." if not isinstance(value, MutableDict): if isinstance(value, basestring): if value: value = value.strip() value = loads(value) else: value = {} if isinstance(value, dict): return MutableDict(value) # this call will raise ValueError return Mutable.coerce(key, value) else: return value
id = Column(Integer, primary_key=True) c_id = Column(ForeignKey('c.id')) b_id = Column(ForeignKey('b.id')) d_json = Column(JSON) # 1. set up the join() as a variable, so we can refer # to it in the mapping multiple times. j = join(B, D, D.b_id == B.id).join(C, C.id == D.c_id) # 2. Create a new mapper() to B, with non_primary=True. # Columns in the join with the same name must be # disambiguated within the mapping, using named properties. B_viacd = mapper(B, j, non_primary=True, properties={ "b_id": [j.c.b_id, j.c.d_b_id], "d_id": j.c.d_id }) A.b = relationship(B_viacd, primaryjoin=A.b_id == B_viacd.c.b_id) # Create DB engine = create_engine('postgresql://localhost/test_db') Base.metadata.create_all(engine) # If we associate `Mutable` with `JSON` then `A` can not be instantiated succesfully Mutable.associate_with(JSON) item1 = A()
def coerce(cls, key, value): if not isinstance(value, MutableList): if isinstance(value, (set, list, tuple)): return MutableList(value) return Mutable.coerce(key, value) return value
def changed(self): if self.parent: MutationObj.changed(self.parent) else: Mutable.changed(self)
def coerce(class_, key, value): if not isinstance(value, mutators_dict): if isinstance(value, dict): return mutators_dict(value) return Mutable.coerce(key, value) return value
def coerce(class_, key, value): if not isinstance(value, mutators_list): if isinstance(value, list): return mutators_list(value) return Mutable.coerce(key, value) return value
def __init__(self, *args, **kwargs): Mutable.__init__(self) Game.__init__(self, *args, **kwargs)
def coerce(cls, key, value): "Convert plain dictionaries to MutableDict." if isinstance(value, MutableDict): return value if isinstance(value, dict): return MutableDict(value) return Mutable.coerce(key, value)