当前位置: 首页>>代码示例>>Python>>正文


Python message.DecodeError方法代码示例

本文整理汇总了Python中google.protobuf.message.DecodeError方法的典型用法代码示例。如果您正苦于以下问题:Python message.DecodeError方法的具体用法?Python message.DecodeError怎么用?Python message.DecodeError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.protobuf.message的用法示例。


在下文中一共展示了message.DecodeError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_vector_tile

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def _get_vector_tile(self, x_tile, y_tile, z_tile):
        """Load up a single vector tile."""
        cache_file = "mapscache/{}.{}.{}.json".format(z_tile, x_tile, y_tile)
        if cache_file not in self._tiles:
            if os.path.isfile(cache_file):
                with open(cache_file, 'rb') as f:
                    tile = json.loads(f.read().decode('utf-8'))
            else:
                url = _VECTOR_URL.format(z_tile, x_tile, y_tile, _KEY)
                data = requests.get(url).content
                try:
                    tile = mapbox_vector_tile.decode(data)
                    with open(cache_file, mode='w') as f:
                        json.dump(literal_eval(repr(tile)), f)
                except DecodeError:
                    tile = None
            if tile:
                self._tiles[cache_file] = [x_tile, y_tile, z_tile, tile, False]
                if len(self._tiles) > _CACHE_SIZE:
                    self._tiles.popitem(False)
                self._screen.force_update() 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:23,代码来源:maps.py

示例2: deserialize_graph

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def deserialize_graph(ser_graph, graph_cls=None):
    from google.protobuf.message import DecodeError
    from .serialize.protos.graph_pb2 import GraphDef
    from .graph import DirectedGraph
    graph_cls = graph_cls or DirectedGraph
    ser_graph_bin = to_binary(ser_graph)
    g = GraphDef()
    try:
        ser_graph = ser_graph
        g.ParseFromString(ser_graph_bin)
        return graph_cls.from_pb(g)
    except DecodeError:
        pass

    try:
        ser_graph_bin = zlib.decompress(ser_graph_bin)
        g.ParseFromString(ser_graph_bin)
        return graph_cls.from_pb(g)
    except (zlib.error, DecodeError):
        pass

    json_obj = json.loads(to_str(ser_graph))
    return graph_cls.from_json(json_obj) 
开发者ID:mars-project,项目名称:mars,代码行数:25,代码来源:utils.py

示例3: handle

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def handle(self, connection_id, message_content):
        """Handles parsing incoming requests, and wrapping the final response.

        Args:
            connection_id (str): ZMQ identity sent over ZMQ socket
            message_content (bytes): Byte encoded request protobuf to be parsed

        Returns:
            HandlerResult: result to be sent in response back to client
        """
        try:
            request = self._request_proto()
            request.ParseFromString(message_content)
        except DecodeError:
            LOGGER.info('Protobuf %s failed to deserialize', request)
            return self._wrap_result(self._status.INTERNAL_ERROR)

        try:
            response = self._respond(request)
        except _ResponseFailed as e:
            response = e.status

        return self._wrap_result(response) 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:25,代码来源:client_handlers.py

示例4: handle

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def handle(self, connection_id, message_content):
        # If this is the configured consensus engine, make it active. This is
        # necessary for setting the active engine when the configured engine is
        # changed to an engine that is not registered yet
        request = consensus_pb2.ConsensusRegisterRequest()

        try:
            request.ParseFromString(message_content)
        except DecodeError:
            LOGGER.exception("Unable to decode ConsensusRegisterRequest")
            return HandlerResult(status=HandlerResult.DROP)

        if request.additional_protocols is not None:
            additional_protocols = \
                [(p.name, p.version) for p in request.additional_protocols]
        else:
            additional_protocols = []

        self._proxy.activate_if_configured(
            request.name, request.version, additional_protocols)

        return HandlerResult(status=HandlerStatus.PASS) 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:24,代码来源:handlers.py

