-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'daritter-compat_struct'
- Loading branch information
Showing
2 changed files
with
49 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
pyvisa.compat.struct | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Python 2/3 compatibility for struct module | ||
:copyright: 2015, PSF | ||
:license: PSF License | ||
""" | ||
|
||
from __future__ import division, unicode_literals, print_function, absolute_import | ||
|
||
import sys | ||
import struct | ||
|
||
# we always want the exception to be able to catch it | ||
error = struct.error | ||
|
||
# compatibility for unicode literals was introduced in 2.7.8 | ||
# if we're above that there is nothing to do except aliasing | ||
if sys.hexversion >= 0x02070800: | ||
pack = struct.pack | ||
pack_into = struct.pack_into | ||
unpack = struct.unpack | ||
unpack_from = struct.unpack_from | ||
calcsize = struct.calcsize | ||
else: | ||
def pack(fmt, *args): | ||
return struct.pack(str(fmt), *args) | ||
|
||
def pack_into(fmt, *args, **argk): | ||
return struct.pack_into(str(fmt), *args, **argk) | ||
|
||
def unpack(fmt, string): | ||
return struct.unpack(str(fmt), string) | ||
|
||
def unpack_from(fmt, *args, **kwargs): | ||
return struct.unpack_from(str(fmt), *args, **kwargs) | ||
|
||
def calcsize(fmt): | ||
return struct.calcsize(str(fmt)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters