diff --git a/src/xpra/net/net_util.py b/src/xpra/net/net_util.py index bade73a760..61be11a5b3 100755 --- a/src/xpra/net/net_util.py +++ b/src/xpra/net/net_util.py @@ -152,9 +152,6 @@ def if_indextoname(index): return _libc.if_indextoname(c_uint(index), s) - - - def main(): from xpra.platform import init, clean try: diff --git a/src/xpra/net/protocol.py b/src/xpra/net/protocol.py index a43d76bfd8..ed767cbc9b 100644 --- a/src/xpra/net/protocol.py +++ b/src/xpra/net/protocol.py @@ -24,23 +24,22 @@ log = Logger("network", "protocol") debug = log.debug from xpra.os_util import Queue, strtobytes, get_hex_uuid -from xpra.daemon_thread import make_daemon_thread -from xpra.simple_stats import std_unit, std_unit_dec +from xpra.util import repr_ellipsized from xpra.net.bytestreams import ABORT -from xpra.os_util import builtins -_memoryview = builtins.__dict__.get("memoryview") + try: from Crypto.Cipher import AES from Crypto.Protocol.KDF import PBKDF2 except Exception, e: - AES = None - PBKDF2 = None + AES, PBKDF2 = None, None log("pycrypto is missing: %s", e) from zlib import compress, decompress try: + from xpra.os_util import builtins + _memoryview = builtins.__dict__.get("memoryview") from lz4 import LZ4_compress, LZ4_uncompress #@UnresolvedImport has_lz4 = True def lz4_compress(packet, level): @@ -195,19 +194,6 @@ def get_network_caps(legacy=True): return caps -def repr_ellipsized(obj, limit=100): - if isinstance(obj, str) and len(obj) > limit: - try: - s = repr(obj[:limit]) - if len(obj)>limit: - s += "..." - return s - except: - return binascii.hexlify(obj[:limit]) - else: - return repr(obj) - - class ConnectionClosedException(Exception): pass @@ -295,6 +281,7 @@ def __init__(self, scheduler, conn, process_packet_cb, get_packet_cb=None): self.cipher_out_name = None self.cipher_out_block_size = 0 self._write_lock = Lock() + from xpra.daemon_thread import make_daemon_thread self._write_thread = make_daemon_thread(self._write_thread_loop, "write") self._read_thread = make_daemon_thread(self._read_thread_loop, "read") self._read_parser_thread = make_daemon_thread(self._read_parse_thread_loop, "parse") @@ -992,6 +979,7 @@ def close(self): #no data sent or received, skip logging of stats: self._log_stats = False if self._log_stats: + from xpra.simple_stats import std_unit, std_unit_dec log.info("connection closed after %s packets received (%s bytes) and %s packets sent (%s bytes)", std_unit(self.input_packetcount), std_unit_dec(self._conn.input_bytecount), std_unit(self.output_packetcount), std_unit_dec(self._conn.output_bytecount) diff --git a/src/xpra/server/server_core.py b/src/xpra/server/server_core.py index 5159762ee7..346fd6057a 100644 --- a/src/xpra/server/server_core.py +++ b/src/xpra/server/server_core.py @@ -28,11 +28,11 @@ from xpra.platform import set_application_name from xpra.os_util import load_binary_file, get_machine_id, get_user_uuid, SIGNAMES from xpra.version_util import version_compat_check, get_version_info, get_platform_info, get_host_info, local_version, mk -from xpra.net.protocol import Protocol, use_lz4, use_rencode, use_yaml, new_cipher_caps, get_network_caps, repr_ellipsized +from xpra.net.protocol import Protocol, use_lz4, use_rencode, use_yaml, new_cipher_caps, get_network_caps from xpra.server.background_worker import stop_worker from xpra.daemon_thread import make_daemon_thread from xpra.server.proxy import XpraProxy -from xpra.util import typedict +from xpra.util import typedict, repr_ellipsized diff --git a/src/xpra/util.py b/src/xpra/util.py index 6d88e77e6c..f2c67dd957 100644 --- a/src/xpra/util.py +++ b/src/xpra/util.py @@ -5,6 +5,7 @@ # later version. See the file COPYING for details. import os +import binascii from xpra.os_util import strtobytes, bytestostr import traceback import threading @@ -318,6 +319,19 @@ def print_leaks(): return print_leaks +def repr_ellipsized(obj, limit=100): + if isinstance(obj, str) and len(obj) > limit: + try: + s = repr(obj[:limit]) + if len(obj)>limit: + s += "..." + return s + except: + return binascii.hexlify(obj[:limit]) + else: + return repr(obj) + + def pver(v): #print for lists with version numbers, or CSV strings if type(v) in (list, tuple):