예제 #1
0
 def execute(self, streams):
     try:
         parser = PDFContentParser(streams)
     except PSEOF:
         # empty page
         return
     while 1:
         try:
             (_,obj) = parser.nextobject()
         except PSEOF:
             break
         if isinstance(obj, PSKeyword):
             name = keyword_name(obj)
             method = 'do_%s' % name.replace('*','_a').replace('"','_w').replace("'",'_q')
             if hasattr(self, method):
                 func = getattr(self, method)
                 nargs = func.func_code.co_argcount-1
                 if nargs:
                     args = self.pop(nargs)
                     if 1 <= self.debug:
                         print >>stderr, 'exec: %s %r' % (name, args)
                     if len(args) == nargs:
                         func(*args)
                 else:
                     if 1 <= self.debug:
                         print >>stderr, 'exec: %s' % (name)
                     func()
             else:
                 if STRICT:
                     raise PDFInterpreterError('Unknown operator: %r' % name)
         else:
             self.push(obj)
     return
예제 #2
0
 def execute(self, streams):
     try:
         parser = PDFContentParser(streams)
     except PSEOF:
         # empty page
         return
     while 1:
         try:
             (_,obj) = parser.nextobject()
         except PSEOF:
             break
         if isinstance(obj, PSKeyword):
             name = keyword_name(obj)
             method = 'do_%s' % name.replace('*','_a').replace('"','_w').replace("'",'_q')
             if hasattr(self, method):
                 func = getattr(self, method)
                 nargs = func.func_code.co_argcount-1
                 if nargs:
                     args = self.pop(nargs)
                     if 2 <= self.debug:
                         print >>sys.stderr, 'exec: %s %r' % (name, args)
                     if len(args) == nargs:
                         func(*args)
                 else:
                     if 2 <= self.debug:
                         print >>sys.stderr, 'exec: %s' % (name)
                     func()
             else:
                 if STRICT:
                     raise PDFInterpreterError('Unknown operator: %r' % name)
         else:
             self.push(obj)
     return
 def execute(self, streams):
     for2Mem=''
     try:
         parser = PDFContentParser(streams)
     except PSEOF:
         # empty page
         return
     while 1:
         try:
             (_,obj) = parser.nextobject()
         except PSEOF:#breaks when detects parser end of file SR
             break
         if isinstance(obj, PSKeyword):#if object is of known type
             name = keyword_name(obj)
             method = 'do_%s' % name.replace('*','_a').replace('"','_w').replace("'",'_q')#figures out what method to execute 
             if hasattr(self, method):#if object has that method
                 func = getattr(self, method)#assign method to func (so that it can be called abstractly)
                 nargs = func.func_code.co_argcount-1#see "inspect" module (Python STL) gets number of arguments
                 if nargs:
                     args = self.pop(nargs)
                     if 2 <= self.debug:
                         print >>sys.stderr, 'exec: %s %r' % (name, args)
                     if len(args) == nargs:
                         result=func(*args)#here the functions are executed
                         if isinstance(result, basestring):
                             for2Mem+=result
                 else:
                     if 2 <= self.debug:
                         print >>sys.stderr, 'exec: %s' % (name)
                     func()
             else:
                 if STRICT:
                     raise PDFInterpreterError('Unknown operator: %r' % name)
         else:
             self.push(obj)
     return for2Mem