• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python os_util.bytestostr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xpra.os_util.bytestostr函数的典型用法代码示例。如果您正苦于以下问题:Python bytestostr函数的具体用法?Python bytestostr怎么用?Python bytestostr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了bytestostr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:svn2github,项目名称:Xpra,代码行数:12,代码来源:os_util_test.py


示例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
开发者ID:svn2github,项目名称:Xpra,代码行数:12,代码来源:subprocess_wrapper.py


示例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
开发者ID:svn2github,项目名称:Xpra,代码行数:14,代码来源:subprocess_wrapper.py


示例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
开发者ID:svn2github,项目名称:Xpra,代码行数:25,代码来源:util.py


示例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)
开发者ID:svn2github,项目名称:Xpra,代码行数:25,代码来源:client_base.py


示例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)
开发者ID:svn2github,项目名称:Xpra,代码行数:25,代码来源:window_backing_base.py


示例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)
开发者ID:svn2github,项目名称:Xpra,代码行数:28,代码来源:gobject_client_base.py


示例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)
开发者ID:svn2github,项目名称:Xpra,代码行数:30,代码来源:window_backing_base.py


示例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
开发者ID:svn2github,项目名称:Xpra,代码行数:8,代码来源:util.py


示例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)
开发者ID:svn2github,项目名称:Xpra,代码行数:9,代码来源:util.py


示例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)
开发者ID:svn2github,项目名称:Xpra,代码行数:18,代码来源:client_base.py


示例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]
开发者ID:svn2github,项目名称:Xpra,代码行数:11,代码来源:auth_test.py


示例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)
开发者ID:ljmljz,项目名称:xpra,代码行数:12,代码来源:gobject_client_base.py


示例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)
开发者ID:ljmljz,项目名称:xpra,代码行数:16,代码来源:client_base.py


示例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)
开发者ID:svn2github,项目名称:Xpra,代码行数:47,代码来源:client_window.py


示例16: pver

		def pver(v):
			if type(v) in (tuple, list):
				s = ""
				for i in range(len(v)):
					if i>0:
						#dot seperated numbers
						if type(v[i-1])==int:
							s += "."
						else:
							s += ", "
					s += str(v[i])
				return s
			if type(v)==bytes:
				from xpra.os_util import bytestostr
				v = bytestostr(v)
			if type(v)==str and v.startswith("v"):
				return v[1:]
			return str(v)
开发者ID:svn2github,项目名称:Xpra,代码行数:18,代码来源:net_util.py


示例17: 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
     assert type(v) in (list, tuple), "expected a list or tuple value for %s but got %s" % (k, type(v))
     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
             assert type(x)==item_type, "invalid item type for %s %s: expected %s but got %s" % (type(v), k, item_type, type(x))
     if max_items is not None:
         assert len(v)<=max_items, "too many items in %s %s: maximum %s allowed, but got %s" % (type(v), k, max_items, len(v))
     return aslist
开发者ID:svn2github,项目名称:Xpra,代码行数:19,代码来源:util.py


示例18: process_packet

 def process_packet(self, proto, packet):
     try:
         handler = None
         packet_type = packet[0]
         if packet_type!=int:
             packet_type = bytestostr(packet_type)
         handler = self._packet_handlers.get(packet_type)
         if handler:
             handler(packet)
             return
         handler = self._ui_packet_handlers.get(packet_type)
         if not handler:
             log.error("unknown packet type: %s", packet_type)
             return
         self.idle_add(handler, packet)
     except KeyboardInterrupt:
         raise
     except:
         log.error("Unhandled error while processing a '%s' packet from peer using %s", packet_type, handler, exc_info=True)
开发者ID:svn2github,项目名称:Xpra,代码行数:19,代码来源:client_base.py


示例19: process_packet

 def process_packet(self, proto, packet):
     command = bytestostr(packet[0])
     if command==Protocol.CONNECTION_LOST:
         log("connection-lost: %s, calling stop", packet[1:])
         self.net_stop()
         return
     elif command==Protocol.GIBBERISH:
         log.warn("gibberish received:")
         log.warn(" %s", repr_ellipsized(packet[1], limit=80))
         log.warn(" stopping")
         self.net_stop()
         return
     elif command=="stop":
         log("received stop message")
         self.net_stop()
         return
     elif command=="exit":
         log("received exit message")
         sys.exit(0)
         return
     #make it easier to hookup signals to methods:
     attr = command.replace("-", "_")
     if self.method_whitelist is not None and attr not in self.method_whitelist:
         log.warn("invalid command: %s (not in whitelist: %s)", attr, self.method_whitelist)
         return
     wo = self.wrapped_object
     if not wo:
         log("wrapped object is no more, ignoring method call '%s'", attr)
         return
     method = getattr(wo, attr, None)
     if not method:
         log.warn("unknown command: '%s'", attr)
         log.warn(" packet: '%s'", repr_ellipsized(str(packet)))
         return
     if DEBUG_WRAPPER:
         log("calling %s.%s%s", wo, attr, str(tuple(packet[1:]))[:128])
     self.idle_add(method, *packet[1:])
     INJECT_FAULT(proto)
开发者ID:svn2github,项目名称:Xpra,代码行数:38,代码来源:subprocess_wrapper.py


示例20: 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)
     img_data = self.img_data_tobytes(img_data)
     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 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)
开发者ID:svn2github,项目名称:Xpra,代码行数:23,代码来源:window_backing_base.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python os_util.strtobytes函数代码示例发布时间:2022-05-26
下一篇:
Python protocol.Protocol类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap