Fixing for quote-nazism

This commit is contained in:
László Károlyi 2018-05-10 17:32:01 +02:00
parent 31bb1bcc23
commit 4adcf9080e
No known key found for this signature in database
GPG Key ID: 2DCAF25E55735BFE
3 changed files with 32 additions and 32 deletions

View File

@ -136,23 +136,23 @@ class CommandLineInterface(object):
action="store_true", action="store_true",
) )
self._arg_proxy_host = self.parser.add_argument( self._arg_proxy_host = self.parser.add_argument(
'--proxy-headers-host', "--proxy-headers-host",
dest='proxy_headers_host', dest="proxy_headers_host",
help='Specify which header will be used for getting the host ' help="Specify which header will be used for getting the host "
'part. Can be omitted, requires --proxy-headers to be specified ' "part. Can be omitted, requires --proxy-headers to be specified "
'when passed. \'X-Real-IP\' (when passed by your webserver) is a ' "when passed. \"X-Real-IP\" (when passed by your webserver) is a "
'good candidate for this.', "good candidate for this.",
default=False, default=False,
action='store', action="store",
) )
self._arg_proxy_port = self.parser.add_argument( self._arg_proxy_port = self.parser.add_argument(
'--proxy-headers-port', "--proxy-headers-port",
dest='proxy_headers_port', dest="proxy_headers_port",
help='Specify which header will be used for getting the port ' help="Specify which header will be used for getting the port "
'part. Can be omitted, requires --proxy-headers to be specified ' "part. Can be omitted, requires --proxy-headers to be specified "
'when passed.', "when passed.",
default=False, default=False,
action='store', action="store",
) )
self.parser.add_argument( self.parser.add_argument(
"application", "application",
@ -174,7 +174,7 @@ class CommandLineInterface(object):
return return
raise ArgumentError( raise ArgumentError(
argument=argument, argument=argument,
message='--proxy-headers has to be passed for this parameter.') message="--proxy-headers has to be passed for this parameter.")
def _get_forwarded_host(self, args: Namespace) -> str_or_none: def _get_forwarded_host(self, args: Namespace) -> str_or_none:
""" """
@ -186,7 +186,7 @@ class CommandLineInterface(object):
argument=self._arg_proxy_host, args=args) argument=self._arg_proxy_host, args=args)
return args.proxy_headers_host return args.proxy_headers_host
if args.proxy_headers: if args.proxy_headers:
return 'X-Forwarded-For' return "X-Forwarded-For"
def _get_forwarded_port(self, args: Namespace) -> str_or_none: def _get_forwarded_port(self, args: Namespace) -> str_or_none:
""" """
@ -198,7 +198,7 @@ class CommandLineInterface(object):
argument=self._arg_proxy_port, args=args) argument=self._arg_proxy_port, args=args)
return args.proxy_headers_port return args.proxy_headers_port
if args.proxy_headers: if args.proxy_headers:
return 'X-Forwarded-Port' return "X-Forwarded-Port"
def run(self, args): def run(self, args):
""" """

View File

@ -46,11 +46,11 @@ def parse_x_forwarded_for(headers,
new_headers = dict() new_headers = dict()
for name, values in headers.items(): for name, values in headers.items():
name = name.lower() name = name.lower()
name = name if type(name) is bytes else name.encode('utf-8') name = name if type(name) is bytes else name.encode("utf-8")
new_headers[name] = values new_headers[name] = values
headers = new_headers headers = new_headers
address_header_name = address_header_name.lower().encode('utf-8') address_header_name = address_header_name.lower().encode("utf-8")
result = original result = original
if address_header_name in headers: if address_header_name in headers:
address_value = header_value(headers, address_header_name) address_value = header_value(headers, address_header_name)

View File

@ -243,9 +243,9 @@ class TestCLIInterface(TestCase):
`X-Forwarded-For` header. `X-Forwarded-For` header.
""" """
self.assertCLI( self.assertCLI(
['--proxy-headers'], ["--proxy-headers"],
{ {
'proxy_forwarded_address_header': 'X-Forwarded-For', "proxy_forwarded_address_header": "X-Forwarded-For",
}, },
) )
@ -255,22 +255,22 @@ class TestCLIInterface(TestCase):
the passed one, and `--proxy-headers` is mandatory. the passed one, and `--proxy-headers` is mandatory.
""" """
self.assertCLI( self.assertCLI(
['--proxy-headers', '--proxy-headers-host', 'blah'], ["--proxy-headers", "--proxy-headers-host", "blah"],
{ {
'proxy_forwarded_address_header': 'blah', "proxy_forwarded_address_header": "blah",
}, },
) )
with self.assertRaises(expected_exception=ArgumentError) as exc: with self.assertRaises(expected_exception=ArgumentError) as exc:
self.assertCLI( self.assertCLI(
['--proxy-headers-host', 'blah'], ["--proxy-headers-host", "blah"],
{ {
'proxy_forwarded_address_header': 'blah', "proxy_forwarded_address_header": "blah",
}, },
) )
self.assertEqual(exc.exception.argument_name, '--proxy-headers-host') self.assertEqual(exc.exception.argument_name, "--proxy-headers-host")
self.assertEqual( self.assertEqual(
exc.exception.message, exc.exception.message,
'--proxy-headers has to be passed for this parameter.') "--proxy-headers has to be passed for this parameter.")
def test_custom_proxyport(self): def test_custom_proxyport(self):
""" """
@ -278,19 +278,19 @@ class TestCLIInterface(TestCase):
the passed one, and `--proxy-headers` is mandatory. the passed one, and `--proxy-headers` is mandatory.
""" """
self.assertCLI( self.assertCLI(
['--proxy-headers', '--proxy-headers-port', 'blah2'], ["--proxy-headers", "--proxy-headers-port", "blah2"],
{ {
'proxy_forwarded_port_header': 'blah2', "proxy_forwarded_port_header": "blah2",
}, },
) )
with self.assertRaises(expected_exception=ArgumentError) as exc: with self.assertRaises(expected_exception=ArgumentError) as exc:
self.assertCLI( self.assertCLI(
['--proxy-headers-port', 'blah2'], ["--proxy-headers-port", "blah2"],
{ {
'proxy_forwarded_address_header': 'blah2', "proxy_forwarded_address_header": "blah2",
}, },
) )
self.assertEqual(exc.exception.argument_name, '--proxy-headers-port') self.assertEqual(exc.exception.argument_name, "--proxy-headers-port")
self.assertEqual( self.assertEqual(
exc.exception.message, exc.exception.message,
'--proxy-headers has to be passed for this parameter.') "--proxy-headers has to be passed for this parameter.")