forked from ni/nimi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_attributes.py
More file actions
167 lines (106 loc) · 6.03 KB
/
_attributes.py
File metadata and controls
167 lines (106 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# -*- coding: utf-8 -*-
# This file was generated
import nifake._converters as _converters
import nifake.errors as errors
import hightime
class Attribute(object):
'''Base class for all typed attributes.'''
def __init__(self, attribute_id):
self._attribute_id = attribute_id
class AttributeViInt32(Attribute):
def __get__(self, session, session_type):
return session._get_attribute_vi_int32(self._attribute_id)
def __set__(self, session, value):
session._set_attribute_vi_int32(self._attribute_id, value)
class AttributeViInt32TimeDeltaMilliseconds(Attribute):
def __get__(self, session, session_type):
return hightime.timedelta(milliseconds=session._get_attribute_vi_int32(self._attribute_id))
def __set__(self, session, value):
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_milliseconds_int32(value))
class AttributeViInt32TimeDeltaMonths(Attribute):
def __get__(self, session, session_type):
return _converters.convert_month_to_timedelta(session._get_attribute_vi_int32(self._attribute_id))
def __set__(self, session, value):
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_months_int32(value))
class AttributeViInt64(Attribute):
def __get__(self, session, session_type):
return session._get_attribute_vi_int64(self._attribute_id)
def __set__(self, session, value):
session._set_attribute_vi_int64(self._attribute_id, value)
class AttributeViReal64(Attribute):
def __get__(self, session, session_type):
return session._get_attribute_vi_real64(self._attribute_id)
def __set__(self, session, value):
session._set_attribute_vi_real64(self._attribute_id, value)
class AttributeViReal64TimeDeltaSeconds(Attribute):
def __get__(self, session, session_type):
return hightime.timedelta(seconds=session._get_attribute_vi_real64(self._attribute_id))
def __set__(self, session, value):
session._set_attribute_vi_real64(self._attribute_id, _converters.convert_timedelta_to_seconds_real64(value))
class AttributeViString(Attribute):
def __get__(self, session, session_type):
return session._get_attribute_vi_string(self._attribute_id)
def __set__(self, session, value):
session._set_attribute_vi_string(self._attribute_id, value)
class AttributeViStringRepeatedCapability(Attribute):
def __get__(self, session, session_type):
return session._get_attribute_vi_string(self._attribute_id)
def __set__(self, session, value):
session._set_attribute_vi_string(self._attribute_id, _converters.convert_repeated_capabilities_without_prefix(value))
class AttributeViStringCommaSeparated(Attribute):
def __get__(self, session, session_type):
return _converters.convert_comma_separated_string_to_list(session._get_attribute_vi_string(self._attribute_id))
def __set__(self, session, value):
session._set_attribute_vi_string(self._attribute_id, _converters.convert_list_to_comma_separated_string(value))
class AttributeViBoolean(Attribute):
def __get__(self, session, session_type):
return session._get_attribute_vi_boolean(self._attribute_id)
def __set__(self, session, value):
session._set_attribute_vi_boolean(self._attribute_id, value)
class AttributeEnum(Attribute):
def __init__(self, underlying_attribute_meta_class, enum_meta_class, attribute_id):
super(AttributeEnum, self).__init__(attribute_id)
self._underlying_attribute = underlying_attribute_meta_class(attribute_id)
self._attribute_type = enum_meta_class
def __get__(self, session, session_type):
return self._attribute_type(self._underlying_attribute.__get__(session, session_type))
def __set__(self, session, value):
if type(value) is not self._attribute_type:
raise TypeError('must be ' + str(self._attribute_type.__name__) + ' not ' + str(type(value).__name__))
return self._underlying_attribute.__set__(session, value.value)
class AttributeEnumWithConverter(Attribute):
'''Class for attributes that use enums internally but are exposed in the nifake Python module as something else, thus need conversion.'''
def __init__(self, underlying_attribute_enum, getter_converter, setter_converter):
'''Creates and returns an instance of AttributeEnumWithConverter attribute meta class.
Args:
underlying_attribute_enum (AttributeEnum): The AttributeEnum instance for the underlying
enum
getter_converter (function): The function that converts the enum value to its converted
value
setter_converter (function): The function that converts the converted value back to the
enum value
'''
super(AttributeEnumWithConverter, self).__init__(underlying_attribute_enum._attribute_id)
self._underlying_attribute_enum = underlying_attribute_enum
self._getter_converter = getter_converter
self._setter_converter = setter_converter
def __get__(self, session, session_type):
try:
return self._getter_converter(
self._underlying_attribute_enum.__get__(session, session_type)
)
except (KeyError, ValueError):
raise errors.DriverTooNewError()
def __set__(self, session, value):
try:
return self._underlying_attribute_enum.__set__(session, self._setter_converter(value))
except KeyError:
raise ValueError(f'Invalid value: {value}')
# nitclk specific attribute type
class AttributeSessionReference(Attribute):
def __get__(self, session, session_type):
# Import here to avoid a circular dependency when initial import happens
from nifake.session import SessionReference
return SessionReference(session._get_attribute_vi_session(self._attribute_id))
def __set__(self, session, value):
session._set_attribute_vi_session(self._attribute_id, _converters.convert_to_nitclk_session_number(value))