示例5: start

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def start(self):
        """Starts receiving messages on the underlying socket and passes them
        to the message router.
        """
        self._is_running = True

        while self._is_running:
            try:
                zmq_msg = await self._socket.recv_multipart()

                message = Message()
                message.ParseFromString(zmq_msg[-1])

                await self._msg_router.route_msg(message)
            except DecodeError as e:
                LOGGER.warning('Unable to decode: %s', e)
            except zmq.ZMQError as e:
                LOGGER.warning('Unable to receive: %s', e)
                return
            except asyncio.CancelledError:
                self._is_running = False 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:23,代码来源:messaging.py

示例6: _parse_header

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def _parse_header(cls, header_proto, resource):
        """Deserializes a resource's base64 encoded Protobuf header.
        """
        header = header_proto()
        try:
            header_bytes = base64.b64decode(resource['header'])
            header.ParseFromString(header_bytes)
        except (KeyError, TypeError, ValueError, DecodeError):
            header = resource.get('header', None)
            LOGGER.error(
                'The validator sent a resource with %s %s',
                'a missing header' if header is None else 'an invalid header:',
                header or '')
            raise errors.ResourceHeaderInvalid()

        resource['header'] = cls._message_to_dict(header)
        return resource 
开发者ID:hyperledger,项目名称:sawtooth-core,代码行数:19,代码来源:route_handlers.py

