_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q224300
parse_headers
train
def parse_headers(header_list): """ Convert headers from our serialized dict with lists for keys to a HTTPMessage """ header_string = b"" for key, values in header_list.items(): for v in values: header_string += \ key.encode('utf-8') + b":" + v.encode('utf-8')...
python
{ "resource": "" }
q224301
VCRConnection._uri
train
def _uri(self, url): """Returns request absolute URI""" if url and not url.startswith('/'): # Then this must be a proxy request. return url uri = "{0}://{1}{2}{3}".format( self._protocol, self.real_connection.host, self._port_postfix(),...
python
{ "resource": "" }
q224302
VCRConnection._url
train
def _url(self, uri): """Returns request selector url from absolute URI""" prefix = "{}://{}{}".format( self._protocol, self.real_connection.host, self._port_postfix(), ) return uri.replace(prefix, '', 1)
python
{ "resource": "" }
q224303
VCRConnection.request
train
def request(self, method, url, body=None, headers=None, *args, **kwargs): '''Persist the request metadata in self._vcr_request''' self._vcr_request = Request( method=method, uri=self._uri(url), body=body, headers=headers or {} ) log.debug('...
python
{ "resource": "" }
q224304
VCRConnection.getresponse
train
def getresponse(self, _=False, **kwargs): '''Retrieve the response''' # Check to see if the cassette has a response for this request. If so, # then return it if self.cassette.can_play_response_for(self._vcr_request): log.info( "Playing response for {} from cas...
python
{ "resource": "" }
q224305
VCRConnection.connect
train
def connect(self, *args, **kwargs): """ httplib2 uses this. Connects to the server I'm assuming. Only pass to the baseclass if we don't have a recorded response and are not write-protected. """ if hasattr(self, '_vcr_request') and \ self.cassette.can_pl...
python
{ "resource": "" }
q224306
CassettePatcherBuilder._recursively_apply_get_cassette_subclass
train
def _recursively_apply_get_cassette_subclass(self, replacement_dict_or_obj): """One of the subtleties of this class is that it does not directly replace HTTPSConnection with `VCRRequestsHTTPSConnection`, but a subclass of the aforementioned class that has the `cassette` class attribute a...
python
{ "resource": "" }
q224307
_Widget_fontdict
train
def _Widget_fontdict(): """Turns the above font definitions into a dictionary. Assumes certain line breaks and spaces. """ flist = Widget_fontobjects[2:-2].splitlines() fdict = {} for f in flist: k, v = f.split(" ") fdict[k[1:]] = v return fdict
python
{ "resource": "" }
q224308
getTextlength
train
def getTextlength(text, fontname="helv", fontsize=11, encoding=0): """Calculate length of a string for a given built-in font. Args: fontname: name of the font. fontsize: size of font in points. encoding: encoding to use (0=Latin, 1=Greek, 2=Cyrillic). Returns: (float) length...
python
{ "resource": "" }
q224309
getPDFstr
train
def getPDFstr(s): """ Return a PDF string depending on its coding. Notes: If only ascii then "(original)" is returned, else if only 8 bit chars then "(original)" with interspersed octal strings \nnn is returned, else a string "<FEFF[hexstring]>" is returned, where [hexstring] is the ...
python
{ "resource": "" }
q224310
CheckFont
train
def CheckFont(page, fontname): """Return an entry in the page's font list if reference name matches. """ for f in page.getFontList(): if f[4] == fontname: return f if f[3].lower() == fontname.lower(): return f return None
python
{ "resource": "" }
q224311
Matrix.invert
train
def invert(self, src=None): """Calculate the inverted matrix. Return 0 if successful and replace current one. Else return 1 and do nothing. """ if src is None: dst = TOOLS._invert_matrix(self) else: dst = TOOLS._invert_matrix(src) if dst[0] == 1: ...
python
{ "resource": "" }
q224312
Matrix.preTranslate
train
def preTranslate(self, tx, ty): """Calculate pre translation and replace current matrix.""" self.e += tx * self.a + ty * self.c self.f += tx * self.b + ty * self.d return self
python
{ "resource": "" }
q224313
Matrix.preScale
train
def preScale(self, sx, sy): """Calculate pre scaling and replace current matrix.""" self.a *= sx self.b *= sx self.c *= sy self.d *= sy return self
python
{ "resource": "" }
q224314
Matrix.preShear
train
def preShear(self, h, v): """Calculate pre shearing and replace current matrix.""" a, b = self.a, self.b self.a += v * self.c self.b += v * self.d self.c += h * a self.d += h * b return self
python
{ "resource": "" }
q224315
Matrix.preRotate
train
def preRotate(self, theta): """Calculate pre rotation and replace current matrix.""" while theta < 0: theta += 360 while theta >= 360: theta -= 360 epsilon = 1e-5 if abs(0 - theta) < epsilon: pass elif abs(90.0 - theta) < epsilon: a = self.a ...
python
{ "resource": "" }
q224316
Matrix.concat
train
def concat(self, one, two): """Multiply two matrices and replace current one.""" if not len(one) == len(two) == 6: raise ValueError("bad sequ. length") self.a, self.b, self.c, self.d, self.e, self.f = TOOLS._concat_matrix(one, two) return self
python
{ "resource": "" }
q224317
Point.transform
train
def transform(self, m): """Replace point by its transformation with matrix-like m.""" if len(m) != 6: raise ValueError("bad sequ. length") self.x, self.y = TOOLS._transform_point(self, m) return self
python
{ "resource": "" }
q224318
Point.unit
train
def unit(self): """Return unit vector of a point.""" s = self.x * self.x + self.y * self.y if s < 1e-5: return Point(0,0) s = math.sqrt(s) return Point(self.x / s, self.y / s)
python
{ "resource": "" }
q224319
Point.abs_unit
train
def abs_unit(self): """Return unit vector of a point with positive coordinates.""" s = self.x * self.x + self.y * self.y if s < 1e-5: return Point(0,0) s = math.sqrt(s) return Point(abs(self.x) / s, abs(self.y) / s)
python
{ "resource": "" }
q224320
Point.distance_to
train
def distance_to(self, *args): """Return the distance to a rectangle or another point.""" if not len(args) > 0: raise ValueError("at least one parameter must be given") x = args[0] if len(args) > 1: unit = args[1] else: unit = "px" u = ...
python
{ "resource": "" }
q224321
Rect.normalize
train
def normalize(self): """Replace rectangle with its finite version.""" if self.x1 < self.x0: self.x0, self.x1 = self.x1, self.x0 if self.y1 < self.y0: self.y0, self.y1 = self.y1, self.y0 return self
python
{ "resource": "" }
q224322
Rect.isEmpty
train
def isEmpty(self): """Check if rectangle area is empty.""" return self.x0 == self.x1 or self.y0 == self.y1
python
{ "resource": "" }
q224323
Rect.isInfinite
train
def isInfinite(self): """Check if rectangle is infinite.""" return self.x0 > self.x1 or self.y0 > self.y1
python
{ "resource": "" }
q224324
Rect.includePoint
train
def includePoint(self, p): """Extend rectangle to include point p.""" if not len(p) == 2: raise ValueError("bad sequ. length") self.x0, self.y0, self.x1, self.y1 = TOOLS._include_point_in_rect(self, p) return self
python
{ "resource": "" }
q224325
Rect.includeRect
train
def includeRect(self, r): """Extend rectangle to include rectangle r.""" if not len(r) == 4: raise ValueError("bad sequ. length") self.x0, self.y0, self.x1, self.y1 = TOOLS._union_rect(self, r) return self
python
{ "resource": "" }
q224326
Rect.intersect
train
def intersect(self, r): """Restrict self to common area with rectangle r.""" if not len(r) == 4: raise ValueError("bad sequ. length") self.x0, self.y0, self.x1, self.y1 = TOOLS._intersect_rect(self, r) return self
python
{ "resource": "" }
q224327
Rect.transform
train
def transform(self, m): """Replace rectangle with its transformation by matrix m.""" if not len(m) == 6: raise ValueError("bad sequ. length") self.x0, self.y0, self.x1, self.y1 = TOOLS._transform_rect(self, m) return self
python
{ "resource": "" }
q224328
Rect.intersects
train
def intersects(self, x): """Check if intersection with rectangle x is not empty.""" r1 = Rect(x) if self.isEmpty or self.isInfinite or r1.isEmpty: return False r = Rect(self) if r.intersect(r1).isEmpty: return False return True
python
{ "resource": "" }
q224329
Quad.isRectangular
train
def isRectangular(self): """Check if quad is rectangular. """ # if any two of the 4 corners are equal return false upper = (self.ur - self.ul).unit if not bool(upper): return False right = (self.lr - self.ur).unit if not bool(right): return False ...
python
{ "resource": "" }
q224330
Quad.transform
train
def transform(self, m): """Replace quad by its transformation with matrix m.""" if len(m) != 6: raise ValueError("bad sequ. length") self.ul *= m self.ur *= m self.ll *= m self.lr *= m return self
python
{ "resource": "" }
q224331
Widget._validate
train
def _validate(self): """Validate the class entries. """ checker = (self._check0, self._check1, self._check2, self._check3, self._check4, self._check5) if not 0 <= self.field_type <= 5: raise NotImplementedError("unsupported widget type") if type(sel...
python
{ "resource": "" }
q224332
Widget._adjust_font
train
def _adjust_font(self): """Ensure the font name is from our list and correctly spelled. """ fnames = [k for k in Widget_fontdict.keys()] fl = list(map(str.lower, fnames)) if (not self.text_font) or self.text_font.lower() not in fl: self.text_font = "helv" i = ...
python
{ "resource": "" }
q224333
Document.embeddedFileCount
train
def embeddedFileCount(self): """Return number of embedded files.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document_embeddedFileCount(self)
python
{ "resource": "" }
q224334
Document.embeddedFileDel
train
def embeddedFileDel(self, name): """Delete embedded file by name.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document_embeddedFileDel(self, name)
python
{ "resource": "" }
q224335
Document.embeddedFileInfo
train
def embeddedFileInfo(self, id): """Retrieve embedded file information given its entry number or name.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document_embeddedFileInfo(self, id)
python
{ "resource": "" }
q224336
Document.embeddedFileUpd
train
def embeddedFileUpd(self, id, buffer=None, filename=None, ufilename=None, desc=None): """Change an embedded file given its entry number or name.""" return _fitz.Document_embeddedFileUpd(self, id, buffer, filename, ufilename, desc)
python
{ "resource": "" }
q224337
Document.embeddedFileGet
train
def embeddedFileGet(self, id): """Retrieve embedded file content by name or by number.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document_embeddedFileGet(self, id)
python
{ "resource": "" }
q224338
Document.embeddedFileAdd
train
def embeddedFileAdd(self, buffer, name, filename=None, ufilename=None, desc=None): """Embed a new file.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document_embeddedFileAdd(self, buffer, name, filename, ufi...
python
{ "resource": "" }
q224339
Document.convertToPDF
train
def convertToPDF(self, from_page=0, to_page=-1, rotate=0): """Convert document to PDF selecting page range and optional rotation. Output bytes object.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document_conv...
python
{ "resource": "" }
q224340
Document.layout
train
def layout(self, rect=None, width=0, height=0, fontsize=11): """Re-layout a reflowable document.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") val = _fitz.Document_layout(self, rect, width, height, fontsize) self._...
python
{ "resource": "" }
q224341
Document.makeBookmark
train
def makeBookmark(self, pno=0): """Make page bookmark in a reflowable document.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document_makeBookmark(self, pno)
python
{ "resource": "" }
q224342
Document.findBookmark
train
def findBookmark(self, bookmark): """Find page number after layouting a document.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document_findBookmark(self, bookmark)
python
{ "resource": "" }
q224343
Document._deleteObject
train
def _deleteObject(self, xref): """Delete an object given its xref.""" if self.isClosed: raise ValueError("operation illegal for closed doc") return _fitz.Document__deleteObject(self, xref)
python
{ "resource": "" }
q224344
Document.authenticate
train
def authenticate(self, password): """Decrypt document with a password.""" if self.isClosed: raise ValueError("operation illegal for closed doc") val = _fitz.Document_authenticate(self, password) if val: # the doc is decrypted successfully and we init the outline ...
python
{ "resource": "" }
q224345
Document.write
train
def write(self, garbage=0, clean=0, deflate=0, ascii=0, expand=0, linear=0, pretty=0, decrypt=1): """Write document to a bytes object.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") if self.pageCount < 1: raise V...
python
{ "resource": "" }
q224346
Document.select
train
def select(self, pyliste): """Build sub-pdf with page numbers in 'list'.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") val = _fitz.Document_select(self, pyliste) self._reset_page_refs() self.initData() ...
python
{ "resource": "" }
q224347
Document._getCharWidths
train
def _getCharWidths(self, xref, bfname, ext, ordering, limit, idx=0): """Return list of glyphs and glyph widths of a font.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document__getCharWidths(self, xref, bfname...
python
{ "resource": "" }
q224348
Document._getPageInfo
train
def _getPageInfo(self, pno, what): """Show fonts or images used on a page.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") val = _fitz.Document__getPageInfo(self, pno, what) x = [] for v in val: i...
python
{ "resource": "" }
q224349
Document.extractImage
train
def extractImage(self, xref=0): """Extract image which 'xref' is pointing to.""" if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") return _fitz.Document_extractImage(self, xref)
python
{ "resource": "" }
q224350
Document.getPageFontList
train
def getPageFontList(self, pno): """Retrieve a list of fonts used on a page. """ if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") if self.isPDF: return self._getPageInfo(pno, 1) return []
python
{ "resource": "" }
q224351
Document.getPageImageList
train
def getPageImageList(self, pno): """Retrieve a list of images used on a page. """ if self.isClosed or self.isEncrypted: raise ValueError("operation illegal for closed / encrypted doc") if self.isPDF: return self._getPageInfo(pno, 2) return []
python
{ "resource": "" }
q224352
Document.copyPage
train
def copyPage(self, pno, to=-1): """Copy a page to before some other page of the document. Specify 'to = -1' to copy after last page. """ pl = list(range(len(self))) if pno < 0 or pno > pl[-1]: raise ValueError("'from' page number out of range") if to < -1 or to > pl[-...
python
{ "resource": "" }
q224353
Document.movePage
train
def movePage(self, pno, to = -1): """Move a page to before some other page of the document. Specify 'to = -1' to move after last page. """ pl = list(range(len(self))) if pno < 0 or pno > pl[-1]: raise ValueError("'from' page number out of range") if to < -1 or to > pl...
python
{ "resource": "" }
q224354
Document.deletePage
train
def deletePage(self, pno = -1): """Delete a page from the document. First page is '0', last page is '-1'. """ pl = list(range(len(self))) if pno < -1 or pno > pl[-1]: raise ValueError("page number out of range") if pno >= 0: pl.remove(pno) else: ...
python
{ "resource": "" }
q224355
Document.deletePageRange
train
def deletePageRange(self, from_page = -1, to_page = -1): """Delete pages from the document. First page is '0', last page is '-1'. """ pl = list(range(len(self))) f = from_page t = to_page if f == -1: f = pl[-1] if t == -1: t = pl[-1] ...
python
{ "resource": "" }
q224356
Document._forget_page
train
def _forget_page(self, page): """Remove a page from document page dict.""" pid = id(page) if pid in self._page_refs: self._page_refs[pid] = None
python
{ "resource": "" }
q224357
Document._reset_page_refs
train
def _reset_page_refs(self): """Invalidate all pages in document dictionary.""" if self.isClosed: return for page in self._page_refs.values(): if page: page._erase() page = None self._page_refs.clear()
python
{ "resource": "" }
q224358
Page.addLineAnnot
train
def addLineAnnot(self, p1, p2): """Add 'Line' annot for points p1 and p2.""" CheckParent(self) val = _fitz.Page_addLineAnnot(self, p1, p2) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val return val
python
{ "resource": "" }
q224359
Page.addTextAnnot
train
def addTextAnnot(self, point, text): """Add a 'sticky note' at position 'point'.""" CheckParent(self) val = _fitz.Page_addTextAnnot(self, point, text) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val ...
python
{ "resource": "" }
q224360
Page.addInkAnnot
train
def addInkAnnot(self, list): """Add a 'handwriting' as a list of list of point-likes. Each sublist forms an independent stroke.""" CheckParent(self) val = _fitz.Page_addInkAnnot(self, list) if not val: return val.thisown = True val.parent = weakref.proxy(self) s...
python
{ "resource": "" }
q224361
Page.addStampAnnot
train
def addStampAnnot(self, rect, stamp=0): """Add a 'rubber stamp' in a rectangle.""" CheckParent(self) val = _fitz.Page_addStampAnnot(self, rect, stamp) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val ...
python
{ "resource": "" }
q224362
Page.addFileAnnot
train
def addFileAnnot(self, point, buffer, filename, ufilename=None, desc=None): """Add a 'FileAttachment' annotation at location 'point'.""" CheckParent(self) val = _fitz.Page_addFileAnnot(self, point, buffer, filename, ufilename, desc) if not val: return val.thisown = True ...
python
{ "resource": "" }
q224363
Page.addStrikeoutAnnot
train
def addStrikeoutAnnot(self, rect): """Strike out content in a rectangle or quadrilateral.""" CheckParent(self) val = _fitz.Page_addStrikeoutAnnot(self, rect) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val ...
python
{ "resource": "" }
q224364
Page.addUnderlineAnnot
train
def addUnderlineAnnot(self, rect): """Underline content in a rectangle or quadrilateral.""" CheckParent(self) val = _fitz.Page_addUnderlineAnnot(self, rect) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val ...
python
{ "resource": "" }
q224365
Page.addSquigglyAnnot
train
def addSquigglyAnnot(self, rect): """Wavy underline content in a rectangle or quadrilateral.""" CheckParent(self) val = _fitz.Page_addSquigglyAnnot(self, rect) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val...
python
{ "resource": "" }
q224366
Page.addHighlightAnnot
train
def addHighlightAnnot(self, rect): """Highlight content in a rectangle or quadrilateral.""" CheckParent(self) val = _fitz.Page_addHighlightAnnot(self, rect) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val ...
python
{ "resource": "" }
q224367
Page.addRectAnnot
train
def addRectAnnot(self, rect): """Add a 'Rectangle' annotation.""" CheckParent(self) val = _fitz.Page_addRectAnnot(self, rect) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val return val
python
{ "resource": "" }
q224368
Page.addCircleAnnot
train
def addCircleAnnot(self, rect): """Add a 'Circle' annotation.""" CheckParent(self) val = _fitz.Page_addCircleAnnot(self, rect) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val return val
python
{ "resource": "" }
q224369
Page.addPolylineAnnot
train
def addPolylineAnnot(self, points): """Add a 'Polyline' annotation for a sequence of points.""" CheckParent(self) val = _fitz.Page_addPolylineAnnot(self, points) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = v...
python
{ "resource": "" }
q224370
Page.addPolygonAnnot
train
def addPolygonAnnot(self, points): """Add a 'Polygon' annotation for a sequence of points.""" CheckParent(self) val = _fitz.Page_addPolygonAnnot(self, points) if not val: return val.thisown = True val.parent = weakref.proxy(self) self._annot_refs[id(val)] = val ...
python
{ "resource": "" }
q224371
Page.addFreetextAnnot
train
def addFreetextAnnot(self, rect, text, fontsize=12, fontname=None, color=None, rotate=0): """Add a 'FreeText' annotation in rectangle 'rect'.""" CheckParent(self) val = _fitz.Page_addFreetextAnnot(self, rect, text, fontsize, fontname, color, rotate) if not val: return val.thiso...
python
{ "resource": "" }
q224372
Page.addWidget
train
def addWidget(self, widget): """Add a form field. """ CheckParent(self) doc = self.parent if not doc.isPDF: raise ValueError("not a PDF") widget._validate() # Check if PDF already has our fonts. # If none insert all of them in a new object and store t...
python
{ "resource": "" }
q224373
Page.firstAnnot
train
def firstAnnot(self): """Points to first annotation on page""" CheckParent(self) val = _fitz.Page_firstAnnot(self) if val: val.thisown = True val.parent = weakref.proxy(self) # owning page object self._annot_refs[id(val)] = val return val
python
{ "resource": "" }
q224374
Page.deleteLink
train
def deleteLink(self, linkdict): """Delete link if PDF""" CheckParent(self) val = _fitz.Page_deleteLink(self, linkdict) if linkdict["xref"] == 0: return linkid = linkdict["id"] try: linkobj = self._annot_refs[linkid] linkobj._erase() except...
python
{ "resource": "" }
q224375
Page.deleteAnnot
train
def deleteAnnot(self, fannot): """Delete annot if PDF and return next one""" CheckParent(self) val = _fitz.Page_deleteAnnot(self, fannot) if val: val.thisown = True val.parent = weakref.proxy(self) # owning page object val.parent._annot_refs[id(val)] ...
python
{ "resource": "" }
q224376
Page._forget_annot
train
def _forget_annot(self, annot): """Remove an annot from reference dictionary.""" aid = id(annot) if aid in self._annot_refs: self._annot_refs[aid] = None
python
{ "resource": "" }
q224377
Annot.rect
train
def rect(self): """Rectangle containing the annot""" CheckParent(self) val = _fitz.Annot_rect(self) val = Rect(val) return val
python
{ "resource": "" }
q224378
Annot.fileUpd
train
def fileUpd(self, buffer=None, filename=None, ufilename=None, desc=None): """Update annotation attached file.""" CheckParent(self) return _fitz.Annot_fileUpd(self, buffer, filename, ufilename, desc)
python
{ "resource": "" }
q224379
Link.dest
train
def dest(self): """Create link destination details.""" if hasattr(self, "parent") and self.parent is None: raise ValueError("orphaned object: parent is None") if self.parent.parent.isClosed or self.parent.parent.isEncrypted: raise ValueError("operation illegal for closed ...
python
{ "resource": "" }
q224380
Tools.measure_string
train
def measure_string(self, text, fontname, fontsize, encoding=0): """Measure length of a string for a Base14 font.""" return _fitz.Tools_measure_string(self, text, fontname, fontsize, encoding)
python
{ "resource": "" }
q224381
Tools._le_annot_parms
train
def _le_annot_parms(self, annot, p1, p2): """Get common parameters for making line end symbols. """ w = annot.border["width"] # line width sc = annot.colors["stroke"] # stroke color if not sc: sc = (0,0,0) scol = " ".join(map(str, sc)) + " RG\n" fc...
python
{ "resource": "" }
q224382
pbis
train
def pbis(a): """End point of a reflected sun ray, given an angle a.""" return(math.cos(3*a - math.pi), (math.sin(3*a - math.pi)))
python
{ "resource": "" }
q224383
print_descr
train
def print_descr(rect, annot): """Print a short description to the right of an annot rect.""" annot.parent.insertText(rect.br + (10, 0), "'%s' annotation" % annot.type[1], color = red)
python
{ "resource": "" }
q224384
recoverpix
train
def recoverpix(doc, item): """Return pixmap for item, which is a list of 2 xref numbers. Second xref is that of an smask if > 0. Return None for any error. """ x = item[0] # xref of PDF image s = item[1] # xref of its /SMask try: pix1 = fitz.Pixmap(doc, x) # make pixmap fr...
python
{ "resource": "" }
q224385
PDFdisplay.on_update_page_links
train
def on_update_page_links(self, evt): """ Perform PDF update of changed links.""" if not self.update_links: # skip if unsupported links evt.Skip() return pg = self.doc[getint(self.TextToPage.Value) -1] for i in range(len(self.page_links)): ...
python
{ "resource": "" }
q224386
PDFdisplay.Rect_to_wxRect
train
def Rect_to_wxRect(self, fr): """ Return a zoomed wx.Rect for given fitz.Rect.""" r = (fr * self.zoom).irect # zoomed IRect return wx.Rect(r.x0, r.y0, r.width, r.height)
python
{ "resource": "" }
q224387
PDFdisplay.wxRect_to_Rect
train
def wxRect_to_Rect(self, wr): """ Return a shrunk fitz.Rect for given wx.Rect.""" r = fitz.Rect(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height) return r * self.shrink
python
{ "resource": "" }
q224388
PDFdisplay.is_in_free_area
train
def is_in_free_area(self, nr, ok = -1): """ Determine if rect covers a free area inside the bitmap.""" for i, r in enumerate(self.link_rects): if r.Intersects(nr) and i != ok: return False bmrect = wx.Rect(0,0,dlg.bitmap.Size[0],dlg.bitmap.Size[1]) return bmre...
python
{ "resource": "" }
q224389
PDFdisplay.get_linkrect_idx
train
def get_linkrect_idx(self, pos): """ Determine if cursor is inside one of the link hot spots.""" for i, r in enumerate(self.link_rects): if r.Contains(pos): return i return -1
python
{ "resource": "" }
q224390
PDFdisplay.get_bottomrect_idx
train
def get_bottomrect_idx(self, pos): """ Determine if cursor is on bottom right corner of a hot spot.""" for i, r in enumerate(self.link_bottom_rects): if r.Contains(pos): return i return -1
python
{ "resource": "" }
q224391
getTextWords
train
def getTextWords(page): """Return the text words as a list with the bbox for each word. """ CheckParent(page) dl = page.getDisplayList() tp = dl.getTextPage() l = tp._extractTextWords_AsList() del dl del tp return l
python
{ "resource": "" }
q224392
getText
train
def getText(page, output = "text"): """ Extract a document page's text. Args: output: (str) text, html, dict, json, rawdict, xhtml or xml. Returns: the output of TextPage methods extractText, extractHTML, extractDICT, extractJSON, extractRAWDICT, extractXHTML or etractXML respectively. Def...
python
{ "resource": "" }
q224393
getPagePixmap
train
def getPagePixmap(doc, pno, matrix = None, colorspace = csRGB, clip = None, alpha = True): """Create pixmap of document page by page number. Notes: Convenience function calling page.getPixmap. Args: pno: (int) page number matrix: Matrix for transformation (default:...
python
{ "resource": "" }
q224394
getToC
train
def getToC(doc, simple = True): """Create a table of contents. Args: simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation. """ def recurse(olItem, liste...
python
{ "resource": "" }
q224395
updateLink
train
def updateLink(page, lnk): """ Update a link on the current page. """ CheckParent(page) annot = getLinkText(page, lnk) if annot == "": raise ValueError("link kind not supported") page.parent._updateObject(lnk["xref"], annot, page = page) return
python
{ "resource": "" }
q224396
insertLink
train
def insertLink(page, lnk, mark = True): """ Insert a new link for the current page. """ CheckParent(page) annot = getLinkText(page, lnk) if annot == "": raise ValueError("link kind not supported") page._addAnnot_FromString([annot]) return
python
{ "resource": "" }
q224397
newPage
train
def newPage(doc, pno=-1, width=595, height=842): """Create and return a new page object. """ doc._newPage(pno, width=width, height=height) return doc[pno]
python
{ "resource": "" }
q224398
insertPage
train
def insertPage( doc, pno, text=None, fontsize=11, width=595, height=842, fontname="helv", fontfile=None, color=None, ): """ Create a new PDF page and insert some text. Notes: Function combining Document.newPage() and Page.inser...
python
{ "resource": "" }
q224399
drawSquiggle
train
def drawSquiggle(page, p1, p2, breadth = 2, color=None, dashes=None, width=1, roundCap=False, overlay=True, morph=None): """Draw a squiggly line from point p1 to point p2. """ img = page.newShape() p = img.drawSquiggle(Point(p1), Point(p2), breadth = breadth) img.finish(color=color, d...
python
{ "resource": "" }