@@ -3,6 +3,7 @@ ${template_parameters['encoding_tag']}
33<%
44 import build.helper as helper
55 import os
6+ from string import capwords
67
78 grpc_supported = template_parameters[' include_grpc_support' ]
89
@@ -33,7 +34,9 @@ from functools import wraps
3334% if attributes:
3435import ${ module_name} ._attributes as _attributes
3536% endif
37+ % if config[' repeated_capability_object_type' ][' python' ] != ' applicable-attributes-only' :
3638import ${ module_name} ._converters as _converters
39+ % endif
3740import ${ module_name} ._library_interpreter as _library_interpreter
3841import ${ module_name} .enums as enums
3942import ${ module_name} .errors as errors
@@ -92,82 +95,71 @@ class _Lock(object):
9295% endif
9396% if len (config[' repeated_capabilities' ]) > 0 :
9497% if config[' repeated_capability_object_type' ][' python' ] == ' applicable-attributes-only' :
95- % for rep_cap in config[' repeated_capabilities' ]:
98+ class _RepeatedCapabilityAttributeOnlyBase(object):
99+ def __init__(self, session, prefix):
100+ object.__setattr__(self, '_session', session)
101+ object.__setattr__(self, '_prefix', prefix)
102+ object.__setattr__(self, '_repeated_capability', '')
103+
104+ def _get_attribute_vi_real64(self, attribute):
105+ value = self._session._interpreter.get_attribute_vi_real64(self._prefix + self._repeated_capability, attribute)
106+ return value
107+
108+ def _set_attribute_vi_real64(self, attribute, value):
109+ self._session._interpreter.set_attribute_vi_real64(self._prefix + self._repeated_capability, attribute, value)
110+
111+ def _get_attribute_vi_int32(self, attribute):
112+ value = self._session._interpreter.get_attribute_vi_int32(self._prefix + self._repeated_capability, attribute)
113+ return value
114+
115+ def _set_attribute_vi_int32(self, attribute, value):
116+ self._session._interpreter.set_attribute_vi_int32(self._prefix + self._repeated_capability, attribute, value)
96117
97- class _RepeatedCapability${ rep_cap[' python_name' ].capitalize()} (object):
98- % for attribute in helper.sorted_attrs(helper.filter_rep_cap_supported_attributes(attributes, rep_cap[' python_name' ])):
118+ def _get_attribute_vi_string(self, attribute):
119+ value = self._session._interpreter.get_attribute_vi_string(self._prefix + self._repeated_capability, attribute)
120+ return value
121+
122+ def _set_attribute_vi_string(self, attribute, value):
123+ self._session._interpreter.set_attribute_vi_string(self._prefix + self._repeated_capability, attribute, value)
124+
125+
126+ % for rep_cap in config[' repeated_capabilities' ]:
127+ class _RepeatedCapability${ capwords(rep_cap[' python_name' ].replace(' _' , ' ' )).replace(' ' , ' ' )} (_RepeatedCapabilityAttributeOnlyBase):
128+ % for attribute in helper.sorted_attrs(helper.filter_rep_cap_supported_attributes(attributes, rep_cap[' python_name' ])):
99129<%
100130helper.add_attribute_rep_cap_tip(attributes[attribute], config)
101131%> \
102- % if attributes[attribute][' enum' ]:
103- % if helper.enum_uses_converter(enums[attributes[attribute][' enum' ]]):
132+ % if attributes[attribute][' enum' ]:
133+ % if helper.enum_uses_converter(enums[attributes[attribute][' enum' ]]):
104134 ${ attributes[attribute][' python_name' ]} = _attributes.AttributeEnumWithConverter(_attributes.AttributeEnum(_attributes.Attribute${ attributes[attribute][' type' ]} , enums.${ enums[attributes[attribute][' enum' ]][' python_name' ]} , ${ attribute} ), _converters.${ enums[attributes[attribute][' enum' ]][' enum_to_converted_value_function_name' ]} , _converters.${ enums[attributes[attribute][' enum' ]][' converted_value_to_enum_function_name' ]} )
105- % else :
135+ % else :
106136 ${ attributes[attribute][' python_name' ]} = _attributes.AttributeEnum(_attributes.Attribute${ attributes[attribute][' type' ]} , enums.${ enums[attributes[attribute][' enum' ]][' python_name' ]} , ${ attribute} )
107- % endif
108- % else :
137+ % endif
138+ % else :
109139 ${ attributes[attribute][' python_name' ]} = _attributes.${ attributes[attribute][' attribute_class' ]} (${ attribute} )
110- % endif
111- % if ' documentation' in attributes[attribute] and len (helper.get_documentation_for_node_docstring(attributes[attribute], config, indent = 4 ).strip()) > 0 :
140+ % endif
141+ % if ' documentation' in attributes[attribute] and len (helper.get_documentation_for_node_docstring(attributes[attribute], config, indent = 4 ).strip()) > 0 :
112142 '''Type: ${ attributes[attribute][' type_in_documentation' ]}
113143
114144 ${ helper.get_documentation_for_node_docstring(attributes[attribute], config, indent = 4 )}
115145 '''
116- % endif
117- % endfor
118- def __init__(self, session, repeated_capability_list):
119- object.__setattr__(self, '_session', session)
120- object.__setattr__(self, '_repeated_capability_list', repeated_capability_list)
121- object.__setattr__(self, '_prefix', '${ rep_cap[" prefix" ]} ')
122- object.__setattr__(self, '_current_repeated_capability_list', repeated_capability_list if len(repeated_capability_list) > 0 else [''])
123- object.__setattr__(self, '_separator', '')
146+ % endif
147+ % endfor
148+ def __init__(self, session):
149+ super(_RepeatedCapability${ capwords(rep_cap[' python_name' ].replace(' _' , ' ' )).replace(' ' , ' ' )} , self).__init__(session, '${ rep_cap[" prefix" ]} ')
124150
125151 def __setattr__(self, key, value):
126152 if key not in dir(self):
127153 raise AttributeError("'{0}' object has no attribute '{1}'".format(type(self).__name__, key))
128154 object.__setattr__(self, key, value)
129155
130156 def __getitem__(self, repeated_capability):
131- '''Set/get properties or call methods with a repeated capability (i.e. channels)'''
132- rep_caps_list = _converters.convert_repeated_capabilities(repeated_capability, self._prefix)
133- complete_rep_cap_list = [
134- current_rep_cap + self._separator + rep_cap
135- for current_rep_cap in self._current_repeated_capability_list
136- for rep_cap in rep_caps_list
137- ]
138- object.__setattr__(self, '_current_repeated_capability_list', complete_rep_cap_list)
139- self._current_repeated_capability_list = complete_rep_cap_list
140-
157+ super(_RepeatedCapability${ capwords(rep_cap[' python_name' ].replace(' _' , ' ' )).replace(' ' , ' ' )} , self).__setattr__('_repeated_capability', repeated_capability)
141158 return self
142159
143- def _get_attribute_vi_real64(self, attribute):
144- repeated_capability = ','.join(self._current_repeated_capability_list)
145- value = self._session._interpreter.get_attribute_vi_real64(repeated_capability, attribute)
146- return value
147-
148- def _set_attribute_vi_real64(self, attribute, value):
149- repeated_capability = ','.join(self._current_repeated_capability_list)
150- self._session._interpreter.set_attribute_vi_real64(repeated_capability, attribute, value)
151-
152- def _get_attribute_vi_int32(self, attribute):
153- repeated_capability = ','.join(self._current_repeated_capability_list)
154- value = self._session._interpreter.get_attribute_vi_int32(repeated_capability, attribute)
155- return value
156160
157- def _set_attribute_vi_int32(self, attribute, value):
158- repeated_capability = ','.join(self._current_repeated_capability_list)
159- self._session._interpreter.set_attribute_vi_int32(repeated_capability, attribute, value)
160-
161- def _get_attribute_vi_string(self, attribute):
162- repeated_capability = ','.join(self._current_repeated_capability_list)
163- value = self._session._interpreter.get_attribute_vi_string(repeated_capability, attribute)
164- return value
165-
166- def _set_attribute_vi_string(self, attribute, value):
167- repeated_capability = ','.join(self._current_repeated_capability_list)
168- self._session._interpreter.set_attribute_vi_string(repeated_capability, attribute, value)
169- % endfor
170- % else :
161+ % endfor
162+ % else :
171163class _RepeatedCapabilities(object):
172164 def __init__(self, session, prefix, current_repeated_capability_list):
173165 self._session = session
@@ -205,7 +197,7 @@ class _NoChannel(object):
205197 self._session._repeated_capability = self._repeated_capability_cache
206198
207199
208- % endif
200+ % endif
209201% endif
210202class _SessionBase(object):
211203 '''Base class for all ${ config[' driver_name' ]} sessions.'''
@@ -214,12 +206,8 @@ class _SessionBase(object):
214206 _is_frozen = False
215207
216208% for attribute in helper.sorted_attrs(helper.filter_codegen_attributes(attributes)):
209+ % if not (' supported_rep_caps' in attributes[attribute] and len (attributes[attribute][' supported_rep_caps' ]) > 0 and config[' repeated_capability_object_type' ][' python' ] == ' applicable-attributes-only' ):
217210<%
218- # Skip attributes with repeated capability expansion set to "applicable-attributes-only"
219- if ' repeated_capability_type' in attributes[attribute]:
220- rep_cap_type = attributes[attribute][' repeated_capability_type' ]
221- if any (rep_cap.get(' python_name' ) == rep_cap_type and config[' repeated_capability_object_type' ] == ' applicable-attributes-only' for rep_cap in config[' repeated_capabilities' ]):
222- continue
223211helper.add_attribute_rep_cap_tip(attributes[attribute], config)
224212%> \
225213 % if attributes[attribute][' enum' ]:
@@ -237,6 +225,7 @@ helper.add_attribute_rep_cap_tip(attributes[attribute], config)
237225 ${ helper.get_documentation_for_node_docstring(attributes[attribute], config, indent = 4 )}
238226 '''
239227% endif
228+ % endif
240229% endfor
241230<%
242231init_function = config[' functions' ][' _init_function' ]
@@ -263,7 +252,7 @@ constructor_params = helper.filter_parameters(init_function['parameters'], helpe
263252 # Instantiate any repeated capability objects
264253% for rep_cap in config[' repeated_capabilities' ]:
265254% if config[' repeated_capability_object_type' ][' python' ] == ' applicable-attributes-only' :
266- self.${ rep_cap[' python_name' ]} = _RepeatedCapability${ rep_cap[' python_name' ].capitalize() } (self, repeated_capability_list )
255+ self.${ rep_cap[' python_name' ]} = _RepeatedCapability${ capwords( rep_cap[' python_name' ].replace( ' _ ' , ' ' )).replace( ' ' , ' ' ) } (self )
267256% else :
268257 self.${ rep_cap[' python_name' ]} = _RepeatedCapabilities(self, '${ rep_cap[" prefix" ]} ', repeated_capability_list)
269258% endif
0 commit comments