예제 #1
0
def register_deserialization_handlers():
    for supported_class in supported_classes:
        SerializerBase.register_dict_to_class(supported_class, deserialize)
    for supported_exc in supported_exceptions:
        SerializerBase.register_dict_to_class(supported_exc, deserialize_exception)
    import subprocess
    SerializerBase.register_class_to_dict(subprocess.CalledProcessError, serialize_called_process_error)
예제 #2
0
def register_deserialization_handlers():
    for supported_class in supported_classes:
        SerializerBase.register_dict_to_class(supported_class, deserialize)
    for supported_exc in supported_exceptions:
        SerializerBase.register_dict_to_class(supported_exc,
                                              deserialize_exception)
    import subprocess
    SerializerBase.register_class_to_dict(subprocess.CalledProcessError,
                                          serialize_called_process_error)
 def __init__(self):
     super().__init__()
     self.split_job = None
     self.parts_lock = threading.Lock()
     self.worker_fails = dict()
     self.ongoing_ranges = set()
     self.failed_ranges = set()
     self.completed_ranges = set()
     self.cleanup_queue = set()
     self.last_assigned_frame = 0
     self.job_parts = 0
     SerializerBase.register_dict_to_class("job.ExportRange", ExportRange.export_range_dict_to_class)
     SerializerBase.register_class_to_dict(ExportRange, ExportRange.export_range_class_to_dict)
예제 #4
0
    def to_dict(self) -> dict:
        """
            Serpent serialization requires to_dict
            Represent class InvalidUserError as a dictionary
            :return: A dictionary representation of this InvalidUserError
        """
        return {
            "__class__": "InvalidUserError",
            "message": self.message
        }

    @staticmethod
    def to_class(class_name: str, dictionary: dict) -> 'InvalidUserError':
        """
            This converts a dictionary representing an InvalidUserError
            to an object of type InvalidUserError
            This exception is thrown when there is a problem with the provided user_id
            :param class_name: parameter is required for serialization
            :param dictionary: dictionary representing an InvalidUserError
            :return:
        """
        del class_name
        return InvalidUserError(dictionary["message"])


# Register serialization and deserialization hooks for InvalidUserError and InvalidMovieError
SerializerBase.register_class_to_dict(InvalidUserError, InvalidUserError.to_dict)
SerializerBase.register_dict_to_class("InvalidUserError", InvalidUserError.to_class)
SerializerBase.register_class_to_dict(InvalidMovieError, InvalidMovieError.to_dict)
SerializerBase.register_dict_to_class("InvalidMovieError", InvalidMovieError.to_class)
예제 #5
0
파일: server.py 프로젝트: Peque/Pyro4
        "number-attribute": obj.number
    }


def thingy_dict_to_class(classname, d):
    print("{deserializer hook, converting to class: %s}" % d)
    return mycustomclasses.Thingy(d["number-attribute"])


def otherthingy_dict_to_class(classname, d):
    print("{deserializer hook, converting to class: %s}" % d)
    return mycustomclasses.OtherThingy(d["number"])

# for 'Thingy' we register both serialization and deserialization hooks
SerializerBase.register_dict_to_class("waheeee-custom-thingy", thingy_dict_to_class)
SerializerBase.register_class_to_dict(mycustomclasses.Thingy, thingy_class_to_dict)

# for 'OtherThingy' we only register a deserialization hook (and for serialization depend on serpent's default behavior)
SerializerBase.register_dict_to_class("mycustomclasses.OtherThingy", otherthingy_dict_to_class)


# regular Pyro server stuff

@Pyro4.expose
class Server(object):
    def method(self, arg):
        print("\nmethod called, arg=", arg)
        response = mycustomclasses.Thingy(999)
        return response

    def othermethod(self, arg):
예제 #6
0
    @staticmethod
    def to_dict(obj):
        return {
            "__class__": "Pyro4.utils.messagebus.message",
            "msgid": str(obj.msgid),
            "created": obj.created.isoformat(),
            "data": obj.data,
        }

    @classmethod
    def from_dict(cls, classname, d):
        return cls(uuid.UUID(d["msgid"]), datetime.datetime.strptime(d["created"], "%Y-%m-%dT%H:%M:%S.%f"), d["data"])


# make sure Pyro knows how to serialize the custom Message class
SerializerBase.register_class_to_dict(Message, Message.to_dict)
SerializerBase.register_dict_to_class("Pyro4.utils.messagebus.message", Message.from_dict)


