60 | | while 1 : |
61 | | line = self.infile.readline() |
62 | | if not line : |
63 | | break |
64 | | # now workaround the unavailability of "Universal New Line" |
65 | | # under Python <2.3. |
66 | | line = line.strip().replace("\r\n", " ").replace("\r", " ") |
67 | | if line.startswith("% ") : |
68 | | lastcomment = line[2:] |
69 | | if line.endswith(" obj") : |
70 | | # New object begins here |
71 | | (n0, n1, dummy) = line.split() |
72 | | (major, minor) = map(int, (n0, n1)) |
73 | | obj = PDFObject(major, minor, lastcomment) |
74 | | while 1 : |
75 | | line = self.infile.readline() |
76 | | if not line : |
77 | | break |
78 | | line = line.strip() |
79 | | if line.startswith("% ") : |
| 60 | inobject = 0 |
| 61 | for fullline in self.infile.xreadlines() : |
| 62 | parts = [ l.strip() for l in fullline.splitlines() ] |
| 63 | for line in parts : |
| 64 | if line.startswith("% ") : |
| 65 | if inobject : |
81 | | elif line.startswith("endobj") : |
82 | | break |
| 67 | else : |
| 68 | lastcomment = line[2:] |
| 69 | elif line.endswith(" obj") : |
| 70 | # New object begins here |
| 71 | (n0, n1, dummy) = line.split() |
| 72 | (major, minor) = map(int, (n0, n1)) |
| 73 | obj = PDFObject(major, minor, lastcomment) |
| 74 | inobject = 1 |
| 75 | elif line.startswith("endobj") : |
| 76 | try : |
| 77 | # try to find a different version of this object |
| 78 | oldobject = objects[major] |
| 79 | except KeyError : |
| 80 | # not found, so we add it |
| 81 | objects[major] = obj |
85 | | try : |
86 | | # try to find a different version of this object |
87 | | oldobject = objects[major] |
88 | | except KeyError : |
89 | | # not found, so we add it |
90 | | objects[major] = obj |
91 | | else : |
92 | | # only overwrite older versions of this object |
93 | | # same minor seems to be possible, so the latest one |
94 | | # found in the file will be the one we keep. |
95 | | # if we want the first one, just use > instead of >= |
96 | | if minor >= oldobject.minor : |
97 | | objects[major] = obj |