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 --- 19 unchanged lines hidden (view full) --- 28# Nathan Binkert 29 30##################################################################### 31# 32# Proxy object support. 33# 34##################################################################### 35 |
36import copy 37 |
38class BaseProxy(object): 39 def __init__(self, search_self, search_up): 40 self._search_self = search_self 41 self._search_up = search_up 42 self._multiplier = None 43 44 def __str__(self): 45 if self._search_self and not self._search_up: --- 80 unchanged lines hidden (view full) --- 126 self._modifiers = [] 127 128 def __getattr__(self, attr): 129 # python uses __bases__ internally for inheritance 130 if attr.startswith('_'): 131 return super(AttrProxy, self).__getattr__(self, attr) 132 if hasattr(self, '_pdesc'): 133 raise AttributeError, "Attribute reference on bound proxy" |
134 # Return a copy of self rather than modifying self in place 135 # since self could be an indirect reference via a variable or 136 # parameter 137 new_self = copy.deepcopy(self) 138 new_self._modifiers.append(attr) 139 return new_self |
140 141 # support indexing on proxies (e.g., Self.cpu[0]) 142 def __getitem__(self, key): 143 if not isinstance(key, int): 144 raise TypeError, "Proxy object requires integer index" |
145 if hasattr(self, '_pdesc'): 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) 154 except: 155 return None, False 156 while isproxy(val): 157 val = val.unproxy(obj) --- 58 unchanged lines hidden --- |