A method on the wrapped PyMongo object that does no I/O and can be called synchronously
| 212 | |
| 213 | |
| 214 | class DelegateMethod(ReadOnlyProperty): |
| 215 | """A method on the wrapped PyMongo object that does no I/O and can be called |
| 216 | synchronously""" |
| 217 | |
| 218 | def __init__(self, doc=None): |
| 219 | ReadOnlyProperty.__init__(self, doc) |
| 220 | self.wrap_class = None |
| 221 | |
| 222 | def wrap(self, original_class): |
| 223 | self.wrap_class = original_class |
| 224 | return self |
| 225 | |
| 226 | def create_attribute(self, cls, attr_name): |
| 227 | if self.wrap_class is None: |
| 228 | return ReadOnlyProperty.create_attribute(self, cls, attr_name) |
| 229 | |
| 230 | method = getattr(cls.__delegate_class__, attr_name) |
| 231 | original_class = self.wrap_class |
| 232 | |
| 233 | @functools.wraps(method) |
| 234 | def wrapper(self_, *args, **kwargs): |
| 235 | result = method(self_.delegate, *args, **kwargs) |
| 236 | |
| 237 | # Don't call isinstance(), not checking subclasses. |
| 238 | if result.__class__ == original_class: |
| 239 | # Delegate to the current object to wrap the result. |
| 240 | return self_.wrap(result) |
| 241 | else: |
| 242 | return result |
| 243 | |
| 244 | if self.doc: |
| 245 | wrapper.__doc__ = self.doc |
| 246 | |
| 247 | wrapper.is_wrap_method = True # For Synchro. |
| 248 | return wrapper |
| 249 | |
| 250 | |
| 251 | class MotorCursorChainingMethod(MotorAttributeFactory): |
no outgoing calls
no test coverage detected
searching dependent graphs…