Merge "Move InputProxy to utils"
This commit is contained in:
commit
0d6fb2e0c2
swift/common
@ -42,47 +42,8 @@ from urllib import quote, unquote
|
||||
|
||||
from swift.common.swob import Request
|
||||
from swift.common.utils import (get_logger, get_remote_client,
|
||||
get_valid_utf8_str, config_true_value)
|
||||
|
||||
|
||||
class InputProxy(object):
|
||||
"""
|
||||
File-like object that counts bytes read.
|
||||
To be swapped in for wsgi.input for accounting purposes.
|
||||
"""
|
||||
def __init__(self, wsgi_input):
|
||||
"""
|
||||
:param wsgi_input: file-like object to wrap the functionality of
|
||||
"""
|
||||
self.wsgi_input = wsgi_input
|
||||
self.bytes_received = 0
|
||||
self.client_disconnect = False
|
||||
|
||||
def read(self, *args, **kwargs):
|
||||
"""
|
||||
Pass read request to the underlying file-like object and
|
||||
add bytes read to total.
|
||||
"""
|
||||
try:
|
||||
chunk = self.wsgi_input.read(*args, **kwargs)
|
||||
except Exception:
|
||||
self.client_disconnect = True
|
||||
raise
|
||||
self.bytes_received += len(chunk)
|
||||
return chunk
|
||||
|
||||
def readline(self, *args, **kwargs):
|
||||
"""
|
||||
Pass readline request to the underlying file-like object and
|
||||
add bytes read to total.
|
||||
"""
|
||||
try:
|
||||
line = self.wsgi_input.readline(*args, **kwargs)
|
||||
except Exception:
|
||||
self.client_disconnect = True
|
||||
raise
|
||||
self.bytes_received += len(line)
|
||||
return line
|
||||
get_valid_utf8_str, config_true_value,
|
||||
InputProxy)
|
||||
|
||||
|
||||
class ProxyLoggingMiddleware(object):
|
||||
|
@ -1525,3 +1525,43 @@ def reiterate(iterable):
|
||||
return itertools.chain([chunk], iterable)
|
||||
except StopIteration:
|
||||
return []
|
||||
|
||||
|
||||
class InputProxy(object):
|
||||
"""
|
||||
File-like object that counts bytes read.
|
||||
To be swapped in for wsgi.input for accounting purposes.
|
||||
"""
|
||||
def __init__(self, wsgi_input):
|
||||
"""
|
||||
:param wsgi_input: file-like object to wrap the functionality of
|
||||
"""
|
||||
self.wsgi_input = wsgi_input
|
||||
self.bytes_received = 0
|
||||
self.client_disconnect = False
|
||||
|
||||
def read(self, *args, **kwargs):
|
||||
"""
|
||||
Pass read request to the underlying file-like object and
|
||||
add bytes read to total.
|
||||
"""
|
||||
try:
|
||||
chunk = self.wsgi_input.read(*args, **kwargs)
|
||||
except Exception:
|
||||
self.client_disconnect = True
|
||||
raise
|
||||
self.bytes_received += len(chunk)
|
||||
return chunk
|
||||
|
||||
def readline(self, *args, **kwargs):
|
||||
"""
|
||||
Pass readline request to the underlying file-like object and
|
||||
add bytes read to total.
|
||||
"""
|
||||
try:
|
||||
line = self.wsgi_input.readline(*args, **kwargs)
|
||||
except Exception:
|
||||
self.client_disconnect = True
|
||||
raise
|
||||
self.bytes_received += len(line)
|
||||
return line
|
||||
|
Loading…
Reference in New Issue
Block a user