本文整理汇总了Python中xpra.os_util.bytestostr函数的典型用法代码示例。如果您正苦于以下问题:Python bytestostr函数的具体用法?Python bytestostr怎么用?Python bytestostr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bytestostr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
def check(self, str_value):
b = strtobytes(str_value)
assert b
s = bytestostr(b)
assert s
assert s==str_value
if not _memoryview:
return
mv = _memoryview(b)
mvb = memoryview_to_bytes(mv)
mvs = bytestostr(mvb)
assert mvs==str_value
示例2: get_env
def get_env(self):
env = os.environ.copy()
env["XPRA_SKIP_UI"] = "1"
env["XPRA_LOG_PREFIX"] = "%s " % self.description
#let's make things more complicated than they should be:
#on win32, the environment can end up containing unicode, and subprocess chokes on it
for k,v in env.items():
try:
env[k] = bytestostr(v.encode("utf8"))
except:
env[k] = bytestostr(v)
return env
示例3: exec_env
def exec_env(blacklist=["LS_COLORS", ]):
env = os.environ.copy()
env["XPRA_SKIP_UI"] = "1"
env["XPRA_FORCE_COLOR_LOG"] = "1"
#let's make things more complicated than they should be:
#on win32, the environment can end up containing unicode, and subprocess chokes on it
for k,v in env.items():
if k in blacklist:
continue
try:
env[k] = bytestostr(v.encode("utf8"))
except:
env[k] = bytestostr(v)
return env
示例4: listget
def listget(self, k, default_value=[], item_type=None, max_items=None):
v = self.capsget(k, default_value)
if v is None:
return default_value
if type(v) not in (list, tuple):
typedict.log.warn("expected a list or tuple value for %s but got %s", k, type(v))
return default_value
aslist = list(v)
if item_type:
for i in range(len(aslist)):
x = aslist[i]
if sys.version > '3' and type(x)==bytes and item_type==str:
x = bytestostr(x)
aslist[i] = x
elif type(x)==unicode and item_type==str:
x = str(x)
aslist[i] = x
if type(x)!=item_type:
typedict.log.warn("invalid item type for %s %s: expected %s but got %s", type(v), k, item_type, type(x))
return default_value
if max_items is not None:
if len(v)>max_items:
typedict.log.warn("too many items in %s %s: maximum %s allowed, but got %s", type(v), k, max_items, len(v))
return default_value
return aslist
示例5: _process_gibberish
def _process_gibberish(self, packet):
(_, message, data) = packet
p = self._protocol
show_as_text = p and p.input_packetcount==0 and all(c in string.printable for c in bytestostr(data))
if show_as_text:
#looks like the first packet back is just text, print it:
data = bytestostr(data)
if data.find("Traceback "):
for x in data.split("\n"):
log.warn(x.strip("\r"))
else:
log.warn("Failed to connect, received: %s", repr_ellipsized(data.strip("\n").strip("\r")))
else:
log.warn("Received uninterpretable nonsense: %s", message)
log.warn(" packet no %i data: %s", p.input_packetcount, repr_ellipsized(data))
if str(data).find("assword")>0:
self.warn_and_quit(EXIT_SSH_FAILURE,
"Your ssh program appears to be asking for a password."
+ GOT_PASSWORD_PROMPT_SUGGESTION)
elif str(data).find("login")>=0:
self.warn_and_quit(EXIT_SSH_FAILURE,
"Your ssh program appears to be asking for a username.\n"
"Perhaps try using something like 'ssh:[email protected]:display'?")
else:
self.quit(EXIT_PACKET_FAILURE)
示例6: draw_region
def draw_region(self, x, y, width, height, coding, img_data, rowstride, options, callbacks):
""" dispatches the paint to one of the paint_XXXX methods """
if DRAW_DEBUG:
log.info("draw_region(%s, %s, %s, %s, %s, %s bytes, %s, %s, %s)", x, y, width, height, coding, len(img_data), rowstride, options, callbacks)
coding = bytestostr(coding)
if coding == "mmap":
self.idle_add(self.paint_mmap, img_data, x, y, width, height, rowstride, options, callbacks)
elif coding == "rgb24":
if rowstride==0:
rowstride = width * 3
self.paint_rgb24(img_data, x, y, width, height, rowstride, options, callbacks)
elif coding == "rgb32":
if rowstride==0:
rowstride = width * 4
self.paint_rgb32(img_data, x, y, width, height, rowstride, options, callbacks)
elif coding == "x264":
self.paint_with_video_decoder(dec_avcodec, "x264", img_data, x, y, width, height, options, callbacks)
elif coding == "vpx":
self.paint_with_video_decoder(dec_vpx, "vpx", img_data, x, y, width, height, options, callbacks)
elif coding == "webp":
self.paint_webp(img_data, x, y, width, height, options, callbacks)
elif coding[:3]=="png" or coding=="jpeg":
self.paint_image(coding, img_data, x, y, width, height, options, callbacks)
else:
raise Exception("invalid encoding: %s" % coding)
示例7: _process_hello
def _process_hello(self, packet):
log.debug("process_hello: %s", packet)
props = packet[1]
if props:
def sorted_nicely(l):
""" Sort the given iterable in the way that humans expect."""
def convert(text):
if text.isdigit():
return int(text)
else:
return text
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', bytestostr(key)) ]
return sorted(l, key = alphanum_key)
for k in sorted_nicely(props.keys()):
v = props.get(k)
if sys.version_info[0]>=3:
#FIXME: this is a nasty and horrible python3 workaround (yet again)
#we want to print bytes as strings without the ugly 'b' prefix..
#it assumes that all the strings are raw or in (possibly nested) lists or tuples only
def fixvalue(w):
if type(w)==bytes:
return bytestostr(w)
elif type(w) in (tuple,list):
return type(w)([fixvalue(x) for x in w])
return w
v = fixvalue(v)
log.info("%s=%s", bytestostr(k), nonl(v))
self.quit(0)
示例8: draw_region
def draw_region(self, x, y, width, height, coding, img_data, rowstride, options, callbacks):
""" dispatches the paint to one of the paint_XXXX methods """
log("draw_region(%s, %s, %s, %s, %s, %s bytes, %s, %s, %s)", x, y, width, height, coding, len(img_data), rowstride, options, callbacks)
coding = bytestostr(coding)
options["encoding"] = coding #used for choosing the color of the paint box
if coding == "mmap":
self.idle_add(self.paint_mmap, img_data, x, y, width, height, rowstride, options, callbacks)
elif coding == "rgb24" or coding == "rgb32":
#avoid confusion over how many bytes-per-pixel we may have:
rgb_format = options.get("rgb_format")
if rgb_format:
Bpp = len(rgb_format)
elif coding=="rgb24":
Bpp = 3
else:
Bpp = 4
if rowstride==0:
rowstride = width * Bpp
if Bpp==3:
self.paint_rgb24(img_data, x, y, width, height, rowstride, options, callbacks)
else:
self.paint_rgb32(img_data, x, y, width, height, rowstride, options, callbacks)
elif coding in VIDEO_DECODERS:
self.paint_with_video_decoder(VIDEO_DECODERS.get(coding), coding, img_data, x, y, width, height, options, callbacks)
elif coding == "webp":
self.paint_webp(img_data, x, y, width, height, options, callbacks)
elif coding in self._PIL_encodings:
self.paint_image(coding, img_data, x, y, width, height, options, callbacks)
else:
self.do_draw_region(x, y, width, height, coding, img_data, rowstride, options, callbacks)
示例9: capsget
def capsget(self, key, default=None):
v = self.get(key)
#py3k and bytes as keys...
if v is None and type(key)==str:
v = self.get(strtobytes(key), default)
if sys.version >= '3' and type(v)==bytes:
v = bytestostr(v)
return v
示例10: sorted_nicely
def sorted_nicely(l):
""" Sort the given iterable in the way that humans expect."""
def convert(text):
if text.isdigit():
return int(text)
else:
return text
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', bytestostr(key)) ]
return sorted(l, key = alphanum_key)
示例11: _process_disconnect
def _process_disconnect(self, packet):
#ie: ("disconnect", "version error", "incompatible version")
reason = bytestostr(packet[1])
info = packet[2:]
s = nonl(reason)
if len(info):
s += " (%s)" % (", ".join([nonl(bytestostr(x)) for x in info]))
if self.server_capabilities is None or len(self.server_capabilities)==0:
#server never sent hello to us - so disconnect is an error
#(but we don't know which one - the info message may help)
log.warn("server failure: disconnected before the session could be established")
e = EXIT_FAILURE
elif disconnect_is_an_error(reason):
log.warn("server failure: %s", reason)
e = EXIT_FAILURE
else:
e = EXIT_OK
self.warn_and_quit(e, "server requested disconnect: %s" % s)
示例12: test_env
def test_env(self):
for var_name in ("XPRA_PASSWORD", "SOME_OTHER_VAR_NAME"):
password = strtobytes(uuid.uuid4().hex)
os.environ[var_name] = bytestostr(password)
try:
kwargs = {}
if var_name!="XPRA_PASSWORD":
kwargs["name"] = var_name
self._test_hmac_auth(env_auth, password, name=var_name)
finally:
del os.environ[var_name]
示例13: do_command
def do_command(self):
cr = self.server_capabilities.listget("command_response")
if cr is None:
self.warn_and_quit(EXIT_UNSUPPORTED, "server does not support control command")
return
code, text = cr
text = bytestostr(text)
if code!=0:
log.warn("server returned error code %s", code)
self.warn_and_quit(EXIT_REMOTE_ERROR, " %s" % text)
return
self.warn_and_quit(EXIT_OK, text)
示例14: _process_gibberish
def _process_gibberish(self, packet):
(_, message, data) = packet
p = self._protocol
show_as_text = p and p.input_packetcount==0 and all(c in string.printable for c in bytestostr(data))
if show_as_text:
#looks like the first packet back is just text, print it:
data = bytestostr(data)
if data.find("Traceback "):
for x in data.split("\n"):
netlog.warn(x.strip("\r"))
else:
netlog.warn("Failed to connect, received: %s", repr_ellipsized(data.strip("\n").strip("\r")))
else:
netlog.warn("Received uninterpretable nonsense: %s", message)
netlog.warn(" packet no %i data: %s", p.input_packetcount, repr_ellipsized(data))
self.quit(EXIT_PACKET_FAILURE)
示例15: apply_geometry_hints
def apply_geometry_hints(self, hints):
""" we convert the hints as a dict into a gdk.Geometry + gdk.WindowHints """
wh = Gdk.WindowHints
name_to_hint = {"maximum-size" : wh.MAX_SIZE,
"max_width" : wh.MAX_SIZE,
"max_height" : wh.MAX_SIZE,
"minimum-size" : wh.MIN_SIZE,
"min_width" : wh.MIN_SIZE,
"min_height" : wh.MIN_SIZE,
"base-size" : wh.BASE_SIZE,
"base_width" : wh.BASE_SIZE,
"base_height" : wh.BASE_SIZE,
"increment" : wh.RESIZE_INC,
"width_inc" : wh.RESIZE_INC,
"height_inc" : wh.RESIZE_INC,
"min_aspect_ratio" : wh.ASPECT,
"max_aspect_ratio" : wh.ASPECT,
}
#these fields can be copied directly to the gdk.Geometry as ints:
INT_FIELDS= ["min_width", "min_height",
"max_width", "max_height",
"base_width", "base_height",
"width_inc", "height_inc"]
ASPECT_FIELDS = {
"min_aspect_ratio" : "min_aspect",
"max_aspect_ratio" : "max_aspect",
}
geom = Gdk.Geometry()
mask = 0
for k,v in hints.items():
k = bytestostr(k)
if k in INT_FIELDS:
if k.find("width")>=0:
v = self._client.sx(v)
elif k.find("height")>=0:
v = self._client.sy(v)
elif k.find("size")>=0:
v = self._client.sp(v)
setattr(geom, k, int(v))
mask |= int(name_to_hint.get(k, 0))
elif k in ASPECT_FIELDS:
field = ASPECT_FIELDS.get(k)
setattr(geom, field, float(v))
mask |= int(name_to_hint.get(k, 0))
gdk_hints = Gdk.WindowHints(mask)
metalog("apply_geometry_hints(%s) geometry=%s, hints=%s", hints, geom, gdk_hints)
self.set_geometry_hints(None, geom, gdk_hints)