diff --git a/.gitignore b/.gitignore index 3b3baaa6..457cab9f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .pydevproject .settings *.pyc +venv cover dist proxy.py.egg-info diff --git a/Makefile b/Makefile index 422ea38b..7599b073 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all clean package test +.PHONY: all clean test package release all: clean test diff --git a/proxy.py b/proxy.py index ae7baa91..36de7d42 100755 --- a/proxy.py +++ b/proxy.py @@ -29,28 +29,28 @@ __license__ = 'BSD' logger = logging.getLogger(__name__) # True if we are running on Python 3. -if sys.version_info[0] == 3: +if sys.version_info[0] == 3: # pragma: no cover text_type = str binary_type = bytes from urllib import parse as urlparse -else: +else: # pragma: no cover text_type = unicode binary_type = str import urlparse -def text_(s, encoding='utf-8', errors='strict'): +def text_(s, encoding='utf-8', errors='strict'): # pragma: no cover """ If ``s`` is an instance of ``binary_type``, return ``s.decode(encoding, errors)``, otherwise return ``s``""" if isinstance(s, binary_type): return s.decode(encoding, errors) - return s # pragma: no cover + return s -def bytes_(s, encoding='utf-8', errors='strict'): +def bytes_(s, encoding='utf-8', errors='strict'): # pragma: no cover """ If ``s`` is an instance of ``text_type``, return ``s.encode(encoding, errors)``, otherwise return ``s``""" - if isinstance(s, text_type): # pragma: no cover + if isinstance(s, text_type): return s.encode(encoding, errors) return s @@ -314,6 +314,10 @@ class Server(Connection): super(Server, self).__init__(b'server') self.addr = (host, int(port)) + def __del__(self): + if self.conn: + self.close() + def connect(self): self.conn = socket.create_connection((self.addr[0], self.addr[1])) diff --git a/tests.py b/tests.py index d570b612..57d9bb8f 100644 --- a/tests.py +++ b/tests.py @@ -211,15 +211,15 @@ class TestHttpParser(unittest.TestCase): b'
\n' + b'