Skip to content

Commit

Permalink
同步最新SSRR源码
Browse files Browse the repository at this point in the history
  • Loading branch information
Scyllaly committed May 19, 2018
1 parent fa968d0 commit 68d2317
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 3 deletions.
Empty file modified initcfg.sh
100644 → 100755
Empty file.
Empty file modified initmudbjson.sh
100644 → 100755
Empty file.
Empty file modified logrun.sh
100644 → 100755
Empty file.
Empty file modified run.sh
100644 → 100755
Empty file.
Empty file modified setup_cymysql.sh
100644 → 100755
Empty file.
Empty file modified setup_cymysql2.sh
100644 → 100755
Empty file.
36 changes: 33 additions & 3 deletions shadowsocks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,19 @@ def is_ip(address):
return False


def sync_str_bytes(obj, target_example):
"""sync (obj)'s type to (target_example)'s type"""
if type(obj) != type(target_example):
if type(target_example) == str:
obj = to_str(obj)
if type(target_example) == bytes:
obj = to_bytes(obj)
return obj


def match_regex(regex, text):
# avoid 'cannot use a string pattern on a bytes-like object'
regex = sync_str_bytes(regex, text)
regex = re.compile(regex)
for item in regex.findall(text):
return True
Expand Down Expand Up @@ -381,12 +393,12 @@ def test_inet_conv():

def test_parse_header():
assert parse_header(b'\x03\x0ewww.google.com\x00\x50') == \
(0, b'www.google.com', 80, 18)
(0, ADDRTYPE_HOST, b'www.google.com', 80, 18)
assert parse_header(b'\x01\x08\x08\x08\x08\x00\x35') == \
(0, b'8.8.8.8', 53, 7)
(0, ADDRTYPE_IPV4, b'8.8.8.8', 53, 7)
assert parse_header((b'\x04$\x04h\x00@\x05\x08\x05\x00\x00\x00\x00\x00'
b'\x00\x10\x11\x00\x50')) == \
(0, b'2404:6800:4005:805::1011', 80, 19)
(0, ADDRTYPE_IPV6, b'2404:6800:4005:805::1011', 80, 19)


def test_pack_header():
Expand All @@ -411,7 +423,25 @@ def test_ip_network():
assert 'www.google.com' not in ip_network


def test_sync_str_bytes():
assert sync_str_bytes(b'a\.b', b'a\.b') == b'a\.b'
assert sync_str_bytes('a\.b', b'a\.b') == b'a\.b'
assert sync_str_bytes(b'a\.b', 'a\.b') == 'a\.b'
assert sync_str_bytes('a\.b', 'a\.b') == 'a\.b'
pass


def test_match_regex():
assert match_regex(br'a\.b', b'abc,aaa,aaa,b,aaa.b,a.b')
assert match_regex(r'a\.b', b'abc,aaa,aaa,b,aaa.b,a.b')
assert match_regex(br'a\.b', b'abc,aaa,aaa,b,aaa.b,a.b')
assert match_regex(r'a\.b', b'abc,aaa,aaa,b,aaa.b,a.b')
assert match_regex(r'\bgoogle\.com\b', b' google.com ')
pass

if __name__ == '__main__':
test_sync_str_bytes()
test_match_regex()
test_inet_conv()
test_parse_header()
test_pack_header()
Expand Down
Empty file modified shadowsocks/logrun.sh
100644 → 100755
Empty file.
Empty file modified shadowsocks/run.sh
100644 → 100755
Empty file.
Empty file modified shadowsocks/stop.sh
100644 → 100755
Empty file.
Empty file modified shadowsocks/tail.sh
100644 → 100755
Empty file.
Empty file modified stop.sh
100644 → 100755
Empty file.
Empty file modified tail.sh
100644 → 100755
Empty file.

0 comments on commit 68d2317

Please sign in to comment.