示例7: testParseErrors

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def testParseErrors(self, message_module):
    msg = message_module.TestAllTypes()
    self.assertRaises(TypeError, msg.FromString, 0)
    self.assertRaises(Exception, msg.FromString, '0')
    # TODO(jieluo): Fix cpp extension to raise error instead of warning.
    # b/27494216
    end_tag = encoder.TagBytes(1, 4)
    if api_implementation.Type() == 'python':
      with self.assertRaises(message.DecodeError) as context:
        msg.FromString(end_tag)
      self.assertEqual('Unexpected end-group tag.', str(context.exception))
    else:
      with warnings.catch_warnings(record=True) as w:
        # Cause all warnings to always be triggered.
        warnings.simplefilter('always')
        msg.FromString(end_tag)
        assert len(w) == 1
        assert issubclass(w[-1].category, RuntimeWarning)
        self.assertEqual('Unexpected end-group tag: Not all data was converted',
                         str(w[-1].message)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:message_test.py

示例8: test_unpack

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def test_unpack(data_dir, heka_format, try_snappy, strict, expected_count,
                expected_exception):
    count = 0
    threw_exception = False
    filename = "{}/test_{}.heka".format(data_dir, heka_format)
    with open(filename, "rb") as o:
        if "gzip" in heka_format:
            o = streaming_gzip_wrapper(o)
        try:
            for r, b in message_parser.unpack(o, try_snappy=try_snappy, strict=strict):
                j = json.loads(r.message.payload)
                assert count == j["seq"]
                count += 1
        except DecodeError:
            threw_exception = True

    assert count == expected_count
    assert threw_exception == expected_exception 
开发者ID:mozilla,项目名称:python_moztelemetry,代码行数:20,代码来源:test_message_parser.py

示例9: __call__

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def __call__(self, stream, content_type):
        """
        Args:
            stream:
            content_type:
        """
        try:
            data = stream.read()
        finally:
            stream.close()

        for possible_response in _possible_responses():
            try:
                response = possible_response()
                response.ParseFromString(data)
                return response
            except (UnicodeDecodeError, DecodeError):
                # given that the payload does not have the response type, there no way to infer
                # the response without keeping state, so I'm iterating all the options.
                pass
        raise ValueError("data is not in the expected format") 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:23,代码来源:predictor.py

示例10: deserialize_token

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def deserialize_token(blob):
  """Coverts urlsafe base64 text to delegation_pb2.DelegationToken.

  Raises:
    BadTokenError if blob doesn't look like a valid DelegationToken.
  """
  if isinstance(blob, unicode):
    blob = blob.encode('ascii', 'ignore')
  try:
    as_bytes = b64.decode(blob)
  except (TypeError, ValueError) as exc:
    raise exceptions.BadTokenError('Not base64: %s' % exc)
  if len(as_bytes) > MAX_TOKEN_SIZE:
    raise exceptions.BadTokenError(
        'Unexpectedly huge token (%d bytes)' % len(as_bytes))
  try:
    return delegation_pb2.DelegationToken.FromString(as_bytes)
  except message.DecodeError as exc:
    raise exceptions.BadTokenError('Bad proto: %s' % exc) 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:delegation.py

示例11: _filtered_graph_bytes

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def _filtered_graph_bytes(graph_bytes):
    try:
        graph_def = graph_pb2.GraphDef().FromString(graph_bytes)
    # The reason for the RuntimeWarning catch here is b/27494216, whereby
    # some proto parsers incorrectly raise that instead of DecodeError
    # on certain kinds of malformed input. Triggering this seems to require
    # a combination of mysterious circumstances.
    except (message.DecodeError, RuntimeWarning):
        logger.warning(
            "Could not parse GraphDef of size %d. Skipping.", len(graph_bytes),
        )
        return None
    # Use the default filter parameters:
    # limit_attr_size=1024, large_attrs_key="_too_large_attrs"
    process_graph.prepare_graph_for_ui(graph_def)
    return graph_def.SerializeToString() 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:18,代码来源:uploader.py

示例12: _fetch_current_frame

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def _fetch_current_frame(self):
        path = "{}/{}".format(
            self.PLUGIN_LOGDIR, shared_config.SUMMARY_FILENAME
        )
        with self._lock:
            try:
                frame = file_system_tools.read_tensor_summary(path).astype(
                    np.uint8
                )
                self.most_recent_frame = frame
                return frame
            except (message.DecodeError, IOError, tf.errors.NotFoundError):
                if self.most_recent_frame is None:
                    self.most_recent_frame = im_util.get_image_relative_to_script(
                        "no-data.png"
                    )
                return self.most_recent_frame 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:19,代码来源:beholder_plugin.py

示例13: _deserialize

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def _deserialize(s, proto):
    if not isinstance(s, bytes):
        raise ValueError(
            'Parameter s must be bytes, '
            'but got type: {}'
            .format(type(s))
        )

    if not (hasattr(proto, 'ParseFromString') and
            callable(proto.ParseFromString)):
        raise ValueError(
            'No ParseFromString method is detected. '
            '\ntype is {}'.format(type(proto))
        )

    decoded = cast(Optional[int], proto.ParseFromString(s))
    if decoded is not None and decoded != len(s):
        raise message.DecodeError(
            "Protobuf decoding consumed too few bytes: {} out of {}"
            .format(decoded, len(s))
        )
    return proto 
开发者ID:seetaresearch,项目名称:dragon,代码行数:24,代码来源:serialization.py

示例14: profile_python

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def profile_python(self, options):
    """Profile the statistics of the Python codes.

      By default, it shows the call stack from root. To avoid
      redundant output, you may use options to filter as below
        options['show_name_regexes'] = ['.*my_code.py.*']

    Args:
      options: A dict of options. See core/profiler/g3doc/options.md.
    Returns:
      a MultiGraphNodeProto that records the results.
    """
    opts = _build_options(options)
    tfprof_node = tfprof_output_pb2.MultiGraphNodeProto()
    try:
      tfprof_node.ParseFromString(
          print_mdl.Profile('code'.encode('utf-8'), opts.SerializeToString()))
    except message.DecodeError as _:
      pass
    return tfprof_node 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:22,代码来源:model_analyzer.py

示例15: profile_operations

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import DecodeError [as 别名]
def profile_operations(self, options):
    """Profile the statistics of the Operation types (e.g. MatMul, Conv2D).

    Args:
      options: A dict of options. See core/profiler/g3doc/options.md.
    Returns:
      a MultiGraphNodeProto that records the results.
    """
    opts = _build_options(options)
    tfprof_node = tfprof_output_pb2.MultiGraphNodeProto()
    try:
      tfprof_node.ParseFromString(
          print_mdl.Profile('op'.encode('utf-8'), opts.SerializeToString()))
    except message.DecodeError as _:
      pass
    return tfprof_node 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:18,代码来源:model_analyzer.py


注:本文中的google.protobuf.message.DecodeError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。