コード例 #1
0
ファイル: elementmap.py プロジェクト: dls-controls/pymalcolm
    def replace_endpoints(self, d):
        children = OrderedDict()

        for k, v in d.items():
            assert isinstance(k, str_), "Expected string, got %s" % (k,)
            if k == "typeid":
                assert v == self.typeid, \
                    "Dict has typeid %s but Class has %s" % (v, self.typeid)
            else:
                try:
                    object.__getattribute__(self, k)
                except AttributeError:
                    children[k] = deserialize_object(v, self.child_type_check)
                else:
                    raise AttributeError(
                        "Setting child %r would shadow an attribute" % (k,))

        self.endpoints = list(children)

        for k, v in children.items():
            self.set_endpoint_data(k, v, notify=False)

        if self.process:
            self.process.report_changes(
                [self.process_path, serialize_object(self)])
コード例 #2
0
    def replace_endpoints(self, d):
        children = OrderedDict()

        for k, v in d.items():
            assert isinstance(k, str_), "Expected string, got %s" % (k, )
            if k == "typeid":
                assert v == self.typeid, \
                    "Dict has typeid %s but Class has %s" % (v, self.typeid)
            else:
                try:
                    object.__getattribute__(self, k)
                except AttributeError:
                    children[k] = deserialize_object(v, self.child_type_check)
                else:
                    raise AttributeError(
                        "Setting child %r would shadow an attribute" % (k, ))

        self.endpoints = list(children)

        for k, v in children.items():
            self.set_endpoint_data(k, v, notify=False)

        if self.process:
            self.process.report_changes(
                [self.process_path, serialize_object(self)])
コード例 #3
0
 def set_required(self, required, notify=True):
     """Set the required string list"""
     for r in required:
         assert r in self.elements, \
             "Expected one of %r, got %r" % (list(self.elements), r)
     required = StringArray(deserialize_object(t, str_) for t in required)
     self.set_endpoint_data("required", required, notify)
コード例 #4
0
 def make_return_table(self, part_tasks):
     # Filter part tasks so that we only run the ones hooked to us
     columns = OrderedDict(name=StringArrayMeta("Part name"))
     for part in part_tasks:
         hooked = [
             method_name
             for (method_name, hook, _) in get_hook_decorated(part)
             if hook is self
         ]
         for method_name, method_meta, func in get_method_decorated(part):
             if method_name in hooked:
                 # Add return metas to the table columns
                 for arg_name in method_meta.returns.elements:
                     md = method_meta.returns.elements[arg_name].to_dict()
                     if "ArrayMeta" in md["typeid"]:
                         md["tags"] = md["tags"] + ["hook:return_array"]
                     else:
                         md["typeid"] = md["typeid"].replace(
                             "Meta", "ArrayMeta")
                     meta = deserialize_object(md, VArrayMeta)
                     if arg_name in columns:
                         column_d = columns[arg_name].to_dict()
                         assert column_d == md, \
                             "%s != %s" % (column_d, md)
                     columns[arg_name] = meta
     meta = TableMeta("Part returns from hook", columns=columns)
     return_table = Table(meta)
     return return_table
コード例 #5
0
    def set_takes(self, takes, notify=True):
        """Set the arguments and default values for the method

        Args:
            takes (MapMeta): Arguments to the function
        """
        takes = deserialize_object(takes, MapMeta)
        self.set_endpoint_data("takes", takes, notify)
コード例 #6
0
ファイル: methodmeta.py プロジェクト: dls-controls/pymalcolm
    def set_takes(self, takes, notify=True):
        """Set the arguments and default values for the method

        Args:
            takes (MapMeta): Arguments to the function
        """
        takes = deserialize_object(takes, MapMeta)
        self.set_endpoint_data("takes", takes, notify)
コード例 #7
0
ファイル: request.py プロジェクト: dls-controls/pymalcolm
    def set_id(self, id_):
        """
        Set the identifier for the request

        Args:
            id_(int): Unique identifier for request
        """
        if id_ is not None:
            id_ = deserialize_object(id_, int)
        self.set_endpoint_data("id", id_)
コード例 #8
0
ファイル: attribute.py プロジェクト: dls-controls/pymalcolm
 def set_meta(self, meta, notify=True):
     """Set the VMeta object"""
     meta = deserialize_object(meta)
     # Check that the meta attribute_class is ourself
     assert hasattr(meta, "attribute_class"), \
         "Expected meta object, got %r" % meta
     assert isinstance(self, meta.attribute_class), \
         "Meta object needs to be attached to %s, we are a %s" % (
             meta.attribute_class, type(self))
     self.set_endpoint_data("meta", meta, notify)
コード例 #9
0
 def set_meta(self, meta, notify=True):
     """Set the VMeta object"""
     meta = deserialize_object(meta)
     # Check that the meta attribute_class is ourself
     assert hasattr(meta, "attribute_class"), \
         "Expected meta object, got %r" % meta
     assert isinstance(self, meta.attribute_class), \
         "Meta object needs to be attached to %s, we are a %s" % (
             meta.attribute_class, type(self))
     self.set_endpoint_data("meta", meta, notify)
コード例 #10
0
    def set_id(self, id_):
        """
        Set the identifier for the request

        Args:
            id_(int): Unique identifier for request
        """
        if id_ is not None:
            id_ = deserialize_object(id_, int)
        self.set_endpoint_data("id", id_)
コード例 #11
0
 def set_delta(self, delta):
     delta = deserialize_object(delta, bool)
     self.set_endpoint_data("delta", delta)
