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

All Samples(15306)  |  Call(14688)  |  Derive(0)  |  Import(618)
Unpack the string containing packed C structure data, according to fmt.
Requires len(string) == calcsize(fmt).

src/p/k/pksampler-HEAD/pk/stereo/CDLow.py   pksampler(Download)
def get_volume():
#	cd_open()
	try:
		return struct.unpack("BBBB",ioctl(cd.cd, CDROMVOLREAD, struct.pack("BBBB",0,0,0,0)))
 
	except:
		return (0,0,0,0)
#	cd_close()
 
def set_volume(frontleft,frontright=None,backleft=0,backright=0):
#	cd_open()
	if frontright == None: frontright = frontleft
	try:
		return struct.unpack("BBBB",ioctl(cd.cd, CDROMVOLCTRL, struct.pack("BBBB",frontleft,frontright,backleft,backright)))
		except:
			i = i +1
#	cd_close()
	format, status, track, something, absaddr, relmin, relsec, relfrm = struct.unpack(subchnl_fmt, info)
	absmin, abssec, absfrm = struct.unpack(addr_fmt, struct.pack("i", absaddr))
	zero = (1, 0,0,0, 0,0,0)
	if   status == CDROM_AUDIO_PLAY      : cd.status = PLAYING
def get_header():
#	cd_open()
	tochdr = struct.pack(tochdr_fmt, 0, 0)
	tochdr = ioctl(cd.cd, CDROMREADTOCHDR, tochdr)
	cd.start, cd.end = struct.unpack(tochdr_fmt, tochdr)
#	cd_close()
 
	toc = struct.pack(tocentry_fmt, trk, 0, CDROM_MSF, 0)
	toc = ioctl(cd.cd, CDROMREADTOCENTRY, toc)
 
	track, adrctrl, format, addr = struct.unpack(tocentry_fmt, toc)
	m, s, f = struct.unpack(addr_fmt, struct.pack("i", addr))
 
	adr = adrctrl & 0xf

src/d/a/dacp-HEAD/examples/dacp.py   dacp(Download)
	def nested(self, tag):
		s = re.search(tag, self._raw)
 
		if not s: return None
 
		p = s.start()
		l = struct.unpack('>I', self._raw[p + 4:p + 8])[0]
	def array(self, tag):
		q = []
		for m in re.finditer(tag, self._raw):
			p = m.start()
			l = struct.unpack('>I', self._raw[p + 4:p + 8])[0]
			q += [Parser(self._raw[p + 8:p + 8 + l])]
 
			return None
 
		p = s.start()
		l = struct.unpack('>I', self._raw[p + 4:p + 8])[0]
 
		return self._raw[p + 8:p + 8 + l]
 
	def bool(self, tag=None):
		if not tag:
			return bool(struct.unpack('>B', self._raw)[0])
			return None
 
		p = s.start()
		l = struct.unpack('>I', self._raw[p + 4:p + 8])[0]
 
		return bool(struct.unpack('>B', self._raw[p + 8:p + 8 + l])[0])
 
	def int(self, tag=None):
		if not tag:
			return struct.unpack('>I', self._raw)[0]
			return None
 
		p = s.start()
		l = struct.unpack('>I', self._raw[p + 4:p + 8])[0]
 
		return struct.unpack('>I', self._raw[p + 8:p + 8 + l])[0]
 

src/c/r/crapvine-HEAD/exchange_samples/read_bin_test.py   crapvine(Download)
from __future__ import with_statement
from struct import unpack, calcsize
 
def read_string(file):
	strlen = unpack('<h', file.read(2))[0]
	return unpack("%ds" % strlen, file.read(strlen))[0]
 
	print("%s" % (f.read(4)))
	f.read(18)
	s_number_of_creatures = f.read(2)
	number_of_creatures = unpack("<h", s_number_of_creatures)[0]
	print('number of creatures %d' % number_of_creatures)
	s_creature_type = f.read(2)
	creature_type = unpack("<h", s_creature_type)[0]

src/m/a/matplotlib-HEAD/toolkits/basemap-0.9.6.1/examples/pupynere.py   matplotlib(Download)
 
        # Read version byte.
        byte = self.read(1)
        self.version_byte = struct.unpack('>b', byte)[0]
 
        # Read header info.
        self._numrecs()
 
        typecode = typecodes[nc_type-1]
        if nc_type != 2:  # not char 
            values = struct.unpack('>%s' % (typecode * n), values)
            values = array(values, dtype=typecode) 
        else:
            # Remove EOL terminator.
            if values.endswith('\x00'): values = values[:-1]
 
        return values
 
    def _unpack_int(self):
        return struct.unpack('>i', self.read(4))[0]
    def _unpack_int64(self):
        return struct.unpack('>q', self.read(8))[0]
 
    def _read_string(self):
        count = struct.unpack('>i', self.read(4))[0]
        s = self.read(count)
        # Remove EOL terminator.

src/p/k/pksampler-HEAD/scosc/OSC.py   pksampler(Download)
def readBlob(data):
    length   = struct.unpack(">i", data[0:4])[0]    
    nextData = int(math.ceil((length) / 4.0) * 4) + 4   
    return (data[4:length+4], data[nextData:])
 
 
def readInt(data):
    if(len(data)<4):
        print "Error: too few bytes for int", data, len(data)
        rest = data
        integer = 0
    else:
        integer = struct.unpack(">i", data[0:4])[0]
def readLong(data):
    """Tries to interpret the next 8 bytes of the data
    as a 64-bit signed integer."""
    high, low = struct.unpack(">ll", data[0:8])
    big = (long(high) << 32) + low
    rest = data[8:]
    return (big, rest)
 
 
def readDouble(data):
    """Tries to interpret the next 8 bytes of the data
    as a 64-bit double float."""
    floater = struct.unpack(">d", data[0:8])
def readFloat(data):
    if(len(data)<4):
        print "Error: too few bytes for float", data, len(data)
        rest = data
        floater = 0
    else:
        floater = struct.unpack(">f", data[0:4])[0]

src/l/a/Langtangen-HEAD/src/py/examples/reverseformat.py   Langtangen(Download)
    # 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)
    zvalues = struct.unpack(format_nzvalues,data[start:stop])

src/n/o/noen-HEAD/server/Python/src/BinarySampleWrite.py   noen(Download)
def intToBytes(intValue):
    bytes = struct.pack('>I',intValue)
    bytes = struct.unpack('>BBBB',bytes)
    return bytes
 
def formatProjectChange(id):
    format = bigEndian[1] + 'BBBB'

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/k/pksampler-HEAD/scosc/osctools.py   pksampler(Download)
def convertNetworkToLongInt(byteString):
   out = struct.unpack('>Q', byteString)
   return out[0]
 
def oscSecondFraction(fPartOfTime):
   return int((fPartOfTime)*(2**32))
 

src/p/e/pexpect-HEAD/pexpect/examples/script.py   pexpect(Download)
    else:
        TIOCGWINSZ = 1074295912 # assume
    s = struct.pack ("HHHH", 0, 0, 0, 0)
    a = struct.unpack ('HHHH', fcntl.ioctl(sys.stdout.fileno(), TIOCGWINSZ , s))
    global global_pexpect_instance
    global_pexpect_instance.setwinsize(a[0],a[1])
 

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