本文整理汇总了Python中xpra.util.typedict函数的典型用法代码示例。如果您正苦于以下问题:Python typedict函数的具体用法?Python typedict怎么用?Python typedict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了typedict函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: query_sound
def query_sound():
import subprocess
command = get_sound_command()+["_sound_query"]
_add_debug_args(command)
kwargs = exec_kwargs()
env = exec_env()
env.update(get_sound_wrapper_env())
log("query_sound() command=%s, env=%s, kwargs=%s", command, env, kwargs)
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=None, env=env, **kwargs)
out, err = proc.communicate(None)
log("query_sound() process returned %s", proc.returncode)
log("query_sound() out=%s, err=%s", out, err)
if proc.returncode!=0:
return typedict()
d = typedict()
for x in out.decode("utf8").splitlines():
kv = x.split("=", 1)
if len(kv)==2:
#ie: kv = ["decoders", "mp3,vorbis"]
k,v = kv
#fugly warning: all the other values are lists.. but this one is not:
if k!=b"python.bits":
v = [x.encode() for x in v.split(",")]
#d["decoders"] = ["mp3", "vorbis"]
d[k.encode()] = v
log("query_sound()=%s", d)
return d
示例2: paint_and_vscroll
def paint_and_vscroll(self, ydelta=10):
print("paint_and_scroll(%i)" % (ydelta))
W, H = self.window.get_size()
if ydelta>0:
#scroll down, repaint the top:
scrolls = (0, 0, W, H-ydelta, 0, ydelta),
self.window.draw_region(0, 0, W, H, "scroll", scrolls, W*4, 0, typedict({"flush" : 1}), [])
self.paint_crect(0, 0, W, ydelta, 0x80808080)
else:
#scroll up, repaint the bottom:
scrolls = (0, -ydelta, W, H+ydelta, 0, ydelta),
self.window.draw_region(0, 0, W, H, "scroll", scrolls, W*4, 0, typedict({"flush" : 1}), [])
self.paint_crect(0, H-ydelta, W, -ydelta, 0xA0008020)
示例3: split_vscroll
def split_vscroll(self, i=1):
W, H = self.window.get_size()
scrolls = [
(0, H//2, W, H//2-i, 0, i),
(0, i, W, H//2-i, 0, -i),
]
self.window.draw_region(0, 0, W, H, "scroll", scrolls, W*4, 0, typedict({}), [])
示例4: _process_hello
def _process_hello(self, proto, packet):
capabilities = packet[1]
c = typedict(capabilities)
proto.set_compression_level(c.intget("compression_level", self.compression_level))
if use_rencode and c.boolget("rencode"):
proto.enable_rencode()
else:
proto.enable_bencode()
if c.boolget("lz4") and use_lz4 and self.compression_level==1:
proto.enable_lz4()
log("process_hello: capabilities=%s", capabilities)
if c.boolget("version_request"):
self.send_version_info(proto)
return False
auth_caps = self.verify_hello(proto, c)
if auth_caps is not False:
if c.boolget("info_request", False):
self.send_hello_info(proto)
return
command_req = c.strlistget("command_request")
if len(command_req)>0:
#call from UI thread:
self.idle_add(self.handle_command_request, proto, command_req)
return
#continue processing hello packet:
try:
self.hello_oked(proto, packet, c, auth_caps)
except:
log.error("server error processing new connection from %s", proto, exc_info=True)
self.disconnect_client(proto, "server error accepting new connection")
示例5: _process_hello
def _process_hello(self, proto, packet):
capabilities = packet[1]
c = typedict(capabilities)
proto.set_compression_level(c.intget("compression_level", self.compression_level))
proto.enable_compressor_from_caps(c)
if not proto.enable_encoder_from_caps(c):
#this should never happen:
#if we got here, we parsed a packet from the client!
#(maybe the client used an encoding it claims not to support?)
self.disconnect_client(proto, PROTOCOL_ERROR, "failed to negotiate a packet encoder")
return
log("process_hello: capabilities=%s", capabilities)
if c.boolget("version_request"):
self.send_version_info(proto)
return
auth_caps = self.verify_hello(proto, c)
if auth_caps is not False:
if c.boolget("info_request", False):
self.send_hello_info(proto)
return
command_req = c.strlistget("command_request")
if len(command_req)>0:
#call from UI thread:
self.idle_add(self.handle_command_request, proto, command_req)
return
#continue processing hello packet in UI thread:
self.idle_add(self.call_hello_oked, proto, packet, c, auth_caps)
示例6: init_window
def init_window(self, metadata):
self._backing = None
self._metadata = typedict()
# used for only sending focus events *after* the window is mapped:
self._been_mapped = False
self._override_redirect_windows = []
self.update_metadata(metadata)
示例7: __init__
def __init__(self, client, group_leader, wid, x, y, ww, wh, bw, bh, metadata, override_redirect, client_properties, border, max_window_size):
log("%s%s", type(self), (client, group_leader, wid, x, y, ww, wh, bw, bh, metadata, override_redirect, client_properties, max_window_size))
ClientWidgetBase.__init__(self, client, wid, metadata.boolget("has-alpha"))
self._override_redirect = override_redirect
self.group_leader = group_leader
self._pos = (x, y)
self._size = (ww, wh)
self._client_properties = client_properties
self._set_initial_position = False
self.size_constraints = typedict()
self.geometry_hints = {}
self._fullscreen = None
self._maximized = False
self._above = False
self._below = False
self._shaded = False
self._sticky = False
self._skip_pager = False
self._skip_taskbar = False
self._sticky = False
self._iconified = False
self._focused = False
self.border = border
self.max_window_size = max_window_size
self.button_state = {}
self.init_window(metadata)
self.setup_window(bw, bh)
self.update_metadata(metadata)
示例8: do_process_control_packet
def do_process_control_packet(self, proto, packet):
log("process_control_packet(%s, %s)", proto, packet)
packet_type = packet[0]
if packet_type==Protocol.CONNECTION_LOST:
log.info("Connection lost")
if proto in self.potential_protocols:
self.potential_protocols.remove(proto)
return
if packet_type=="hello":
caps = typedict(packet[1])
if caps.boolget("challenge"):
self.send_disconnect(proto, AUTHENTICATION_ERROR, "this socket does not use authentication")
return
if caps.get("info_request", False):
proto.send_now(("hello", self.get_proxy_info(proto)))
self.timeout_add(5*1000, self.send_disconnect, proto, CLIENT_EXIT_TIMEOUT, "info sent")
return
elif caps.get("stop_request", False):
self.stop("socket request", None)
return
elif caps.get("version_request", False):
from xpra import __version__
proto.send_now(("hello", {"version" : __version__}))
self.timeout_add(5*1000, self.send_disconnect, proto, CLIENT_EXIT_TIMEOUT, "version sent")
return
self.send_disconnect(proto, CONTROL_COMMAND_ERROR, "this socket only handles 'info', 'version' and 'stop' requests")
示例9: set_strut
def set_strut(self, strut):
if not HAS_X11_BINDINGS:
return
log("strut=%s", strut)
d = typedict(strut)
values = []
for x in ("left", "right", "top", "bottom"):
v = d.intget(x, 0)
#handle scaling:
if x in ("left", "right"):
v = self._client.sx(v)
else:
v = self._client.sy(v)
values.append(v)
has_partial = False
for x in ("left_start_y", "left_end_y",
"right_start_y", "right_end_y",
"top_start_x", "top_end_x",
"bottom_start_x", "bottom_end_x"):
if x in d:
has_partial = True
v = d.intget(x, 0)
if x.find("_x"):
v = self._client.sx(v)
elif x.find("_y"):
v = self._client.sy(v)
values.append(v)
log("setting strut=%s, has partial=%s", values, has_partial)
def do_set_strut():
if has_partial:
prop_set(self.get_window(), "_NET_WM_STRUT_PARTIAL", ["u32"], values)
prop_set(self.get_window(), "_NET_WM_STRUT", ["u32"], values[:4])
self.when_realized("strut", do_set_strut)
示例10: process_server_packet
def process_server_packet(self, proto, packet):
packet_type = packet[0]
log("process_server_packet: %s", packet_type)
if packet_type==Protocol.CONNECTION_LOST:
self.stop("server connection lost", proto)
return
elif packet_type=="disconnect":
log("got disconnect from server: %s", packet[1])
if self.exit:
self.server_protocol.close()
else:
self.stop("disconnect from server: %s" % packet[1])
elif packet_type=="hello":
c = typedict(packet[1])
maxw, maxh = c.intpair("max_desktop_size", (4096, 4096))
caps = self.filter_server_caps(c)
#add new encryption caps:
if self.cipher:
from xpra.net.crypto import crypto_backend_init, new_cipher_caps, DEFAULT_PADDING
crypto_backend_init()
padding_options = self.caps.strlistget("cipher.padding.options", [DEFAULT_PADDING])
auth_caps = new_cipher_caps(self.client_protocol, self.cipher, self.encryption_key, padding_options)
caps.update(auth_caps)
#may need to bump packet size:
proto.max_packet_size = maxw*maxh*4*4
file_transfer = self.caps.boolget("file-transfer") and c.boolget("file-transfer")
file_size_limit = max(self.caps.intget("file-size-limit"), c.intget("file-size-limit"))
file_max_packet_size = int(file_transfer) * (1024 + file_size_limit*1024*1024)
self.client_protocol.max_packet_size = max(self.client_protocol.max_packet_size, file_max_packet_size)
self.server_protocol.max_packet_size = max(self.server_protocol.max_packet_size, file_max_packet_size)
packet = ("hello", caps)
elif packet_type=="info-response":
#adds proxy info:
#note: this is only seen by the client application
#"xpra info" is a new connection, which talks to the proxy server...
info = packet[1]
info.update(self.get_proxy_info(proto))
elif packet_type=="lost-window":
wid = packet[1]
#mark it as lost so we can drop any current/pending frames
self.lost_windows.add(wid)
#queue it so it gets cleaned safely (for video encoders mostly):
self.encode_queue.put(packet)
#and fall through so tell the client immediately
elif packet_type=="draw":
#use encoder thread:
self.encode_queue.put(packet)
#which will queue the packet itself when done:
return
#we do want to reformat cursor packets...
#as they will have been uncompressed by the network layer already:
elif packet_type=="cursor":
#packet = ["cursor", x, y, width, height, xhot, yhot, serial, pixels, name]
#or:
#packet = ["cursor", ""]
self._packet_recompress(packet, 8, "cursor")
elif packet_type=="window-icon":
self._packet_recompress(packet, 5, "icon")
self.queue_client_packet(packet)
示例11: do_video_paint
def do_video_paint(self, img, x, y, enc_width, enc_height, width, height, options, callbacks):
target_rgb_formats = self.RGB_MODES
# as some video formats like vpx can forward transparency
# also we could skip the csc step in some cases:
pixel_format = img.get_pixel_format()
cd = self._csc_decoder
if cd is not None:
if cd.get_src_format() != pixel_format:
log("do_video_paint csc: switching src format from %s to %s", cd.get_src_format(), pixel_format)
self.do_clean_csc_decoder()
elif cd.get_dst_format() not in target_rgb_formats:
log("do_video_paint csc: switching dst format from %s to %s", cd.get_dst_format(), target_rgb_formats)
self.do_clean_csc_decoder()
elif cd.get_src_width() != enc_width or cd.get_src_height() != enc_height:
log(
"do_video_paint csc: switching src size from %sx%s to %sx%s",
enc_width,
enc_height,
cd.get_src_width(),
cd.get_src_height(),
)
self.do_clean_csc_decoder()
elif cd.get_dst_width() != width or cd.get_dst_height() != height:
log(
"do_video_paint csc: switching src size from %sx%s to %sx%s",
width,
height,
cd.get_dst_width(),
cd.get_dst_height(),
)
self.do_clean_csc_decoder()
if self._csc_decoder is None:
# use higher quality csc to compensate for lower quality source
# (which generally means that we downscaled via YUV422P or lower)
# or when upscaling the video:
q = options.intget("quality", 50)
csc_speed = int(min(100, 100 - q, 100.0 * (enc_width * enc_height) / (width * height)))
cd = self.make_csc(enc_width, enc_height, pixel_format, width, height, target_rgb_formats, csc_speed)
log("do_video_paint new csc decoder: %s", cd)
self._csc_decoder = cd
rgb_format = cd.get_dst_format()
rgb = cd.convert_image(img)
log("do_video_paint rgb using %s.convert_image(%s)=%s", cd, img, rgb)
img.free()
assert rgb.get_planes() == 0, "invalid number of planes for %s: %s" % (rgb_format, rgb.get_planes())
# make a new options dict and set the rgb format:
paint_options = typedict(options)
paint_options["rgb_format"] = rgb_format
# this will also take care of firing callbacks (from the UI thread):
def paint():
data = rgb.get_pixels()
rowstride = rgb.get_rowstride()
try:
self.do_paint_rgb(rgb_format, data, x, y, width, height, rowstride, paint_options, callbacks)
finally:
rgb.free()
self.idle_add(paint)
示例12: _process_challenge
def _process_challenge(self, packet):
authlog("processing challenge: %s", packet[1:])
def warn_server_and_exit(code, message, server_message="authentication failed"):
authlog.error("Error: authentication failed:")
authlog.error(" %s", message)
self.disconnect_and_quit(code, server_message)
if not self.password_file and not os.environ.get('XPRA_PASSWORD'):
warn_server_and_exit(EXIT_PASSWORD_REQUIRED, "this server requires authentication, please provide a password", "no password available")
return
password = self.load_password()
if not password:
warn_server_and_exit(EXIT_PASSWORD_FILE_ERROR, "failed to load password from file %s" % self.password_file, "no password available")
return
salt = packet[1]
if self.encryption:
assert len(packet)>=3, "challenge does not contain encryption details to use for the response"
server_cipher = typedict(packet[2])
key = self.get_encryption_key()
if key is None:
warn_server_and_exit(EXIT_ENCRYPTION, "the server does not use any encryption", "client requires encryption")
return
if not self.set_server_encryption(server_cipher, key):
return
#all server versions support a client salt,
#they also tell us which digest to use:
digest = packet[3]
client_salt = get_hex_uuid()+get_hex_uuid()
#TODO: use some key stretching algorigthm? (meh)
try:
from xpra.codecs.xor.cyxor import xor_str #@UnresolvedImport
salt = xor_str(salt, client_salt)
except:
salt = xor(salt, client_salt)
if digest==b"hmac":
import hmac, hashlib
def s(v):
try:
return v.encode()
except:
return str(v)
password = s(password)
salt = s(salt)
challenge_response = hmac.HMAC(password, salt, digestmod=hashlib.md5).hexdigest()
elif digest==b"xor":
#don't send XORed password unencrypted:
if not self._protocol.cipher_out and not ALLOW_UNENCRYPTED_PASSWORDS:
warn_server_and_exit(EXIT_ENCRYPTION, "server requested digest %s, cowardly refusing to use it without encryption" % digest, "invalid digest")
return
challenge_response = xor(password, salt)
else:
warn_server_and_exit(EXIT_PASSWORD_REQUIRED, "server requested an unsupported digest: %s" % digest, "invalid digest")
return
if digest:
authlog("%s(%s, %s)=%s", digest, binascii.hexlify(password), binascii.hexlify(salt), challenge_response)
self.password_sent = True
self.remove_packet_handlers("challenge")
self.send_hello(challenge_response, client_salt)
示例13: __init__
def __init__(self, window_class, client, wid=1, W=630, H=480):
self.wid = wid
self.window = window_class(client, None, wid, 10, 10, W, H, W, H, typedict({}), False, typedict({}), 0, None)
self.window.show()
self.paint_rect(0, 0, W, H, chr(255)*4*W*H)
self.paint_rect(W//2-16, H//2-16, 64, 64, chr(0)*4*64*64)
self.counter = 0
self.delta_x = 0
self.delta_y = 0
示例14: __init__
def __init__(self, window_class, client, wid, W=630, H=480, animate=True):
self.wid = wid
self.window = window_class(client, None, wid, 10, 10, W, H, W, H, typedict({}), False, typedict({}), 0, None)
self.window.show()
self.paint_rect(0, 0, W, H, chr(255)*4*W*H)
self.paint_rect(W//2-16, H//2-16, 32, 32, chr(0)*4*32*32)
self.animate = animate
self.damage = False
client.handle_key_action = self.handle_key_action
示例15: paint_image
def paint_image(self, coding, img_data, x, y, width, height, options, callbacks):
""" can be called from any thread """
# log("paint_image(%s, %s bytes, %s, %s, %s, %s, %s, %s)", coding, len(img_data), x, y, width, height, options, callbacks)
PIL = get_codec("PIL")
assert PIL.Image, "PIL.Image not found"
buf = BytesIOClass(img_data)
img = PIL.Image.open(buf)
assert img.mode in ("L", "P", "RGB", "RGBA"), "invalid image mode: %s" % img.mode
transparency = options.get("transparency", -1)
if img.mode == "P":
if transparency >= 0:
# this deals with alpha without any extra work
img = img.convert("RGBA")
else:
img = img.convert("RGB")
elif img.mode == "L":
if transparency >= 0:
# why do we have to deal with alpha ourselves??
def mask_value(a):
if a != transparency:
return 255
return 0
mask = PIL.Image.eval(img, mask_value)
mask = mask.convert("L")
def nomask_value(a):
if a != transparency:
return a
return 0
img = PIL.Image.eval(img, nomask_value)
img = img.convert("RGBA")
img.putalpha(mask)
else:
img = img.convert("RGB")
# use tobytes() if present, fallback to tostring():
data_fn = getattr(img, "tobytes", getattr(img, "tostring", None))
raw_data = data_fn("raw", img.mode)
paint_options = typedict(options)
rgb_format = img.mode
if rgb_format == "RGB":
# PIL flattens the data to a continuous straightforward RGB format:
rowstride = width * 3
img_data = self.process_delta(raw_data, width, height, rowstride, options)
elif rgb_format == "RGBA":
rowstride = width * 4
img_data = self.process_delta(raw_data, width, height, rowstride, options)
else:
raise Exception("invalid image mode: %s" % img.mode)
paint_options["rgb_format"] = rgb_format
self.idle_add(self.do_paint_rgb, rgb_format, img_data, x, y, width, height, rowstride, paint_options, callbacks)
return False