コード例 #12
0
 def set_parameters(self, parameters):
     if parameters is not None:
         parameters = OrderedDict(
             (deserialize_object(k, str_), serialize_object(v))
             for k, v in parameters.items())
     self.set_endpoint_data("parameters", parameters)
コード例 #13
0
ファイル: request.py プロジェクト: dls-controls/pymalcolm
 def set_endpoint(self, endpoint):
     if endpoint is not None:
         endpoint = [deserialize_object(e, str_) for e in endpoint]
     self.set_endpoint_data("endpoint", endpoint)
コード例 #14
0
ファイル: meta.py プロジェクト: dls-controls/pymalcolm
 def set_tags(self, tags, notify=True):
     """Set the tags list"""
     tags = [deserialize_object(t, str_) for t in tags]
     self.set_endpoint_data("tags", tags, notify)
コード例 #15
0
ファイル: meta.py プロジェクト: dls-controls/pymalcolm
 def set_label(self, label, notify=True):
     """Set the label string"""
     label = deserialize_object(label, str_)
     self.set_endpoint_data("label", label, notify)
コード例 #16
0
ファイル: tablemeta.py プロジェクト: dls-controls/pymalcolm
 def set_elements(self, elements, notify=True):
     """Set the elements dict from a ScalarArrayMeta or serialized dict"""
     elements = deserialize_object(elements, TableElementMap)
     self.set_endpoint_data("elements", elements, notify)
コード例 #17
0
 def set_tags(self, tags, notify=True):
     """Set the tags list"""
     tags = [deserialize_object(t, str_) for t in tags]
     self.set_endpoint_data("tags", tags, notify)
コード例 #18
0
 def set_returns(self, returns, notify=True):
     """Set the return parameters for the method to validate against"""
     returns = deserialize_object(returns, MapMeta)
     self.set_endpoint_data("returns", returns, notify)
コード例 #19
0
 def set_elements(self, elements, notify=True):
     """Set the elements dict from a ScalarMeta or serialized dict"""
     elements = deserialize_object(elements, ElementMap)
     self.set_endpoint_data("elements", elements, notify)
コード例 #20
0
ファイル: choicemeta.py プロジェクト: dls-controls/pymalcolm
 def set_choices(self, choices, notify=True):
     """Set the choices list"""
     choices = [deserialize_object(c, str_) for c in choices]
     self.set_endpoint_data("choices", choices, notify)
コード例 #21
0
 def set_label(self, label, notify=True):
     """Set the label string"""
     label = deserialize_object(label, str_)
     self.set_endpoint_data("label", label, notify)
コード例 #22
0
 def set_endpoint(self, endpoint):
     if endpoint is not None:
         endpoint = [deserialize_object(e, str_) for e in endpoint]
     self.set_endpoint_data("endpoint", endpoint)
コード例 #23
0
ファイル: response.py プロジェクト: dls-controls/pymalcolm
 def set_message(self, message):
     if message is not None:
         message = deserialize_object(message, str_)
     self.set_endpoint_data("message", message)
コード例 #24
0
 def set_description(self, description, notify=True):
     """Set the description string"""
     description = deserialize_object(description, str_)
     self.set_endpoint_data("description", description, notify)
コード例 #25
0
ファイル: methodmeta.py プロジェクト: dls-controls/pymalcolm
 def set_returns(self, returns, notify=True):
     """Set the return parameters for the method to validate against"""
     returns = deserialize_object(returns, MapMeta)
     self.set_endpoint_data("returns", returns, notify)
コード例 #26
0
 def set_writeable(self, writeable, notify=True):
     """Set the writeable bool"""
     writeable = deserialize_object(writeable, bool)
     self.set_endpoint_data("writeable", writeable, notify)
コード例 #27
0
 def set_bar(self, bar):
     d = OrderedDict()
     for k, v in bar.items():
         if k != "typeid":
             d[k] = deserialize_object(v)
     self.bar = d
コード例 #28
0
ファイル: request.py プロジェクト: dls-controls/pymalcolm
 def set_parameters(self, parameters):
     if parameters is not None:
         parameters = OrderedDict(
             (deserialize_object(k, str_), serialize_object(v))
             for k, v in parameters.items())
     self.set_endpoint_data("parameters", parameters)
コード例 #29
0
ファイル: meta.py プロジェクト: dls-controls/pymalcolm
 def set_writeable(self, writeable, notify=True):
     """Set the writeable bool"""
     writeable = deserialize_object(writeable, bool)
     self.set_endpoint_data("writeable", writeable, notify)
コード例 #30
0
 def set_choices(self, choices, notify=True):
     """Set the choices list"""
     choices = [deserialize_object(c, str_) for c in choices]
     self.set_endpoint_data("choices", choices, notify)
コード例 #31
0
ファイル: request.py プロジェクト: dls-controls/pymalcolm
 def set_delta(self, delta):
     delta = deserialize_object(delta, bool)
     self.set_endpoint_data("delta", delta)
コード例 #32
0
 def test_deserialize(self):
     a = EmptySerializable()
     d = a.to_dict()
     b = deserialize_object(d)
     assert a.to_dict() == b.to_dict()
コード例 #33
0
ファイル: meta.py プロジェクト: dls-controls/pymalcolm
 def set_description(self, description, notify=True):
     """Set the description string"""
     description = deserialize_object(description, str_)
     self.set_endpoint_data("description", description, notify)