From 211892aebffb19d9505d3602ac407d8c0ae70fa0 Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Sat, 25 May 2019 07:59:45 +0300 Subject: [PATCH] travis: fix style --- pupy/modules/http.py | 5 ++--- pupy/modules/netcreds.py | 2 ++ pupy/network/lib/socks.py | 11 +++++++++- pupy/network/lib/tinyhttp.py | 40 ++++++++++++++++++------------------ 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/pupy/modules/http.py b/pupy/modules/http.py index 6c9fd26c..1ade0a78 100644 --- a/pupy/modules/http.py +++ b/pupy/modules/http.py @@ -98,16 +98,15 @@ class http(PupyModule): self.log(result) except Exception, e: - raise if hasattr(e, 'reason'): message = '{} {} ({})'.format(e.code, e.reason, e.filename) if e.code / 100 < 4: self.warning(message) else: self.error(message) - + return - + elif hasattr(e, 'msg'): message = e.msg else: diff --git a/pupy/modules/netcreds.py b/pupy/modules/netcreds.py index 32b71713..1b5069f5 100644 --- a/pupy/modules/netcreds.py +++ b/pupy/modules/netcreds.py @@ -3,6 +3,8 @@ from pupylib.PupyModule import config, PupyModule, PupyArgumentParser from pupylib.PupyOutput import Table + +@config(cat='creds') class NetCreds(PupyModule): ''' Manage saved authentication information ''' diff --git a/pupy/network/lib/socks.py b/pupy/network/lib/socks.py index 9c5658f7..0ea01424 100644 --- a/pupy/network/lib/socks.py +++ b/pupy/network/lib/socks.py @@ -112,32 +112,41 @@ class ProxyError(IOError): def __str__(self): return self.msg + class GeneralProxyError(ProxyError): pass + class ProxyConnectionError(ProxyError): pass + class SOCKS5AuthError(ProxyError): pass + class SOCKS5Error(ProxyError): pass + class SOCKS4Error(ProxyError): pass + class HTTPError(ProxyError): pass + class AuthenticationRequired(ProxyError): __slots__ = ('methods',) + def __init__(self, methods): super(AuthenticationRequired, self).__init__( 'Authentication required, supported methods: {}'.format( ';'.join(methods))) self.methods = methods + class AuthenticationImpossible(EOFError): pass @@ -1131,7 +1140,7 @@ class socksocket(_BaseSocket): try: self._connect(self, dest_pair) break - except AuthenticationRequired as e: + except AuthenticationRequired: _orig_socket.__init__( self, *self._orig_args, **self._orig_kwargs) diff --git a/pupy/network/lib/tinyhttp.py b/pupy/network/lib/tinyhttp.py index c03bb059..205ba1e4 100644 --- a/pupy/network/lib/tinyhttp.py +++ b/pupy/network/lib/tinyhttp.py @@ -95,7 +95,7 @@ class ProxyPasswordManager(object): class HTTPContext(urllib2.BaseHandler): default = None - + __slots__ = ('cookies', 'headers') handler_order = 999 @@ -106,11 +106,11 @@ class HTTPContext(urllib2.BaseHandler): HTTPContext.default = HTTPContext() return HTTPContext.default - + def __init__(self): self.cookies = cookielib.CookieJar() self.headers = {} - + def http_request(self, request): self.cookies.add_cookie_header(request) host = request.get_host() @@ -123,7 +123,7 @@ class HTTPContext(urllib2.BaseHandler): def http_response(self, request, response): self.cookies.extract_cookies(response, request) - + host = request.get_host() headers = request.headers code = response.headers @@ -150,12 +150,12 @@ class HTTPContext(urllib2.BaseHandler): if host not in self.headers: self.headers[host] = {} - self.headers[host][header] = request.get_headers(header) + self.headers[host][header] = headers.get(header) https_request = http_request - https_response = http_response + https_response = http_response + - class NoRedirects(urllib2.HTTPErrorProcessor): __slots__ = () @@ -532,7 +532,7 @@ class HTTP(object): password_managers.append(http_password_manager) context = HTTPContext.get_default() - + handlers.append(context) handlers.append(urllib2.HTTPDefaultErrorHandler) @@ -561,10 +561,10 @@ class HTTP(object): opener, scheme, host, password_managers, context = self.make_opener(url) result = [] - + try: response = opener.open(url, timeout=self.timeout) - + except ProxyConnectionError as e: if self.proxy == 'wpad': set_proxy_unavailable(scheme, host) @@ -573,21 +573,21 @@ class HTTP(object): except urllib2.HTTPError as e: context.update_from_error(e) - + if not return_headers: raise - + result = [e.fp.read() if e.fp.read else ''] - + if return_url: result.append(e.url) - + if code: result.append(e.code) - + if return_headers: result.append(e.hdrs.dict) - + if len(result) == 1: return result[0] else: @@ -668,16 +668,16 @@ class HTTP(object): raise result = [e.fp.read() if e.fp.read else ''] - + if return_url: result.append(e.url) - + if code: result.append(e.code) - + if return_headers: result.append(e.hdrs.dict) - + if len(result) == 1: return result[0] else: