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

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

179
180class AnyProxy(BaseProxy):
181 def find(self, obj):
182 return obj.find_any(self._pdesc.ptype)
183
184 def path(self):
185 return 'any'
186
187class AllProxy(BaseProxy):
188 def find(self, obj):
189 return obj.find_all(self._pdesc.ptype)
190
191 def path(self):
192 return 'all'
193
194def isproxy(obj):
195 if isinstance(obj, (BaseProxy, params.EthernetAddr)):
196 return True
197 elif isinstance(obj, (list, tuple)):
198 for v in obj:
199 if isproxy(v):
200 return True
201 return False
202
203class ProxyFactory(object):
204 def __init__(self, search_self, search_up):
205 self.search_self = search_self
206 self.search_up = search_up
207
208 def __getattr__(self, attr):
209 if attr == 'any':
210 return AnyProxy(self.search_self, self.search_up)
211 elif attr == 'all':
212 if self.search_up:
213 assert("Parant.all is not supported")
214 return AllProxy(self.search_self, self.search_up)
215 else:
216 return AttrProxy(self.search_self, self.search_up, attr)
217
218# global objects for handling proxies
219Parent = ProxyFactory(search_self = False, search_up = True)
220Self = ProxyFactory(search_self = True, search_up = False)
221
222# limit exports on 'from proxy import *'
223__all__ = ['Parent', 'Self']
224
225# see comment on imports at end of __init__.py.
226import params # for EthernetAddr