1515
1616
1717class Proxy (object ):
18+ """
19+ A temporary object to represent a Container. This gets used when resolving the true location of a
20+ Container's parent.
21+
22+ Proxy objects allow simple bookeeping of all potential parents a Container may have.
23+
24+ This object is used by providing all the necessary information for describing the object. This object
25+ gets passed around and candidates are accumulated. Upon calling resolve, all saved candidates are matched
26+ against the information (provided to the constructor). The candidate that has an exact match is returned.
27+ """
1828
1929 def __init__ (self , manager , source , location , namespace , data_type ):
2030 self .__source = source
@@ -24,24 +34,24 @@ def __init__(self, manager, source, location, namespace, data_type):
2434 self .__manager = manager
2535 self .__candidates = list ()
2636
27- @property
28- def candidates (self ):
29- return self .__candidates
30-
3137 @property
3238 def source (self ):
39+ """The source of the object e.g. file source"""
3340 return self .__source
3441
3542 @property
3643 def location (self ):
44+ """The location of the object. This can be thought of as a unique path"""
3745 return self .__location
3846
3947 @property
4048 def namespace (self ):
49+ """The namespace from which the data_type of this Proxy came from"""
4150 return self .__namespace
4251
4352 @property
4453 def data_type (self ):
54+ """The data_type of Container that should match this Proxy"""
4555 return self .__data_type
4656
4757 @docval ({"name" : "object" , "type" : (BaseBuilder , Container ), "doc" : "the container or builder to get a proxy for" })
@@ -115,8 +125,12 @@ def __get_proxy_container(self, container):
115125 stack = list ()
116126 tmp = container
117127 while tmp is not None :
118- stack .append (tmp .name )
119- tmp = tmp .parent
128+ if isinstance (tmp , Proxy ):
129+ stack .append (tmp .location )
130+ break
131+ else :
132+ stack .append (tmp .name )
133+ tmp = tmp .parent
120134 loc = "/" .join (reversed (stack ))
121135 return Proxy (self , container .container_source , loc , ns , dt )
122136
@@ -523,6 +537,13 @@ def get_attr_value(self, **kwargs):
523537 return None
524538 attr_val = self .__get_override_attr (attr_name , container , manager )
525539 if attr_val is None :
540+ # TODO: A message like this should be used to warn users when an expected attribute
541+ # does not exist on a Container object
542+ #
543+ # if not hasattr(container, attr_name):
544+ # msg = "Container '%s' (%s) does not have attribute '%s'" \
545+ # % (container.name, type(container), attr_name)
546+ # #warnings.warn(msg)
526547 attr_val = getattr (container , attr_name , None )
527548 if attr_val is not None :
528549 attr_val = self .__convert_value (attr_val , spec )
0 commit comments