MCPcopy Index your code
hub / github.com/clips/pattern / PDFContentParser

Class PDFContentParser

pattern/web/pdf/pdfinterp.py:205–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203## PDFContentParser
204##
205class PDFContentParser(PSStackParser):
206
207 def __init__(self, streams):
208 self.streams = streams
209 self.istream = 0
210 PSStackParser.__init__(self, None)
211 return
212
213 def fillfp(self):
214 if not self.fp:
215 if self.istream < len(self.streams):
216 strm = stream_value(self.streams[self.istream])
217 self.istream += 1
218 else:
219 raise PSEOF('Unexpected EOF, file truncated?')
220 self.fp = StringIO(strm.get_data())
221 return
222
223 def seek(self, pos):
224 self.fillfp()
225 PSStackParser.seek(self, pos)
226 return
227
228 def fillbuf(self):
229 if self.charpos < len(self.buf): return
230 while 1:
231 self.fillfp()
232 self.bufpos = self.fp.tell()
233 self.buf = self.fp.read(self.BUFSIZ)
234 if self.buf: break
235 self.fp = None
236 self.charpos = 0
237 return
238
239 def get_inline_data(self, pos, target='EI'):
240 self.seek(pos)
241 i = 0
242 data = ''
243 while i <= len(target):
244 self.fillbuf()
245 if i:
246 c = self.buf[self.charpos]
247 data += c
248 self.charpos += 1
249 if len(target) <= i and c.isspace():
250 i += 1
251 elif i < len(target) and c == target[i]:
252 i += 1
253 else:
254 i = 0
255 else:
256 try:
257 j = self.buf.index(target[0], self.charpos)
258 #print 'found', (0, self.buf[j:j+10])
259 data += self.buf[self.charpos:j+1]
260 self.charpos = j+1
261 i = 1
262 except ValueError:

Callers 1

executeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…