proxy.py (3179:c86dfc93984b) proxy.py (8459:b8c3c20d0385)
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
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
187def isproxy(obj):
188 if isinstance(obj, (BaseProxy, params.EthernetAddr)):
189 return True
190 elif isinstance(obj, (list, tuple)):
191 for v in obj:
192 if isproxy(v):
193 return True
194 return False
195
196class ProxyFactory(object):
197 def __init__(self, search_self, search_up):
198 self.search_self = search_self
199 self.search_up = search_up
200
201 def __getattr__(self, attr):
202 if attr == 'any':
203 return AnyProxy(self.search_self, self.search_up)
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)
204 else:
205 return AttrProxy(self.search_self, self.search_up, attr)
206
207# global objects for handling proxies
208Parent = ProxyFactory(search_self = False, search_up = True)
209Self = ProxyFactory(search_self = True, search_up = False)
210
211# limit exports on 'from proxy import *'
212__all__ = ['Parent', 'Self']
213
214# see comment on imports at end of __init__.py.
215import params # for EthernetAddr
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