def testSerializableTypes(self):
        # new style callable instance.
        i = TestHandler()
        self.assertNotEquals(None, util.try_deserialize_handler(util.try_serialize_handler(i)))

        i = TestHandlerOldStyle()
        self.assertNotEquals(None, util.try_deserialize_handler(util.try_serialize_handler(i)))
示例#2
0
    def testSerializableTypes(self):
        # new style callable instance.
        i = TestHandler()
        self.assertNotEquals(
            None, util.try_deserialize_handler(util.try_serialize_handler(i)))

        i = TestHandlerOldStyle()
        self.assertNotEquals(
            None, util.try_deserialize_handler(util.try_serialize_handler(i)))
示例#3
0
    def from_request(cls, request):
        """Create new TransientShardState from webapp request."""
        mapreduce_spec = MapreduceSpec.from_json_str(
            request.get("mapreduce_spec"))
        mapper_spec = mapreduce_spec.mapper
        input_reader_spec_dict = simplejson.loads(
            request.get("input_reader_state"), cls=JsonDecoder)
        input_reader = mapper_spec.input_reader_class().from_json(
            input_reader_spec_dict)
        initial_input_reader_spec_dict = simplejson.loads(
            request.get("initial_input_reader_state"), cls=JsonDecoder)
        initial_input_reader = mapper_spec.input_reader_class().from_json(
            initial_input_reader_spec_dict)

        output_writer = None
        if mapper_spec.output_writer_class():
            output_writer = mapper_spec.output_writer_class().from_json(
                simplejson.loads(request.get("output_writer_state", "{}"),
                                 cls=JsonDecoder))
            assert isinstance(output_writer, mapper_spec.output_writer_class(
            )), ("%s.from_json returned an instance of wrong class: %s" %
                 (mapper_spec.output_writer_class(), output_writer.__class__))

        request_path = request.path
        base_path = request_path[:request_path.rfind("/")]

        handler = util.try_deserialize_handler(
            request.get("serialized_handler"))
        if not handler:
            handler = mapreduce_spec.mapper.handler

        return cls(base_path,
                   mapreduce_spec,
                   str(request.get("shard_id")),
                   int(request.get("slice_id")),
                   input_reader,
                   initial_input_reader,
                   output_writer=output_writer,
                   retries=int(request.get("retries")),
                   handler=handler)
示例#4
0
  def from_request(cls, request):
    """Create new TransientShardState from webapp request."""
    mapreduce_spec = MapreduceSpec.from_json_str(request.get("mapreduce_spec"))
    mapper_spec = mapreduce_spec.mapper
    input_reader_spec_dict = simplejson.loads(request.get("input_reader_state"),
                                              cls=JsonDecoder)
    input_reader = mapper_spec.input_reader_class().from_json(
        input_reader_spec_dict)
    initial_input_reader_spec_dict = simplejson.loads(
        request.get("initial_input_reader_state"), cls=JsonDecoder)
    initial_input_reader = mapper_spec.input_reader_class().from_json(
        initial_input_reader_spec_dict)

    output_writer = None
    if mapper_spec.output_writer_class():
      output_writer = mapper_spec.output_writer_class().from_json(
          simplejson.loads(request.get("output_writer_state", "{}"),
                           cls=JsonDecoder))
      assert isinstance(output_writer, mapper_spec.output_writer_class()), (
          "%s.from_json returned an instance of wrong class: %s" % (
              mapper_spec.output_writer_class(),
              output_writer.__class__))

    request_path = request.path
    base_path = request_path[:request_path.rfind("/")]

    handler = util.try_deserialize_handler(request.get("serialized_handler"))
    if not handler:
      handler = mapreduce_spec.mapper.handler

    return cls(base_path,
               mapreduce_spec,
               str(request.get("shard_id")),
               int(request.get("slice_id")),
               input_reader,
               initial_input_reader,
               output_writer=output_writer,
               retries=int(request.get("retries")),
               handler=handler)