From c7e47cc7e7b27e8c79d7ccb0c0c116ad12baddca Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Fri, 14 Dec 2018 18:44:56 +0530 Subject: [PATCH] Avoid setting open file limits on Windows OS. Python resource module is unavailable on Windows OS. --- README.md | 3 ++- proxy.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c8d4ebe4..468243bb 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,9 @@ Features - Distributed as a single file module - No external dependency other than standard Python library - Support for `http`, `https` and `websockets` request proxy -- Basic authentication support - Optimize for large file uploads and downloads +- IPv4 and IPv6 support +- Basic authentication support Install ------- diff --git a/proxy.py b/proxy.py index d0a16ef4..d18d01db 100755 --- a/proxy.py +++ b/proxy.py @@ -9,6 +9,7 @@ :copyright: (c) 2013-2018 by Abhinav Singh. :license: BSD, see LICENSE for more details. """ +import os import sys import errno import base64 @@ -17,9 +18,11 @@ import select import logging import argparse import datetime -import resource import threading +if os.name != 'nt': + import resource + VERSION = (0, 3) __version__ = '.'.join(map(str, VERSION[0:2])) __description__ = 'HTTP Proxy Server in Python' @@ -43,7 +46,9 @@ else: # pragma: no cover def text_(s, encoding='utf-8', errors='strict'): # pragma: no cover - """ If ``s`` is an instance of ``binary_type``, return + """Utility to ensure text-like usability. + + 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) @@ -51,7 +56,9 @@ def text_(s, encoding='utf-8', errors='strict'): # pragma: no cover def bytes_(s, encoding='utf-8', errors='strict'): # pragma: no cover - """ If ``s`` is an instance of ``text_type``, return + """Utility to ensure binary-like usability. + + If ``s`` is an instance of ``text_type``, return ``s.encode(encoding, errors)``, otherwise return ``s``""" if isinstance(s, text_type): return s.encode(encoding, errors) @@ -668,7 +675,9 @@ def main(): format='%(asctime)s - %(levelname)s - %(funcName)s:%(lineno)d - %(message)s') try: - set_open_file_limit(int(args.open_file_limit)) + # resource module is not available on Windows OS + if os.name != 'nt': + set_open_file_limit(int(args.open_file_limit)) auth_code = None if args.basic_auth: