Avoid setting open file limits on Windows OS.
Python resource module is unavailable on Windows OS.
This commit is contained in:
parent
83b86426b3
commit
c7e47cc7e7
|
@ -9,8 +9,9 @@ Features
|
||||||
- Distributed as a single file module
|
- Distributed as a single file module
|
||||||
- No external dependency other than standard Python library
|
- No external dependency other than standard Python library
|
||||||
- Support for `http`, `https` and `websockets` request proxy
|
- Support for `http`, `https` and `websockets` request proxy
|
||||||
- Basic authentication support
|
|
||||||
- Optimize for large file uploads and downloads
|
- Optimize for large file uploads and downloads
|
||||||
|
- IPv4 and IPv6 support
|
||||||
|
- Basic authentication support
|
||||||
|
|
||||||
Install
|
Install
|
||||||
-------
|
-------
|
||||||
|
|
15
proxy.py
15
proxy.py
|
@ -9,6 +9,7 @@
|
||||||
:copyright: (c) 2013-2018 by Abhinav Singh.
|
:copyright: (c) 2013-2018 by Abhinav Singh.
|
||||||
:license: BSD, see LICENSE for more details.
|
:license: BSD, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import errno
|
import errno
|
||||||
import base64
|
import base64
|
||||||
|
@ -17,9 +18,11 @@ import select
|
||||||
import logging
|
import logging
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import resource
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
if os.name != 'nt':
|
||||||
|
import resource
|
||||||
|
|
||||||
VERSION = (0, 3)
|
VERSION = (0, 3)
|
||||||
__version__ = '.'.join(map(str, VERSION[0:2]))
|
__version__ = '.'.join(map(str, VERSION[0:2]))
|
||||||
__description__ = 'HTTP Proxy Server in Python'
|
__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
|
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``"""
|
``s.decode(encoding, errors)``, otherwise return ``s``"""
|
||||||
if isinstance(s, binary_type):
|
if isinstance(s, binary_type):
|
||||||
return s.decode(encoding, errors)
|
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
|
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``"""
|
``s.encode(encoding, errors)``, otherwise return ``s``"""
|
||||||
if isinstance(s, text_type):
|
if isinstance(s, text_type):
|
||||||
return s.encode(encoding, errors)
|
return s.encode(encoding, errors)
|
||||||
|
@ -668,6 +675,8 @@ def main():
|
||||||
format='%(asctime)s - %(levelname)s - %(funcName)s:%(lineno)d - %(message)s')
|
format='%(asctime)s - %(levelname)s - %(funcName)s:%(lineno)d - %(message)s')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# resource module is not available on Windows OS
|
||||||
|
if os.name != 'nt':
|
||||||
set_open_file_limit(int(args.open_file_limit))
|
set_open_file_limit(int(args.open_file_limit))
|
||||||
|
|
||||||
auth_code = None
|
auth_code = None
|
||||||
|
|
Loading…
Reference in New Issue