@Pyro4.expose
class Subscriber(object):
    def __init__(self, auto_consume=True, max_queue_size=5000):
        self.bus = Pyro4.Proxy("PYRONAME:" + PYRO_MSGBUS_NAME)
        self.received_messages = queue.Queue(maxsize=max_queue_size)
        if auto_consume:
            self.__bus_consumer_thread = threading.Thread(target=self.__bus_consume_message)
            self.__bus_consumer_thread.daemon = True
            self.__bus_consumer_thread.start()

    def incoming_message(self, topic, message):
        self.received_messages.put((topic, message))
            bias: float = 0.0) -> Generator[sample.Sample, None, None]:
        gen = self.synth.semicircle_gen(frequency, amplitude, phase, bias)
        while True:
            chunk = next(gen)
            yield sample.Sample.from_array(chunk, self.synth.samplerate, 1)

    def pointy(self,
               frequency: int,
               duration: float,
               amplitude: float = 0.9999,
               phase: float = 0.0,
               bias: float = 0.0) -> sample.Sample:
        return self.synth.pointy(frequency, duration, amplitude, phase, bias)

    def pointy_gen(self,
                   frequency: int,
                   amplitude: float = 0.9999,
                   phase: float = 0.0,
                   bias: float = 0.0) -> Generator[sample.Sample, None, None]:
        gen = self.synth.pointy_gen(frequency, amplitude, phase, bias)
        while True:
            chunk = next(gen)
            yield sample.Sample.from_array(chunk, self.synth.samplerate, 1)


if __name__ == "__main__":
    Pyro4.config.SERIALIZER = "marshal"
    Pyro4.config.SERIALIZERS_ACCEPTED = {"marshal"}
    SerializerBase.register_class_to_dict(sample.Sample, sample_serializer)
    Pyro4.Daemon.serveSimple({WaveSynthServer: "synth.wavesynth"})
예제 #8
0
        for (id, value) in ts.replicas.items():

            if id not in self.replicas:

                self.replicas[id] = value

            elif value > self.replicas[id]:

                self.replicas[id] = ts.replicas[id]

    def to_dict(self) -> Dict:
        """
        Used for serpent serialisation
        :return: A dict representing this Timestamp
        """

        return {"__class__": "Timestamp", "replicas": self.replicas}

    @staticmethod
    def from_dict(classname: str, dict: Dict) -> 'Timestamp':
        """
        Used for serpent deserialisation
        :return: A Log
        """

        return Timestamp(dict["replicas"])


SerializerBase.register_class_to_dict(Timestamp, Timestamp.to_dict)
SerializerBase.register_dict_to_class('Timestamp', Timestamp.from_dict)
예제 #9
0
파일: menu.py 프로젝트: asmeyer2012/tarock
def SerializeMenuToDict(menu):
    out = {}
    out["__class__"] = "Menu"
    out["_active"] = menu._active
    out["_info"] = menu._info
    for key in menu._entries.keys():
        out["_entries.{0}".format(key)] = menu._entries[key]
        if key in menu._mask:
            out["_mask.{0}".format(key)] = True
        else:
            out["_mask.{0}".format(key)] = False
    return out


## need to define functions to serialize so Menu can be passed with Pyro
def DeserializeMenuDict(classname, mdict):
    menu = Menu()
    menu._active = mdict["_active"]
    menu._info = mdict["_info"]
    for key in mdict.keys():
        if key[:8] == '_entries':
            xkey = key[9:]
            menu._entries[xkey] = mdict[key]
            if mdict["_mask.{0}".format(xkey)]:
                menu._mask.add(xkey)
    return menu


SerializerBase.register_class_to_dict(Menu, SerializeMenuToDict)
SerializerBase.register_dict_to_class("Menu", DeserializeMenuDict)
예제 #10
0
    def to_dict(obj):
        return {
            "__class__": "Pyro4.utils.messagebus.message",
            "msgid": str(obj.msgid),
            "created": obj.created.isoformat(),
            "data": obj.data
        }

    @classmethod
    def from_dict(cls, classname, d):
        return cls(uuid.UUID(d["msgid"]),
                   datetime.datetime.strptime(d["created"], "%Y-%m-%dT%H:%M:%S.%f"),
                   d["data"])

# make sure Pyro knows how to serialize the custom Message class
SerializerBase.register_class_to_dict(Message, Message.to_dict)
SerializerBase.register_dict_to_class("Pyro4.utils.messagebus.message", Message.from_dict)


