Registry.lookup does not return weakrefs anymore. resolve_type does it instead

This commit is contained in:
Christophe de Vienne 2012-06-27 17:19:34 +02:00
parent 624a8f6186
commit d1d36e66bc

View File

@ -2,10 +2,12 @@ import base64
import datetime import datetime
import decimal import decimal
import inspect import inspect
import weakref import logging
import six import six
import sys import sys
import weakref
log = logging.getLogger(__name__)
#: The 'str' (python 2) or 'bytes' (python 3) type. #: The 'str' (python 2) or 'bytes' (python 3) type.
#: Its use should be restricted to #: Its use should be restricted to
@ -443,18 +445,19 @@ class Registry(object):
return class_ return class_
def lookup(self, typename): def lookup(self, typename):
log.debug('Lookup %s' % typename)
modname = None modname = None
if '.' in typename: if '.' in typename:
modname, typename = typename.rsplit('.', 1) modname, typename = typename.rsplit('.', 1)
for ct in self.complex_types: for ct in self.complex_types:
ct = ct() ct = ct()
if typename == ct.__name__ and ( if ct is not None and typename == ct.__name__ and (
modname is None or modname == ct.__module__): modname is None or modname == ct.__module__):
return weakref.ref(ct) return ct
def resolve_type(self, type_): def resolve_type(self, type_):
if isinstance(type_, six.string_types): if isinstance(type_, six.string_types):
return self.lookup(type_) return weakref.ref(self.lookup(type_))
if isinstance(type_, list): if isinstance(type_, list):
type_ = ArrayType(type_[0]) type_ = ArrayType(type_[0])
if isinstance(type_, dict): if isinstance(type_, dict):