コード例 #1
0
 def __init__(self, name, multiplicity=None, atype=None, order=None):
     self.py_id = util.to_valid_identifier_name(name)
     self.owner_spec = None # filled in when the attr is added to a spec
     self.name = name
     self.type = self._get_valid_type(atype)
     self.order = order
     self.multiplicity = self._get_valid_multiplicity(multiplicity)
コード例 #2
0
 def __init__(self, name, multiplicity=None, atype=None, order=None):
     self.py_id = util.to_valid_identifier_name(name)
     self.owner_spec = None  # filled in when the attr is added to a spec
     self.name = name
     self.type = self._get_valid_type(atype)
     self.order = order
     self.multiplicity = self._get_valid_multiplicity(multiplicity)
コード例 #3
0
 def set_value(self, name, value, order=None):
     """
     Sets the value for the attribute with the specified name.
     """
     py_identifier = util.to_valid_identifier_name(name)
     self.attr_identifiers[name] = py_identifier
     if order:
         self.attr_orders[name] = order
     else:
         self.attr_orders[name] = max(self.attr_orders.values())+1 if len(self.attr_orders.values())>0 else 1
     setattr(self, py_identifier, value)
     self._is_modified = True
コード例 #4
0
 def set_value(self, name, value, order=None):
     """
     Sets the value for the attribute with the specified name.
     """
     py_identifier = util.to_valid_identifier_name(name)
     self.attr_identifiers[name] = py_identifier
     if order:
         self.attr_orders[name] = order
     else:
         self.attr_orders[name] = max(self.attr_orders.values()) + 1 if len(
             self.attr_orders.values()) > 0 else 1
     setattr(self, py_identifier, value)
     self._is_modified = True
コード例 #5
0
 def __init__(cls, *args, **kwargs):
     extra_kwargs = dict(kwargs)
     cls.original_name = None
     cls.name = args[0] if len(args) > 0 else extra_kwargs.pop('name', None)
     name = util.to_valid_identifier_name(cls.name)
     bases = args[1] if len(args) > 1 else extra_kwargs.pop('bases', None)
     dct = args[2] if len(args) > 2 else extra_kwargs.pop('dct', None)
     cls.version = extra_kwargs.get('version', None)
     cls._is_new = not kwargs.pop('persisted', False)
     cls._replace_attributes(extra_kwargs.get('attributes', []))
     cls._is_modified = False  # will be switched to True if either the name bases or attributes are changed
     cls._is_renamed = False  # will be switched to True if the name is changed
     #cls.py_id = util.to_valid_identifier_name(cls.id) # not needed as an extra attribute, it's already the class identifier!
     super(Entity, cls).__init__(name, bases, dct)
コード例 #6
0
 def __init__(cls, *args, **kwargs):
     extra_kwargs = dict(kwargs)
     cls.original_name = None
     cls.name = args[0] if len(args)>0 else extra_kwargs.pop('name', None)
     name = util.to_valid_identifier_name(cls.name)
     bases = args[1] if len(args)>1 else extra_kwargs.pop('bases', None)
     dct = args[2] if len(args)>2 else extra_kwargs.pop('dct', None)
     cls.version = extra_kwargs.get('version', None)
     cls._is_new = not kwargs.pop('persisted', False)
     cls._replace_attributes(extra_kwargs.get('attributes', []))
     cls._is_modified = False # will be switched to True if either the name bases or attributes are changed
     cls._is_renamed = False # will be switched to True if the name is changed
     #cls.py_id = util.to_valid_identifier_name(cls.id) # not needed as an extra attribute, it's already the class identifier!
     super(Entity, cls).__init__(name, bases, dct)
コード例 #7
0
 def __new__(mcs, *args, **kwargs):
     """
     It's not very usual for __new__ to receive args and kwargs,
     instead of the usual: mcs, name, bases, dct.
     We need it here because we want to pass extra params, to
     be picked up by __init__
     """
     assert 'name' in kwargs
     name = util.to_valid_identifier_name(
         args[0] if len(args) > 0 else kwargs.get('name', None))
     bases = args[1] if len(args) > 1 else kwargs.get('bases', tuple())
     dct = args[2] if len(args) > 2 else kwargs.get('dct', {})
     if len([b for b in bases if issubclass(b, Instance)]) == 0:
         bases = (Instance, )
     return super(Entity, mcs).__new__(mcs, name, bases, dct)
コード例 #8
0
 def __new__(mcs, *args, **kwargs):
     """
     It's not very usual for __new__ to receive args and kwargs,
     instead of the usual: mcs, name, bases, dct.
     We need it here because we want to pass extra params, to
     be picked up by __init__
     """
     assert 'name' in kwargs
     name = util.to_valid_identifier_name(
         args[0] if len(args)>0 else kwargs.get('name', None)
     )
     bases = args[1] if len(args)>1 else kwargs.get('bases', tuple())
     dct = args[2] if len(args)>2 else kwargs.get('dct', {})
     if len([b for b in bases if issubclass(b,Instance)]) == 0:
         bases = (Instance, )
     return super(Entity, mcs).__new__(mcs, name, bases, dct)
コード例 #9
0
    def add_values(self, values_list):
        """
        values_list: A list of tuples (attr_name, attr_value)
        """
        for name, value in values_list:
            py_identifier = util.to_valid_identifier_name(name)
            self.attr_identifiers[name] = py_identifier
            self.attr_orders[name] = max(self.attr_orders.values())+1 if len(self.attr_orders.values())>0 else 1

            if not hasattr(self, py_identifier):
                setattr(self, py_identifier, value)
            else:
                old_val = getattr(self, py_identifier)
                if type(old_val)==list:
                    old_val.append(value)
                    setattr(self, py_identifier, old_val)
                else:
                    setattr(self, py_identifier, [old_val, value])
コード例 #10
0
    def add_values(self, values_list):
        """
        values_list: A list of tuples (attr_name, attr_value)
        """
        for name, value in values_list:
            py_identifier = util.to_valid_identifier_name(name)
            self.attr_identifiers[name] = py_identifier
            self.attr_orders[name] = max(self.attr_orders.values()) + 1 if len(
                self.attr_orders.values()) > 0 else 1

            if not hasattr(self, py_identifier):
                setattr(self, py_identifier, value)
            else:
                old_val = getattr(self, py_identifier)
                if type(old_val) == list:
                    old_val.append(value)
                    setattr(self, py_identifier, old_val)
                else:
                    setattr(self, py_identifier, [old_val, value])
コード例 #11
0
 def _replace_name(cls, name):
     cls.original_name = cls.name
     cls.name = name
     cls.__name__ = util.to_valid_identifier_name(cls.name)
     cls._is_renamed = True
     cls._is_modified = True
コード例 #12
0
 def _replace_name(cls, name):
     cls.original_name = cls.name
     cls.name = name
     cls.__name__ = util.to_valid_identifier_name(cls.name)
     cls._is_renamed = True
     cls._is_modified = True