@Pyro4.expose
class Subscriber(object):
    """
    This class is meant to be subclassed, and the consume_message method reimplemented.
    As messages arrive from the publisher, the consume_message method gets called.
    """
    def __init__(self, auto_consume=True, max_queue_size=5000, host='localhost', port=9090, **kwargs):
        """
        kwargs:
            - auto_consume (bool): Automatically start subscribing (True)
            - max_queue_size (int): Max number of elements that can be placed in queue.Queue (5000)
            - host (str): The nameserver hostname ('localhost')
예제 #11
0
                if not (record.id in self):
                    self.records.append(record)

    def to_dict(self) -> Dict:
        """
        Used for serpent serialisation
        :return: A dict representing this Log
        """

        return {
            "__class__": "Log",
            "records": [record.to_dict() for record in self.records]
        }

    @staticmethod
    def from_dict(classname: str, dict: Dict) -> 'Log':
        """
        Used for serpent deserialisation
        :return: A Log
        """

        return Log(
            [Record.from_dict("Record", record) for record in dict["records"]])


SerializerBase.register_class_to_dict(Record, Record.to_dict)
SerializerBase.register_dict_to_class("Record", Record.from_dict)

SerializerBase.register_class_to_dict(Log, Log.to_dict)
SerializerBase.register_dict_to_class("Log", Log.from_dict)
예제 #12
0
파일: z3_embed.py 프로젝트: d1m0/pyboogie
Z3TypeEnv = Dict[str, Z3ValFactory_T]


def fi_deserialize(classname: str, d: Dict[Any, Any]) -> OpaqueVal:
    return OpaqueVal.from_dict(d)


def fi_serialize(obj: OpaqueVal) -> Dict[Any, Any]:
    d = OpaqueVal.to_dict(obj)
    assert "__class__" not in d
    d["__class__"] = "OpaqueVal"
    return d


SerializerBase.register_dict_to_class("OpaqueVal", fi_deserialize)
SerializerBase.register_class_to_dict(OpaqueVal, fi_serialize)


def type_to_z3sort(ast_typ: AstType) -> z3.SortRef:
    if isinstance(ast_typ, AstIntType):
        return IntSort()
    elif isinstance(ast_typ, AstBoolType):
        return BoolSort()
    else:
        # TODO: Multi-dimensional maps NYI
        assert isinstance(ast_typ, AstMapType) and len(ast_typ.domainT) == 1
        return z3.ArraySort(type_to_z3sort(ast_typ.domainT[0]),
                            type_to_z3sort(ast_typ.rangeT))


def type_to_z3(ast_typ: AstType) -> Z3ValFactory_T:
예제 #13
0
    f.ps = d["ps"]
    f.ps_distro = d["ps_distro"]
    f.protocol = d["protocol"]
    f.starting_date = d["starting_date"]
    f.trans_duration = d["trans_duration"]
    f.mesure = d["mesure"]
    m = mesure_config()
    m.metrics = d["mesure"]["metrics"]
    m.sampling_interval = d["mesure"]["sampling_interval"]
    m.finish_date = d["mesure"]["finish_date"]
    m.start_date = d["mesure"]["start_date"]
    f.mesure = m
    return f


SerializerBase.register_class_to_dict(flow_config, flow_config_class_to_dict)
SerializerBase.register_dict_to_class("flow_config", flow_config_dict_to_class)


def mesure_config_class_to_dict(obj):
    return dict(__class__="mesure_config",
                metrics=obj.metrics,
                start_date=obj.start_date,
                finish_date=obj.finish_date,
                sampling_interval=obj.sampling_interval)


def mesure_config_dict_to_class(classname, d):
    m = mesure_config()
    m.metrics = d["metrics"]
    m.sampling_interval = d["sampling_interval"]
예제 #14
0
#       TaskProcessingError is designed to be returned on the result
#       "slot" of Task, and when I've attempted to register
#       (de)serialization hooks for both Task and TaskProcessingError,
#       the end result is that the TaskProcessingError
#       de-serialization hook never gets called (leaving it in its
#       serialized dict form on the deserialized Task object). This
#       defeats the purpose of creating a TaskProcessingError type.
#       Perhaps there is a way around this, but for now I am giving
#       priority to having an error type that can be transmitted
#       for all serializers in both Pyro and Pyro4 (over making
#       Task a class again).
#
if using_pyro4:
    import Pyro4
    from Pyro4.util import SerializerBase

    # register hooks for TaskProcessingError
    def TaskProcessingError_to_dict(obj):
        return {
            "__class__": "pyutilib.pyro.task.TaskProcessingError",
            "message": obj.args[0]
        }

    def dict_to_TaskProcessingError(classname, d):
        return TaskProcessingError(d['message'])

    SerializerBase.register_class_to_dict(TaskProcessingError,
                                          TaskProcessingError_to_dict)
    SerializerBase.register_dict_to_class(
        "pyutilib.pyro.task.TaskProcessingError", dict_to_TaskProcessingError)
예제 #15
0
파일: serialization.py 프로젝트: HMazen/pcd
    f.ps = d["ps"]
    f.ps_distro = d["ps_distro"]
    f.protocol = d["protocol"]
    f.starting_date = d["starting_date"]
    f.trans_duration = d["trans_duration"]
    f.mesure = d["mesure"]
    m = mesure_config()
    m.metrics = d["mesure"]["metrics"]
    m.sampling_interval = d["mesure"]["sampling_interval"]
    m.finish_date = d["mesure"]["finish_date"]
    m.start_date = d["mesure"]["start_date"]
    f.mesure = m
    return f


SerializerBase.register_class_to_dict(flow_config, flow_config_class_to_dict)
SerializerBase.register_dict_to_class("flow_config", flow_config_dict_to_class)


def mesure_config_class_to_dict(obj):
    return dict(__class__="mesure_config", metrics=obj.metrics, start_date=obj.start_date, finish_date=obj.finish_date,
                sampling_interval=obj.sampling_interval)


def mesure_config_dict_to_class(classname, d):
    m = mesure_config()
    m.metrics = d["metrics"]
    m.sampling_interval = d["sampling_interval"]
    m.finish_date = d["finish_date"]
    m.start_date = d["start_date"]
    return m
예제 #16
0
파일: task.py 프로젝트: nerdoc/pyutilib
# Note: We can use this same mechanism to allow Task to be
#       re-implemented as a custom class.  HOWEVER,
#       TaskProcessingError is designed to be returned on the result
#       "slot" of Task, and when I've attempted to register
#       (de)serialization hooks for both Task and TaskProcessingError,
#       the end result is that the TaskProcessingError
#       de-serialization hook never gets called (leaving it in its
#       serialized dict form on the deserialized Task object). This
#       defeats the purpose of creating a TaskProcessingError type.
#       Perhaps there is a way around this, but for now I am giving
#       priority to having an error type that can be transmitted
#       for all serializers in both Pyro and Pyro4 (over making
#       Task a class again).
#
if using_pyro4:
    import Pyro4
    from Pyro4.util import SerializerBase

    # register hooks for TaskProcessingError
    def TaskProcessingError_to_dict(obj):
        return {"__class__": "pyutilib.pyro.task.TaskProcessingError",
                "message": obj.args[0]}
    def dict_to_TaskProcessingError(classname, d):
        return TaskProcessingError(d['message'])
    SerializerBase.register_class_to_dict(
        TaskProcessingError,
        TaskProcessingError_to_dict)
    SerializerBase.register_dict_to_class(
        "pyutilib.pyro.task.TaskProcessingError",
        dict_to_TaskProcessingError)
예제 #17
0

def thingy_dict_to_class(classname, d):
    print("{deserializer hook, converting to class: %s}" % d)
    return mycustomclasses.Thingy(d["number-attribute"])


def otherthingy_dict_to_class(classname, d):
    print("{deserializer hook, converting to class: %s}" % d)
    return mycustomclasses.OtherThingy(d["number"])


# for 'Thingy' we register both serialization and deserialization hooks
SerializerBase.register_dict_to_class("waheeee-custom-thingy",
                                      thingy_dict_to_class)
SerializerBase.register_class_to_dict(mycustomclasses.Thingy,
                                      thingy_class_to_dict)

# for 'OtherThingy' we only register a deserialization hook (and for serialization depend on serpent's default behavior)
SerializerBase.register_dict_to_class("mycustomclasses.OtherThingy",
                                      otherthingy_dict_to_class)

# regular Pyro server stuff


@Pyro4.expose
class Server(object):
    def method(self, arg):
        print("\nmethod called, arg=", arg)
        response = mycustomclasses.Thingy(999)
        return response
예제 #18
0
def register_classes():
    """
    Register the serializers
    """
    SerializerBase.register_class_to_dict(Path, path_class_to_dict)
    SerializerBase.register_dict_to_class('Path', path_dict_to_class)