Skip to content

Commit

Permalink
split more code away from protocol
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@6950 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 25, 2014
1 parent 4cf1267 commit 0f80d3f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
3 changes: 0 additions & 3 deletions src/xpra/net/net_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 7 additions & 19 deletions src/xpra/net/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/xpra/server/server_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
14 changes: 14 additions & 0 deletions src/xpra/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0f80d3f

Please sign in to comment.