Skip to content

Commit 9872c11

Browse files
authored
Yet another refactor (#135)
1 parent a49f071 commit 9872c11

File tree

4 files changed

+8
-30
lines changed

4 files changed

+8
-30
lines changed

Pipfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ twine = "*"
2424
anaconda-client = "*"
2525
pipfile = "*"
2626
wheel = "*"
27+
xxhash = "*"
28+
aiohttp = "*"
29+
async-timeout = "*"
2730

2831
[requires]
2932
python_version = "3.8"

mocket/compat.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,20 @@
22
import os
33
import shlex
44

5-
encoding = os.getenv("MOCKET_ENCODING", "utf-8")
5+
ENCODING = os.getenv("MOCKET_ENCODING", "utf-8")
66

77
text_type = str
88
byte_type = bytes
99
basestring = (str,)
1010

11-
FileNotFoundError = FileNotFoundError
12-
BlockingIOError = BlockingIOError
1311

14-
try:
15-
from json.decoder import JSONDecodeError
16-
except ImportError:
17-
JSONDecodeError = ValueError
18-
19-
20-
def encode_to_bytes(s, encoding=encoding):
12+
def encode_to_bytes(s, encoding=ENCODING):
2113
if isinstance(s, text_type):
2214
s = s.encode(encoding)
2315
return byte_type(s)
2416

2517

26-
def decode_from_bytes(s, encoding=encoding):
18+
def decode_from_bytes(s, encoding=ENCODING):
2719
if isinstance(s, byte_type):
2820
s = codecs.decode(s, encoding, "ignore")
2921
return text_type(s)

mocket/mocket.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
import socket
1010
import ssl
1111
from datetime import datetime, timedelta
12+
from json.decoder import JSONDecodeError
1213

1314
import decorator
1415
import urllib3
1516
from urllib3.util.ssl_ import ssl_wrap_socket as urllib3_ssl_wrap_socket
1617
from urllib3.util.ssl_ import wrap_socket as urllib3_wrap_socket
1718

1819
from .compat import (
19-
BlockingIOError,
20-
FileNotFoundError,
21-
JSONDecodeError,
2220
basestring,
2321
byte_type,
2422
decode_from_bytes,

run_tests.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
import os
32
import sys
43

54

@@ -11,24 +10,10 @@ def main(args=None):
1110

1211
major, minor = sys.version_info[:2]
1312

14-
python35 = False
15-
16-
extras = ["xxhash"]
17-
18-
# aiohttp available on Python >=3.5
19-
if major == 3 and minor >= 5:
20-
python35 = True
21-
22-
extras += ["aiohttp", "async_timeout"]
23-
24-
os.system("pipenv run pip install {}".format(" ".join(extras)))
25-
2613
if not any(a for a in args[1:] if not a.startswith("-")):
2714
args.append("tests/main")
2815
args.append("mocket")
29-
30-
if python35:
31-
args.append("tests/tests35")
16+
args.append("tests/tests35")
3217

3318
if major == 3 and minor >= 8:
3419
args.append("tests/tests38")

0 commit comments

Comments
 (0)