• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(3405)  |  Call(3090)  |  Derive(0)  |  Import(315)
Return size of C struct described by format string fmt.

src/l/a/Langtangen-HEAD/src/py/examples/reverseformat.py   Langtangen(Download)
else:
    data = file.read()  # read rest of file as a char chunk
    # first integer should be the number of z values:
    start = 0; stop = struct.calcsize('i')
    # struct.unpack always return tuples, even for a single number:
    nzvalues = (struct.unpack('i',data[start:stop]))[0]
    # load data into a typle of z values:
    format_nzvalues = str(nzvalues)+'d'
    start = stop; stop = start + struct.calcsize(format_nzvalues)

src/p/y/python-cookbook-HEAD/cb2_examples/cb2_2_8_sol_1.py   python-cookbook(Download)
import struct
format_string = '8l'                # e.g., say a record is 8 4-byte integers
thefile = open('somebinfile', 'r+b')
record_size = struct.calcsize(format_string)
thefile.seek(record_size * record_number)
buffer = thefile.read(record_size)
fields = list(struct.unpack(format_string, buffer))

src/p/y/python-cookbook-HEAD/cb2_examples/cb2_17_4_exm_2.py   python-cookbook(Download)
dll_handle = calldll.load_library ('.\\Ehllapi')
function_address = calldll.get_proc_address (dll_handle, 'HLLAPI')
# allocate and init three membufs with the size to hold an unsigned long
Lsize = struct.calcsize('L')
vFunction = calldll.membuf(Lsize)
mySetLong(vFunction, 1)
vTextLen = calldll.membuf(Lsize)

src/e/a/eagle-maemo-0.7/examples/chat.py   eagle-maemo(Download)
    def read( self ):
        try:
            size_bin = self.conn.recv( struct.calcsize( "!l" ) )
            size = struct.unpack( "!l", size_bin )[ 0 ]
            return self.conn.recv( size )
        except ( socket.error, struct.error ), e:
            return None

src/e/a/eagle-gtk-0.7/examples/chat.py   eagle-gtk(Download)
    def read( self ):
        try:
            size_bin = self.conn.recv( struct.calcsize( "!l" ) )
            size = struct.unpack( "!l", size_bin )[ 0 ]
            return self.conn.recv( size )
        except ( socket.error, struct.error ), e:
            return None

src/p/y/python-cookbook-HEAD/cb2_examples/cb2_1_13_sol_2.py   python-cookbook(Download)
import struct
# Get a 5-byte string, skip 3, get two 8-byte strings, then all the rest:
baseformat = "5s 3x 8s 8s"
# by how many bytes does theline exceed the length implied by this
# base-format (24 bytes in this case, but struct.calcsize is general)
numremain = len(theline) - struct.calcsize(baseformat)
# complete the format with the appropriate 's' field, then unpack

src/p/k/pksampler-HEAD/pk/stereo/CDLow.py   pksampler(Download)
 
tochdr_fmt   = "BB"
tocentry_fmt = "BBBix"
addr_fmt     = "BBB"+"x"*(struct.calcsize('i')-3)
region_fmt   = "BBBBBB"
subchnl_fmt  = "BBxBBiBBB"
 

src/p/k/pksampler-HEAD/pk/stereo/CDROM.py   pksampler(Download)
def sizeof(type):
  return struct.calcsize(type)
 
CDC_CD_R=0x2000
CDC_CD_RW=0x4000
CDC_CLOSE_TRAY=0x1
CDC_DRIVE_STATUS=0x800

src/i/r/ironruby-HEAD/External.LCA_RESTRICTED/Languages/IronPython/27/Lib/site-packages/win32/lib/win32gui_struct.py   ironruby(Download)
def UnpackWMNOTIFY(lparam):
    format = "iii"
    buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
    hwndFrom, idFrom, code = struct.unpack(format, buf)
    return hwndFrom, idFrom, code
 
