зеркало из https://github.com/AvaloniaUI/angle.git
Sync logdog with Chromium
To make it python3 compatible, applying crrev.com/946471: Roll //third_party/logdog 9a84af84d..17ec234f Changes: 17ec234 logdog: make _MAPPING top level variable 88ab863 py3: make logdog lib python3 compatible 794d09a logdog: fix typo in docstring Bug: angleproject:6763 Change-Id: If24f49414b7c4d9fb6cc0630b0bea25a67666a53 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3323238 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Yuly Novikov <ynovikov@chromium.org>
This commit is contained in:
Родитель
16ce5226e8
Коммит
0dad51780f
|
@ -1,8 +1,8 @@
|
|||
Name: logdog
|
||||
Short Name: logdog
|
||||
URL: https://chromium.googlesource.com/infra/luci/luci-py/client/libs/logdog
|
||||
Version: 9a84af84d3fa62b230569cf1d3abf69cc7c576e2
|
||||
Revision: 9a84af84d3fa62b230569cf1d3abf69cc7c576e2
|
||||
Version: 17ec234f823f7bff6ada6584fdbbee9d54b8fc58
|
||||
Revision: 17ec234f823f7bff6ada6584fdbbee9d54b8fc58
|
||||
License: Apache 2.0
|
||||
License File: NOT_SHIPPED
|
||||
Security Critical: no
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
set -eux
|
||||
|
||||
revision=9a84af84d3fa62b230569cf1d3abf69cc7c576e2
|
||||
revision=17ec234f823f7bff6ada6584fdbbee9d54b8fc58
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class ButlerBootstrap(_ButlerBootstrapBase):
|
|||
env (dict): The environment to probe. If None, `os.getenv` will be used.
|
||||
|
||||
Raises:
|
||||
NotBootstrappedError if the current environment is not boostrapped.
|
||||
NotBootstrappedError if the current environment is not bootstrapped.
|
||||
"""
|
||||
if env is None:
|
||||
env = os.environ
|
||||
|
|
|
@ -14,17 +14,22 @@ import time
|
|||
|
||||
from . import streamname, varint
|
||||
|
||||
|
||||
if sys.platform == "win32":
|
||||
from ctypes import GetLastError
|
||||
|
||||
_PY2 = sys.version_info[0] == 2
|
||||
_MAPPING = collections.Mapping if _PY2 else collections.abc.Mapping
|
||||
|
||||
_StreamParamsBase = collections.namedtuple('_StreamParamsBase',
|
||||
('name', 'type', 'content_type', 'tags'))
|
||||
|
||||
|
||||
# Magic number at the beginning of a Butler stream
|
||||
#
|
||||
# See "ProtocolFrameHeaderMagic" in:
|
||||
# <luci-go>/logdog/client/butlerlib/streamproto
|
||||
BUTLER_MAGIC = 'BTLR1\x1e'
|
||||
BUTLER_MAGIC = b'BTLR1\x1e'
|
||||
|
||||
|
||||
class StreamParams(_StreamParamsBase):
|
||||
|
@ -56,7 +61,7 @@ class StreamParams(_StreamParamsBase):
|
|||
raise ValueError('Invalid type (%s)' % (self.type,))
|
||||
|
||||
if self.tags is not None:
|
||||
if not isinstance(self.tags, collections.Mapping):
|
||||
if not isinstance(self.tags, _MAPPING):
|
||||
raise ValueError('Invalid tags type (%s)' % (self.tags,))
|
||||
for k, v in self.tags.items():
|
||||
streamname.validate_tag(k, v)
|
||||
|
@ -187,6 +192,30 @@ class StreamClient(object):
|
|||
def close(self):
|
||||
return self._fd.close()
|
||||
|
||||
class _TextStream(_BasicStream):
|
||||
"""Extends _BasicStream, ensuring data written is UTF-8 text."""
|
||||
|
||||
def __init__(self, stream_client, params, fd):
|
||||
super(StreamClient._TextStream, self).__init__(stream_client, params, fd)
|
||||
self._fd = fd
|
||||
|
||||
def write(self, data):
|
||||
if _PY2 and isinstance(data, str):
|
||||
# byte string is unfortunately accepted in py2 because of
|
||||
# undifferentiated usage of `str` and `unicode` but it should be
|
||||
# discontinued in py3. User should switch to binary stream instead
|
||||
# if there's a need to write bytes.
|
||||
return self._fd.write(data)
|
||||
elif _PY2 and isinstance(data, unicode):
|
||||
return self._fd.write(data.encode('utf-8'))
|
||||
elif not _PY2 and isinstance(data, str):
|
||||
return self._fd.write(data.encode('utf-8'))
|
||||
else:
|
||||
raise ValueError('expect str, got %r that is type %s' % (
|
||||
data,
|
||||
type(data),
|
||||
))
|
||||
|
||||
class _DatagramStream(_StreamBase):
|
||||
"""Wraps a stream object to write length-prefixed datagrams."""
|
||||
|
||||
|
@ -339,12 +368,12 @@ class StreamClient(object):
|
|||
are not valid.
|
||||
"""
|
||||
self._register_new_stream(params.name)
|
||||
params_json = params.to_json()
|
||||
params_bytes = params.to_json().encode('utf-8')
|
||||
|
||||
fobj = self._connect_raw()
|
||||
fobj.write(BUTLER_MAGIC)
|
||||
varint.write_uvarint(fobj, len(params_json))
|
||||
fobj.write(params_json)
|
||||
varint.write_uvarint(fobj, len(params_bytes))
|
||||
fobj.write(params_bytes)
|
||||
return fobj
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
@ -390,7 +419,7 @@ class StreamClient(object):
|
|||
type=StreamParams.TEXT,
|
||||
content_type=content_type,
|
||||
tags=tags)
|
||||
return self._BasicStream(self, params, self.new_connection(params))
|
||||
return self._TextStream(self, params, self.new_connection(params))
|
||||
|
||||
@contextlib.contextmanager
|
||||
def binary(self, name, **kwargs):
|
||||
|
|
|
@ -53,7 +53,7 @@ def validate_tag(key, value):
|
|||
|
||||
|
||||
def normalize_segment(seg, prefix=None):
|
||||
"""Given a string (str|unicode), mutate it into a valid segment name (str).
|
||||
"""Given a string, mutate it into a valid segment name.
|
||||
|
||||
This operates by replacing invalid segment name characters with underscores
|
||||
(_) when encountered.
|
||||
|
@ -87,15 +87,11 @@ def normalize_segment(seg, prefix=None):
|
|||
if _SEGMENT_RE.match(seg) is None:
|
||||
raise AssertionError('Normalized segment is still invalid: %r' % seg)
|
||||
|
||||
# v could be of type unicode. As a valid stream name contains only ascii
|
||||
# characters, it is safe to transcode v to ascii encoding (become str type).
|
||||
if isinstance(seg, unicode):
|
||||
return seg.encode('ascii')
|
||||
return seg
|
||||
|
||||
|
||||
def normalize(v, prefix=None):
|
||||
"""Given a string (str|unicode), mutate it into a valid stream name (str).
|
||||
"""Given a string, mutate it into a valid stream name.
|
||||
|
||||
This operates by replacing invalid stream name characters with underscores (_)
|
||||
when encountered.
|
||||
|
@ -163,7 +159,7 @@ class StreamPath(collections.namedtuple('_StreamPath', ('prefix', 'name'))):
|
|||
except ValueError as e:
|
||||
raise ValueError('Invalid prefix component [%s]: %s' % (
|
||||
self.prefix,
|
||||
e.message,
|
||||
e,
|
||||
))
|
||||
|
||||
try:
|
||||
|
@ -171,7 +167,7 @@ class StreamPath(collections.namedtuple('_StreamPath', ('prefix', 'name'))):
|
|||
except ValueError as e:
|
||||
raise ValueError('Invalid name component [%s]: %s' % (
|
||||
self.name,
|
||||
e.message,
|
||||
e,
|
||||
))
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# that can be found in the LICENSE file.
|
||||
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
|
||||
|
@ -28,7 +29,7 @@ def write_uvarint(w, val):
|
|||
if val > 0:
|
||||
byte |= 0b10000000
|
||||
|
||||
w.write(chr(byte))
|
||||
w.write(struct.pack('B', byte))
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
@ -55,7 +56,7 @@ def read_uvarint(r):
|
|||
if len(byte) == 0:
|
||||
raise ValueError('UVarint was not terminated')
|
||||
|
||||
byte = ord(byte)
|
||||
byte = struct.unpack('B', byte)[0]
|
||||
result |= ((byte & 0b01111111) << (7 * count))
|
||||
count += 1
|
||||
if byte & 0b10000000 == 0:
|
||||
|
|
Загрузка…
Ссылка в новой задаче