~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to .pc/git-updates.diff/PIL/TarIO.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (1.1.4)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130131204920-7tnuhqhlsqdza4c2
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# The Python Imaging Library.
 
3
# $Id$
 
4
#
 
5
# read files from within a tar file
 
6
#
 
7
# History:
 
8
# 95-06-18 fl   Created
 
9
# 96-05-28 fl   Open files in binary mode
 
10
#
 
11
# Copyright (c) Secret Labs AB 1997.
 
12
# Copyright (c) Fredrik Lundh 1995-96.
 
13
#
 
14
# See the README file for information on usage and redistribution.
 
15
#
 
16
 
 
17
import ContainerIO
 
18
import string
 
19
 
 
20
##
 
21
# A file object that provides read access to a given member of a TAR
 
22
# file.
 
23
 
 
24
class TarIO(ContainerIO.ContainerIO):
 
25
 
 
26
    ##
 
27
    # Create file object.
 
28
    #
 
29
    # @param tarfile Name of TAR file.
 
30
    # @param file Name of member file.
 
31
 
 
32
    def __init__(self, tarfile, file):
 
33
 
 
34
        fh = open(tarfile, "rb")
 
35
 
 
36
        while 1:
 
37
 
 
38
            s = fh.read(512)
 
39
            if len(s) != 512:
 
40
                raise IOError, "unexpected end of tar file"
 
41
 
 
42
            name = s[:100]
 
43
            i = string.find(name, chr(0))
 
44
            if i == 0:
 
45
                raise IOError, "cannot find subfile"
 
46
            if i > 0:
 
47
                name = name[:i]
 
48
 
 
49
            size = string.atoi(s[124:136], 8)
 
50
 
 
51
            if file == name:
 
52
                break
 
53
 
 
54
            fh.seek((size + 511) & (~511), 1)
 
55
 
 
56
        # Open region
 
57
        ContainerIO.ContainerIO.__init__(self, fh, fh.tell(), size)