proxy.py (3109:c3956807347f) proxy.py (3179:c86dfc93984b)
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
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
36class BaseProxy(object):
37 def __init__(self, search_self, search_up):
38 self._search_self = search_self
39 self._search_up = search_up
40 self._multiplier = None
41
42 def __str__(self):
43 if self._search_self and not self._search_up:

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

124 self._modifiers = []
125
126 def __getattr__(self, attr):
127 # python uses __bases__ internally for inheritance
128 if attr.startswith('_'):
129 return super(AttrProxy, self).__getattr__(self, attr)
130 if hasattr(self, '_pdesc'):
131 raise AttributeError, "Attribute reference on bound proxy"
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"
132 self._modifiers.append(attr)
133 return self
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
134
135 # support indexing on proxies (e.g., Self.cpu[0])
136 def __getitem__(self, key):
137 if not isinstance(key, int):
138 raise TypeError, "Proxy object requires integer index"
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"
139 self._modifiers.append(key)
140 return self
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
141
142 def find(self, obj):
143 try:
144 val = getattr(obj, self._attr)
145 except:
146 return None, False
147 while isproxy(val):
148 val = val.unproxy(obj)

--- 58 unchanged lines hidden ---
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 ---