Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Static Private Attributes
zipfile.ZipInfo Class Reference
Inheritance diagram for zipfile.ZipInfo:
Inheritance graph
[legend]
Collaboration diagram for zipfile.ZipInfo:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def FileHeader

Public Attributes

 orig_filename
 filename
 date_time
 compress_type
 comment
 extra
 create_system
 create_version
 extract_version
 reserved
 flag_bits
 volume
 internal_attr
 external_attr
 file_size
 compress_size
 header_offset
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _encodeFilenameFlags
def _decodeExtra

Static Private Attributes

tuple __slots__

Detailed Description

Class with attributes describing each file in the ZIP archive.

Definition at line 262 of file zipfile.py.


Constructor & Destructor Documentation

def zipfile.ZipInfo.__init__ (   self,
  filename = "NoName",
  date_time = (1980,1 
)

Definition at line 287 of file zipfile.py.

00287 
00288     def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
00289         self.orig_filename = filename   # Original file name in archive
00290 
00291         # Terminate the file name at the first null byte.  Null bytes in file
00292         # names are used as tricks by viruses in archives.
00293         null_byte = filename.find(chr(0))
00294         if null_byte >= 0:
00295             filename = filename[0:null_byte]
00296         # This is used to ensure paths in generated ZIP files always use
00297         # forward slashes as the directory separator, as required by the
00298         # ZIP format specification.
00299         if os.sep != "/" and os.sep in filename:
00300             filename = filename.replace(os.sep, "/")
00301 
00302         self.filename = filename        # Normalized file name
00303         self.date_time = date_time      # year, month, day, hour, min, sec
00304         # Standard values:
00305         self.compress_type = ZIP_STORED # Type of compression for the file
00306         self.comment = b""              # Comment for each file
00307         self.extra = b""                # ZIP extra data
00308         if sys.platform == 'win32':
00309             self.create_system = 0          # System which created ZIP archive
00310         else:
00311             # Assume everything else is unix-y
00312             self.create_system = 3          # System which created ZIP archive
00313         self.create_version = 20        # Version which created ZIP archive
00314         self.extract_version = 20       # Version needed to extract archive
00315         self.reserved = 0               # Must be zero
00316         self.flag_bits = 0              # ZIP flag bits
00317         self.volume = 0                 # Volume number of file header
00318         self.internal_attr = 0          # Internal attributes
00319         self.external_attr = 0          # External file attributes
00320         # Other attributes are set by class ZipFile:
00321         # header_offset         Byte offset to the file header
00322         # CRC                   CRC-32 of the uncompressed file
00323         # compress_size         Size of the compressed file
00324         # file_size             Size of the uncompressed file

Here is the caller graph for this function:


Member Function Documentation

def zipfile.ZipInfo._decodeExtra (   self) [private]

Definition at line 365 of file zipfile.py.

00365 
00366     def _decodeExtra(self):
00367         # Try to decode the extra field.
00368         extra = self.extra
00369         unpack = struct.unpack
00370         while extra:
00371             tp, ln = unpack('<HH', extra[:4])
00372             if tp == 1:
00373                 if ln >= 24:
00374                     counts = unpack('<QQQ', extra[4:28])
00375                 elif ln == 16:
00376                     counts = unpack('<QQ', extra[4:20])
00377                 elif ln == 8:
00378                     counts = unpack('<Q', extra[4:12])
00379                 elif ln == 0:
00380                     counts = ()
00381                 else:
00382                     raise RuntimeError("Corrupt extra field %s"%(ln,))
00383 
00384                 idx = 0
00385 
00386                 # ZIP64 extension (large files and/or large archives)
00387                 if self.file_size in (0xffffffffffffffff, 0xffffffff):
00388                     self.file_size = counts[idx]
00389                     idx += 1
00390 
00391                 if self.compress_size == 0xFFFFFFFF:
00392                     self.compress_size = counts[idx]
00393                     idx += 1
00394 
00395                 if self.header_offset == 0xffffffff:
00396                     old = self.header_offset
00397                     self.header_offset = counts[idx]
00398                     idx+=1
00399 
00400             extra = extra[ln+4:]
00401 

Here is the call graph for this function:

def zipfile.ZipInfo._encodeFilenameFlags (   self) [private]

Definition at line 359 of file zipfile.py.

00359 
00360     def _encodeFilenameFlags(self):
00361         try:
00362             return self.filename.encode('ascii'), self.flag_bits
00363         except UnicodeEncodeError:
00364             return self.filename.encode('utf-8'), self.flag_bits | 0x800

Here is the caller graph for this function:

Return the per-file header as a string.

Definition at line 325 of file zipfile.py.

00325 
00326     def FileHeader(self):
00327         """Return the per-file header as a string."""
00328         dt = self.date_time
00329         dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2]
00330         dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2)
00331         if self.flag_bits & 0x08:
00332             # Set these to zero because we write them after the file data
00333             CRC = compress_size = file_size = 0
00334         else:
00335             CRC = self.CRC
00336             compress_size = self.compress_size
00337             file_size = self.file_size
00338 
00339         extra = self.extra
00340 
00341         if file_size > ZIP64_LIMIT or compress_size > ZIP64_LIMIT:
00342             # File is larger than what fits into a 4 byte integer,
00343             # fall back to the ZIP64 extension
00344             fmt = '<HHQQ'
00345             extra = extra + struct.pack(fmt,
00346                     1, struct.calcsize(fmt)-4, file_size, compress_size)
00347             file_size = 0xffffffff
00348             compress_size = 0xffffffff
00349             self.extract_version = max(45, self.extract_version)
00350             self.create_version = max(45, self.extract_version)
00351 
00352         filename, flag_bits = self._encodeFilenameFlags()
00353         header = struct.pack(structFileHeader, stringFileHeader,
00354                  self.extract_version, self.reserved, flag_bits,
00355                  self.compress_type, dostime, dosdate, CRC,
00356                  compress_size, file_size,
00357                  len(filename), len(extra))
00358         return header + filename + extra

Here is the call graph for this function:


Member Data Documentation

tuple zipfile.ZipInfo.__slots__ [static, private]
Initial value:
(
            'orig_filename',
            'filename',
            'date_time',
            'compress_type',
            'comment',
            'extra',
            'create_system',
            'create_version',
            'extract_version',
            'reserved',
            'flag_bits',
            'volume',
            'internal_attr',
            'external_attr',
            'header_offset',
            'CRC',
            'compress_size',
            'file_size',
            '_raw_time',
        )

Definition at line 265 of file zipfile.py.

Definition at line 305 of file zipfile.py.

Definition at line 390 of file zipfile.py.

Definition at line 304 of file zipfile.py.

Definition at line 308 of file zipfile.py.

Definition at line 312 of file zipfile.py.

Definition at line 302 of file zipfile.py.

Definition at line 318 of file zipfile.py.

Definition at line 306 of file zipfile.py.

Definition at line 313 of file zipfile.py.

Definition at line 387 of file zipfile.py.

Definition at line 301 of file zipfile.py.

Definition at line 315 of file zipfile.py.

Definition at line 394 of file zipfile.py.

Definition at line 317 of file zipfile.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 288 of file zipfile.py.

Definition at line 314 of file zipfile.py.

Definition at line 316 of file zipfile.py.


The documentation for this class was generated from the following file: