|
|
@ -144,19 +144,41 @@ class FlaskClient(Client): |
|
|
|
self.cookie_jar.extract_wsgi(c.request.environ, headers) |
|
|
|
self.cookie_jar.extract_wsgi(c.request.environ, headers) |
|
|
|
|
|
|
|
|
|
|
|
def open(self, *args, **kwargs): |
|
|
|
def open(self, *args, **kwargs): |
|
|
|
|
|
|
|
as_tuple = kwargs.pop('as_tuple', False) |
|
|
|
|
|
|
|
buffered = kwargs.pop('buffered', False) |
|
|
|
|
|
|
|
follow_redirects = kwargs.pop('follow_redirects', False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
not kwargs and len(args) == 1 |
|
|
|
|
|
|
|
and isinstance(args[0], (EnvironBuilder, dict)) |
|
|
|
|
|
|
|
): |
|
|
|
|
|
|
|
environ = self.environ_base.copy() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(args[0], EnvironBuilder): |
|
|
|
|
|
|
|
environ.update(args[0].get_environ()) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
environ.update(args[0]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
environ['flask._preserve_context'] = self.preserve_context |
|
|
|
|
|
|
|
else: |
|
|
|
kwargs.setdefault('environ_overrides', {}) \ |
|
|
|
kwargs.setdefault('environ_overrides', {}) \ |
|
|
|
['flask._preserve_context'] = self.preserve_context |
|
|
|
['flask._preserve_context'] = self.preserve_context |
|
|
|
kwargs.setdefault('environ_base', self.environ_base) |
|
|
|
kwargs.setdefault('environ_base', self.environ_base) |
|
|
|
|
|
|
|
builder = make_test_environ_builder( |
|
|
|
|
|
|
|
self.application, *args, **kwargs |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
as_tuple = kwargs.pop('as_tuple', False) |
|
|
|
try: |
|
|
|
buffered = kwargs.pop('buffered', False) |
|
|
|
environ = builder.get_environ() |
|
|
|
follow_redirects = kwargs.pop('follow_redirects', False) |
|
|
|
finally: |
|
|
|
builder = make_test_environ_builder(self.application, *args, **kwargs) |
|
|
|
builder.close() |
|
|
|
|
|
|
|
|
|
|
|
return Client.open(self, builder, |
|
|
|
return Client.open( |
|
|
|
|
|
|
|
self, environ, |
|
|
|
as_tuple=as_tuple, |
|
|
|
as_tuple=as_tuple, |
|
|
|
buffered=buffered, |
|
|
|
buffered=buffered, |
|
|
|
follow_redirects=follow_redirects) |
|
|
|
follow_redirects=follow_redirects |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def __enter__(self): |
|
|
|
def __enter__(self): |
|
|
|
if self.preserve_context: |
|
|
|
if self.preserve_context: |
|
|
|