64 | | for fullline in self.infile.xreadlines() : |
65 | | parts = [ l.strip() for l in fullline.splitlines() ] |
66 | | for line in parts : |
67 | | if line.startswith("% ") : |
| 64 | for line in self.infile : |
| 65 | line = line.strip() |
| 66 | if line.startswith("% ") : |
| 67 | if inobject : |
| 68 | obj.comments.append(line) |
| 69 | else : |
| 70 | lastcomment = line[2:] |
| 71 | else : |
| 72 | # New object begins here |
| 73 | result = objre.search(line) |
| 74 | if result is not None : |
| 75 | (major, minor) = [int(num) for num in line[result.start():result.end()].split()[:2]] |
| 76 | obj = PDFObject(major, minor, lastcomment) |
| 77 | obj.content.append(line[result.end():]) |
| 78 | inobject = 1 |
| 79 | elif line.startswith("endobj") \ |
| 80 | or line.startswith(">> endobj") \ |
| 81 | or line.startswith(">>endobj") : |
| 82 | # Handle previous object, if any |
69 | | obj.comments.append(line) |
70 | | else : |
71 | | lastcomment = line[2:] |
72 | | else : |
73 | | # New object begins here |
74 | | result = objre.search(line) |
75 | | if result is not None : |
76 | | (major, minor) = [int(num) for num in line[result.start():result.end()].split()[:2]] |
77 | | obj = PDFObject(major, minor, lastcomment) |
78 | | obj.content.append(line[result.end():]) |
79 | | inobject = 1 |
80 | | elif line.startswith("endobj") \ |
81 | | or line.startswith(">> endobj") \ |
82 | | or line.startswith(">>endobj") : |
83 | | # Handle previous object, if any |
84 | | if inobject : |
85 | | # only overwrite older versions of this object |
86 | | # same minor seems to be possible, so the latest one |
87 | | # found in the file will be the one we keep. |
88 | | # if we want the first one, just use > instead of >= |
89 | | oldobject = objects.setdefault(major, obj) |
90 | | if minor >= oldobject.minor : |
91 | | objects[major] = obj |
92 | | inobject = 0 |
93 | | else : |
94 | | if inobject : |
95 | | obj.content.append(line) |
| 84 | # only overwrite older versions of this object |
| 85 | # same minor seems to be possible, so the latest one |
| 86 | # found in the file will be the one we keep. |
| 87 | # if we want the first one, just use > instead of >= |
| 88 | oldobject = objects.setdefault(major, obj) |
| 89 | if minor >= oldobject.minor : |
| 90 | objects[major] = obj |
| 91 | inobject = 0 |
| 92 | else : |
| 93 | if inobject : |
| 94 | obj.content.append(line) |