(self, objid)
| 405 | |
| 406 | KEYWORD_OBJ = KWD('obj') |
| 407 | def getobj(self, objid): |
| 408 | if not self.xrefs: |
| 409 | raise PDFException('PDFDocument is not initialized') |
| 410 | if 2 <= self.debug: |
| 411 | print >>sys.stderr, 'getobj: objid=%r' % (objid) |
| 412 | if objid in self._cached_objs: |
| 413 | genno = 0 |
| 414 | obj = self._cached_objs[objid] |
| 415 | else: |
| 416 | for xref in self.xrefs: |
| 417 | try: |
| 418 | (strmid, index) = xref.get_pos(objid) |
| 419 | break |
| 420 | except KeyError: |
| 421 | pass |
| 422 | else: |
| 423 | if STRICT: |
| 424 | raise PDFSyntaxError('Cannot locate objid=%r' % objid) |
| 425 | # return null for a nonexistent reference. |
| 426 | return None |
| 427 | if strmid: |
| 428 | stream = stream_value(self.getobj(strmid)) |
| 429 | if stream.get('Type') is not LITERAL_OBJSTM: |
| 430 | if STRICT: |
| 431 | raise PDFSyntaxError('Not a stream object: %r' % stream) |
| 432 | try: |
| 433 | n = stream['N'] |
| 434 | except KeyError: |
| 435 | if STRICT: |
| 436 | raise PDFSyntaxError('N is not defined: %r' % stream) |
| 437 | n = 0 |
| 438 | if strmid in self._parsed_objs: |
| 439 | objs = self._parsed_objs[strmid] |
| 440 | else: |
| 441 | parser = PDFStreamParser(stream.get_data()) |
| 442 | parser.set_document(self) |
| 443 | objs = [] |
| 444 | try: |
| 445 | while 1: |
| 446 | (_,obj) = parser.nextobject() |
| 447 | objs.append(obj) |
| 448 | except PSEOF: |
| 449 | pass |
| 450 | if self.caching: |
| 451 | self._parsed_objs[strmid] = objs |
| 452 | genno = 0 |
| 453 | i = n*2+index |
| 454 | try: |
| 455 | obj = objs[i] |
| 456 | except IndexError: |
| 457 | raise PDFSyntaxError('Invalid object number: objid=%r' % (objid)) |
| 458 | if isinstance(obj, PDFStream): |
| 459 | obj.set_objid(objid, 0) |
| 460 | else: |
| 461 | self._parser.seek(index) |
| 462 | (_,objid1) = self._parser.nexttoken() # objid |
| 463 | (_,genno) = self._parser.nexttoken() # genno |
| 464 | (_,kwd) = self._parser.nexttoken() |
no test coverage detected