# MENUITEMINFO struct
    # 'P' format does not accept PyHANDLE's !
    item = struct.pack(
                _menuiteminfo_fmt,
                struct.calcsize(_menuiteminfo_fmt), # cbSize
                fMask,
                fType,
                fState,
    # could be passed to a 'Get' function
    buf = struct.pack(
                _menuiteminfo_fmt,
                struct.calcsize(_menuiteminfo_fmt), # cbSize
                mask,
                0, #fType,
                0, #fState,
    # Create the struct.
    item = struct.pack(
                _menuinfo_fmt,
                struct.calcsize(_menuinfo_fmt), # cbSize
                fMask,
                dwStyle,
                cyMax,
 
    buf = struct.pack(
                _menuinfo_fmt,
                struct.calcsize(_menuinfo_fmt), # cbSize
                mask,
                0, #dwStyle
                0, #cyMax
def UnpackTVNOTIFY(lparam):
    format = "iiii40s40s"
    buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
    hwndFrom, id, code, action, buf_old, buf_new \
          = struct.unpack(format, buf)
    item_old = UnpackTVITEM(buf_old)
    item_new = UnpackTVITEM(buf_new)
    return hwndFrom, id, code, action, item_old, item_new
 
def UnpackTVDISPINFO(lparam):
    format = "iii40s"
    buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
def UnpackLVDISPINFO(lparam):
    format = "iii40s"
    buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
    hwndFrom, id, code, buf_item = struct.unpack(format, buf)
    item = UnpackLVITEM(buf_item)
    return hwndFrom, id, code, item
 
def UnpackLVNOTIFY(lparam):
    format = "3i8i"
    buf = win32gui.PyGetMemory(lparam, struct.calcsize(format))
def PackDEV_BROADCAST(devicetype, rest_fmt, rest_data, extra_data=_make_bytes('')):
    # It seems a requirement is 4 byte alignment, even for the 'BYTE data[1]'
    # field (eg, that would make DEV_BROADCAST_HANDLE 41 bytes, but we must
    # be 44.
    extra_data += _make_bytes('\0' * (4-len(extra_data)%4))
    format = "iii" + rest_fmt
    full_size = struct.calcsize(format) + len(extra_data)
def UnpackDEV_BROADCAST(lparam):
    if lparam == 0:
        return None
    hdr_format = "iii"
    hdr_size = struct.calcsize(hdr_format)
    hdr_buf = win32gui.PyGetMemory(lparam, hdr_size)
    size, devtype, reserved = struct.unpack("iii", hdr_buf)
        # 2 handles, a GUID, a LONG and possibly an array following...
        fmt = hdr_format + "PP16sl"
        _, _, _, x['handle'], x['hdevnotify'], guid_bytes, x['nameoffset'] = \
            struct.unpack(fmt, buf[:struct.calcsize(fmt)])
        x['eventguid'] = pywintypes.IID(guid_bytes, True)
    elif devtype == win32con.DBT_DEVTYP_DEVICEINTERFACE:
        fmt = hdr_format + "16s"
        _, _, _, guid_bytes = struct.unpack(fmt, buf[:struct.calcsize(fmt)])
        x['classguid'] = pywintypes.IID(guid_bytes, True)
        x['name'] = win32gui.PyGetString(lparam + struct.calcsize(fmt))
    elif devtype == win32con.DBT_DEVTYP_VOLUME:
        # int mask and flags
        fmt = hdr_format + "II"
        _, _, _, x['unitmask'], x['flags'] = struct.unpack(fmt, buf[:struct.calcsize(fmt)])

src/m/e/meresco-HEAD/meresco-components/workingsets/3.4.4-NED/version_1/meresco/components/packer.py   meresco(Download)
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
## end license ##
from struct import pack as struct_pack, unpack as struct_unpack, calcsize
 
class IntPacker(object):
    def __init__(self):
        self._packing = 'Q'
        self.length = calcsize(self._packing)
    def __init__(self):
        self._maxStringLength=300
        self._packing = 'Q%dsI' % self._maxStringLength
        self.length = calcsize(self._packing)
 
    def pack(self, item):
        anInt, aString = item
    def __init__(self):
        self._maxStringLength=300
        self._packing = '%dsIQ' % self._maxStringLength
        self.length = calcsize(self._packing)
 
    def pack(self, item):
        aString, anInt = item

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next