def send_hello(self, challenge_response=None): hello = self.make_hello(challenge_response) self._queue_write(bencode(["hello", hello])) def send_gibberish(): self._queue_write("01234567890123456789") gobject.timeout_add(1000, send_gibberish) gobject.timeout_add(3000, self.try_sending_again)
def test_large_dict(): try: from xpra.x11.gtk_x11 import gdk_display_source #@UnusedImport from xpra.x11.bindings.keyboard_bindings import X11KeyboardBindings #@UnresolvedImport keyboard_bindings = X11KeyboardBindings() mappings = keyboard_bindings.get_keycode_mappings() b = bencode(mappings) print("bencode(%s)=%s" % (mappings, b)) d = bdecode(b) print("bdecode(%s)=%s" % (b, d)) except ImportError, e: print("test_large_dict() skipped because of: %s" % e)
def t(v, encstr=None): be = bencode(v) print("bencode(%s)=%s" % (v, be)) if encstr: assert be==encstr restored = bdecode(be) print("decode(%s)=%s" % (be, restored)) rlist = restored[0] if len(rlist)!=len(v): print("MISMATCH!") print("v=%s" % v) print("l=%s" % rlist) assert len(rlist)==2 assert rlist[0]==v[0] for ok,ov in v[1].items(): d = rlist[1] if ok not in d: print("restored dict is missing %s" % ok) return rlist rv = d.get(ok) if rv!=ov: print("value for %s does not match: %s vs %s" % (ok, ov, rv)) return rlist return rlist
def do_bencode(data): return bencode(data), FLAGS_BENCODE
def do_bencode(v): return bencode(v), FLAGS_BENCODE
def bencode(self, data): return bencode(data), 0
def do_bencode(data): return bencode(data), 0