AlkantarClanX12
Current Path : /proc/thread-self/root/opt/alt/python33/lib64/python3.3/__pycache__/ |
Current File : //proc/thread-self/root/opt/alt/python33/lib64/python3.3/__pycache__/chunk.cpython-33.pyc |
� ��f c @ s d Z Gd d � d � Z d S( u Simple class to read IFF chunks. An IFF chunk (used in formats such as AIFF, TIFF, RMFF (RealMedia File Format)) has the following structure: +----------------+ | ID (4 bytes) | +----------------+ | size (4 bytes) | +----------------+ | data | | ... | +----------------+ The ID is a 4-byte string which identifies the type of chunk. The size field (a 32-bit value, encoded using big-endian byte order) gives the size of the whole chunk, including the 8-byte header. Usually an IFF-type file consists of one or more chunks. The proposed usage of the Chunk class defined here is to instantiate an instance at the start of each chunk and read from the instance until it reaches the end, after which a new instance can be instantiated. At the end of the file, creating a new instance will fail with a EOFError exception. Usage: while True: try: chunk = Chunk(file) except EOFError: break chunktype = chunk.getname() while True: data = chunk.read(nbytes) if not data: pass # do something with data The interface is file-like. The implemented methods are: read, close, seek, tell, isatty. Extra methods are: skip() (called by close, skips to the end of the chunk), getname() (returns the name (ID) of the chunk) The __init__ method has one required argument, a file-like object (including a chunk instance), and one optional argument, a flag which specifies whether or not chunks are aligned on 2-byte boundaries. The default is 1, i.e. aligned. c B s� | Ee Z d Z d d d d d � Z d d � Z d d � Z d d � Z d d � Z d d d � Z d d � Z d d d � Z d d � Z d S( u Chunkc C s d d l } d | _ | | _ | r- d } n d } | | _ | j d � | _ t | j � d k rl t � n y* | j | d | j d � � d | _ Wn | j k r� t � Yn X| r� | j d | _ n d | _ y | j j � | _ Wn! t t f k rd | _ Yn Xd | _ d S( Ni u >u <i u Li FT( u structu Falseu closedu alignu fileu readu chunknameu lenu EOFErroru unpack_fromu chunksizeu erroru size_readu tellu offsetu AttributeErroru IOErroru seekableu True( u selfu fileu alignu bigendianu inclheaderu structu strflag( ( u* /opt/alt/python33/lib64/python3.3/chunk.pyu __init__4 s, * u Chunk.__init__c C s | j S( u* Return the name (ID) of the current chunk.( u chunkname( u self( ( u* /opt/alt/python33/lib64/python3.3/chunk.pyu getnameN s u Chunk.getnamec C s | j S( u% Return the size of the current chunk.( u chunksize( u self( ( u* /opt/alt/python33/lib64/python3.3/chunk.pyu getsizeR s u Chunk.getsizec C s# | j s | j � d | _ n d S( NT( u closedu skipu True( u self( ( u* /opt/alt/python33/lib64/python3.3/chunk.pyu closeV s u Chunk.closec C s | j r t d � � n d S( Nu I/O operation on closed fileF( u closedu ValueErroru False( u self( ( u* /opt/alt/python33/lib64/python3.3/chunk.pyu isatty[ s u Chunk.isattyi c C s� | j r t d � � n | j s0 t d � � n | d k rL | | j } n | d k rh | | j } n | d k s� | | j k r� t � n | j j | j | d � | | _ d S( u� Seek to specified position into the chunk. Default position is 0 (start of chunk). If the file is not seekable, this will result in an error. u I/O operation on closed fileu cannot seeki i i N( u closedu ValueErroru seekableu IOErroru size_readu chunksizeu RuntimeErroru fileu seeku offset( u selfu posu whence( ( u* /opt/alt/python33/lib64/python3.3/chunk.pyu seek` s u Chunk.seekc C s | j r t d � � n | j S( Nu I/O operation on closed file( u closedu ValueErroru size_read( u self( ( u* /opt/alt/python33/lib64/python3.3/chunk.pyu tells s u Chunk.telli c C s� | j r t d � � n | j | j k r. d S| d k rM | j | j } n | | j | j k rv | j | j } n | j j | � } | j t | � | _ | j | j k r� | j r� | j d @r� | j j d � } | j t | � | _ n | S( u� Read at most size bytes from the chunk. If size is omitted or negative, read until the end of the chunk. u I/O operation on closed fileu i i ( u closedu ValueErroru size_readu chunksizeu fileu readu lenu align( u selfu sizeu datau dummy( ( u* /opt/alt/python33/lib64/python3.3/chunk.pyu readx s u Chunk.readc C s� | j r t d � � n | j r� y^ | j | j } | j rW | j d @rW | d } n | j j | d � | j | | _ d SWq� t k r� Yq� Xn xM | j | j k r� t d | j | j � } | j | � } | s� t � q� q� Wd S( u� Skip the rest of the chunk. If you are not interested in the contents of the chunk, this method should be called so that the file points to the start of the next chunk. u I/O operation on closed filei Ni ( u closedu ValueErroru seekableu chunksizeu size_readu alignu fileu seeku IOErroru minu readu EOFError( u selfu nu dummy( ( u* /opt/alt/python33/lib64/python3.3/chunk.pyu skip� s"