Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raise InvalidBinaryFormat
if fmt & 0x04 == big_endian:
endianess = ">"
else:
endianess = "<"
try:
if fmt & 0x03 == single:
result = list(struct.unpack((endianess +
str(data_length // 4) + "f").encode('ascii'), data))
elif fmt & 0x03 == double:
result = list(struct.unpack(endianess +
str(data_length // 8) + "d", data))
else:
raise ValueError("unknown data values fmt requested")
except struct.error:
raise InvalidBinaryFormat("binary data itself was malformed")
return result
def _test_devices_timeouts(self, resource_name):
inst = self.rm.open_resource(resource_name, timeout=0.1)
self.assertRaises(VisaIOError, inst.read)
def setUp(self):
self._test_handler = None
if self.CHECK_NO_WARNING:
self._test_handler = th = TestHandler()
th.setLevel(logging.WARNING)
logger.addHandler(th)
def test_InvalidBinaryFormat(self):
self._test_pickle_unpickle(errors.InvalidBinaryFormat())
def test_ieee_integer(self):
values = list(range(99))
containers = (list, tuple) #+ ((np.asarray,) if np else ())
for fmt in 'bBhHiIfd':
for endi in (True, False):
for cont in containers:
conv = cont(values)
msg = 'fmt=%s, endianness=%s, container=%s' % (fmt, endi, cont.__name__)
try:
block = util.to_ieee_block(conv, fmt, endi)
parsed = util.from_ieee_block(block, fmt, endi, cont)
except Exception as e:
raise Exception(msg + '\n' + repr(e))
self.assertEqual(conv, parsed, msg)
:param resources: iterable of resources.
:param query: query expression.
"""
if '{' in query:
query, _ = query.split('{')
logger.warning('optional part of the query expression not supported. '
'See filter2')
try:
query = query.replace('?', '.')
matcher = re.compile(query, re.IGNORECASE)
except re.error:
raise errors.VisaIOError(constants.VI_ERROR_INV_EXPR)
return tuple(res for res in resources if matcher.match(res))
It accepts the optional part of the expression.
.. warning: This function is experimental and unsafe as it uses eval,
It also might require to open the resource.
:param resources: iterable of resources.
:param query: query expression.
:param open_resource: function to open the resource.
"""
if '{' in query:
try:
query, optional = query.split('{')
optional, _ = optional.split('}')
except ValueError:
raise errors.VisaIOError(constants.VI_ERROR_INV_EXPR)
else:
optional = None
filtered = filter(resources, query)
if not optional:
return filtered
optional = optional.replace('&&', 'and').replace('||', 'or').replace('!', 'not ')
optional = optional.replace('VI_', 'res.VI_')
class AttrGetter():
def __init__(self, resource_name):
self.resource_name = resource_name
self.parsed = parse_resource_name(resource_name)
def _init(self):
try:
lib = Library(self.library_path)
except OSError as exc:
raise errors.LibraryError.from_exception(exc, self.library_path)
self.lib = lib
# Set the argtypes, restype and errcheck for each function
# of the visa library. Additionally store in `_functions` the
# name of the functions.
functions.set_signatures(self.lib, errcheck=self._return_handler)
logger.debug('Library signatures: %d ok, %d failed',
len(getattr(self.lib, '_functions', [])),
len(getattr(self.lib, '_functions_failed', [])))
# Set the library functions as attributes of the object.
for method_name in getattr(self.lib, '_functions', []):
setattr(self, method_name, getattr(self.lib, method_name))
Exp|exp Matches either the preceding or following expression. The or
operator | matches the entire expression that precedes or
follows it and not just the character that precedes or follows
it. For example, VXI|GPIB means (VXI)|(GPIB), not VX(I|G)PIB.
(exp) Grouping characters or expressions.
:param resources: iterable of resources.
:param query: query expression.
"""
if '{' in query:
query, _ = query.split('{')
logger.warning('optional part of the query expression not supported. '
'See filter2')
try:
query = query.replace('?', '.')
matcher = re.compile(query, re.IGNORECASE)
except re.error:
raise errors.VisaIOError(constants.VI_ERROR_INV_EXPR)
return tuple(res for res in resources if matcher.match(res))
def init(self):
"""Singleton class constructor.
See vpp43.Singleton for details.
"""
ResourceTemplate.__init__(self)
# I have "session" as an alias because the specification calls the "vi"
# handle "session" for the resource manager.
self.session = self.vi = vpp43.open_default_resource_manager()