proxy.py (9280:fda147c035b3) proxy.py (10195:7d4d0cd3f7e5)
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 68 unchanged lines hidden (view full) ---

77 def unproxy(self, base):
78 obj = base
79 done = False
80
81 if self._search_self:
82 result, done = self.find(obj)
83
84 if self._search_up:
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 68 unchanged lines hidden (view full) ---

77 def unproxy(self, base):
78 obj = base
79 done = False
80
81 if self._search_self:
82 result, done = self.find(obj)
83
84 if self._search_up:
85 # Search up the tree but mark ourself
86 # as visited to avoid a self-reference
87 self._visited = True
88 obj._visited = True
85 while not done:
86 obj = obj._parent
87 if not obj:
88 break
89 result, done = self.find(obj)
90
89 while not done:
90 obj = obj._parent
91 if not obj:
92 break
93 result, done = self.find(obj)
94
95 self._visited = False
96 base._visited = False
97
91 if not done:
92 raise AttributeError, \
93 "Can't resolve proxy '%s' of type '%s' from '%s'" % \
94 (self.path(), self._pdesc.ptype_str, base.path())
95
96 if isinstance(result, BaseProxy):
97 if result == self:
98 raise RuntimeError, "Cycle in unproxy"

--- 47 unchanged lines hidden (view full) ---

146 raise AttributeError, "Index operation on bound proxy"
147 new_self = copy.deepcopy(self)
148 new_self._modifiers.append(key)
149 return new_self
150
151 def find(self, obj):
152 try:
153 val = getattr(obj, self._attr)
98 if not done:
99 raise AttributeError, \
100 "Can't resolve proxy '%s' of type '%s' from '%s'" % \
101 (self.path(), self._pdesc.ptype_str, base.path())
102
103 if isinstance(result, BaseProxy):
104 if result == self:
105 raise RuntimeError, "Cycle in unproxy"

--- 47 unchanged lines hidden (view full) ---

153 raise AttributeError, "Index operation on bound proxy"
154 new_self = copy.deepcopy(self)
155 new_self._modifiers.append(key)
156 return new_self
157
158 def find(self, obj):
159 try:
160 val = getattr(obj, self._attr)
154 # for any additional unproxying to be done, pass the
155 # current, rather than the original object so that proxy
156 # has the right context
157 obj = val
161 visited = False
162 if hasattr(val, '_visited'):
163 visited = getattr(val, '_visited')
164
165 if not visited:
166 # for any additional unproxying to be done, pass the
167 # current, rather than the original object so that proxy
168 # has the right context
169 obj = val
170 else:
171 return None, False
158 except:
159 return None, False
160 while isproxy(val):
161 val = val.unproxy(obj)
162 for m in self._modifiers:
163 if isinstance(m, str):
164 val = getattr(val, m)
165 elif isinstance(m, int):

--- 67 unchanged lines hidden ---
172 except:
173 return None, False
174 while isproxy(val):
175 val = val.unproxy(obj)
176 for m in self._modifiers:
177 if isinstance(m, str):
178 val = getattr(val, m)
179 elif isinstance(m, int):

--- 67 unchanged lines hidden ---