'''The container for recorded requests and responses'''
+import logging
+
import contextlib2
-import functools
try:
from collections import Counter
except ImportError:
from .errors import UnhandledHTTPRequestError
-class CassetteContextDecorator(object):
+log = logging.getLogger(__name__)
+
+
+class CassetteContextDecorator(contextlib2.ContextDecorator):
"""Context manager/decorator that handles installing the cassette and
removing cassettes.
with contextlib2.ExitStack() as exit_stack:
for patcher in PatcherBuilder(cassette).build_patchers():
exit_stack.enter_context(patcher)
+ log.debug('Entered context for cassette at {0}.'.format(cassette._path))
yield cassette
+ log.debug('Exiting context for cassette at {0}.'.format(cassette._path))
# TODO(@IvanMalison): Hmmm. it kind of feels like this should be somewhere else.
cassette._save()
next(self.__finish, None)
self.__finish = None
- def __call__(self, function):
- @functools.wraps(function)
- def wrapped(*args, **kwargs):
- with self:
- return function(*args, **kwargs)
- return wrapped
-
class Cassette(object):
'''A container for recorded requests and responses'''
return mock.patch.object(obj, patched_attribute, replacement_class)
def _get_cassette_subclass(self, klass):
+ if klass.cassette is not None:
+ return klass
if klass not in self._class_to_cassette_subclass:
- self._class_to_cassette_subclass[klass] = self._cassette_subclass(klass)
+ self._class_to_cassette_subclass[klass] = self._build_cassette_subclass(klass)
return self._class_to_cassette_subclass[klass]
- def _cassette_subclass(self, base_class):
+ def _build_cassette_subclass(self, base_class):
bases = (base_class,)
if not issubclass(base_class, object): # Check for old style class
bases += (object,)
yield cpool, 'CertValidatingHTTPSConnection', VCRCertValidatingHTTPSConnection
-
def reset_patchers():
yield mock.patch.object(httplib, 'HTTPConnection', _HTTPConnection)
yield mock.patch.object(httplib, 'HTTPSConnection', _HTTPSConnection)