예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
    def coerce(cls, key, value):
        if not isinstance(value, MutableList):
            if isinstance(value, list):
                return MutableList(value)
            value = Mutable.coerce(key, value)

        return value
예제 #4
0
파일: __init__.py 프로젝트: benzid-wael/frf
    def coerce(cls, key, value):
        if not isinstance(value, MutableList):
            if isinstance(value, list):
                return MutableList(value)
            value = Mutable.coerce(key, value)

        return value
예제 #5
0
 def coerce(cls, key, value):
     if isinstance(value, MutableDict):
         return value
     elif isinstance(value, dict):
         return MutableDict(value)
     else:
         return Mutable.coerce(key, value)
예제 #6
0
파일: sqla.py 프로젝트: runyaga/ptah
 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
예제 #7
0
파일: metadata.py 프로젝트: aitjcize/bb8
 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
예제 #8
0
 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
예제 #9
0
 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
예제 #10
0
파일: sqla.py 프로젝트: WouterVH/ptah
 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
예제 #11
0
파일: types.py 프로젝트: devhub/baph
 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
예제 #12
0
파일: bitflags.py 프로젝트: azflin/trump
 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
예제 #13
0
파일: base.py 프로젝트: feltus/BDSS
 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
예제 #14
0
 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)
예제 #15
0
 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
예제 #16
0
 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
예제 #17
0
파일: util.py 프로젝트: colwilson/flasker
 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
예제 #18
0
 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
예제 #19
0
 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
예제 #20
0
 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
예제 #21
0
    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
예제 #22
0
파일: models.py 프로젝트: killthrush/pybald
 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
예제 #23
0
파일: models.py 프로젝트: yoshrote/columns2
 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
예제 #24
0
 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
예제 #25
0
    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
예제 #26
0
    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
예제 #27
0
 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
예제 #28
0
파일: json.py 프로젝트: frispete/websauna
 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
예제 #29
0
    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
예제 #30
0
  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
예제 #31
0
    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
예제 #32
0
    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
예제 #33
0
파일: json.py 프로젝트: AriKatz/websauna
 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
예제 #34
0
    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
예제 #35
0
    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
예제 #36
0
    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
예제 #37
0
    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
예제 #38
0
    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
예제 #39
0
    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
예제 #40
0
    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
예제 #41
0
    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
예제 #42
0
    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
예제 #43
0
    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
예제 #44
0
    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
예제 #45
0
    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
예제 #46
0
    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
예제 #47
0
    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()
예제 #49
0
 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
예제 #50
0
 def changed(self):
     if self.parent:
         MutationObj.changed(self.parent)
     else:
         Mutable.changed(self)
예제 #51
0
 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
예제 #52
0
 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
예제 #53
0
 def __init__(self, *args, **kwargs):
     Mutable.__init__(self)
     Game.__init__(self, *args, **kwargs)    
예제 #54
0
 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)