nwo
stringlengths
10
28
sha
stringlengths
40
40
path
stringlengths
11
97
identifier
stringlengths
1
64
parameters
stringlengths
2
2.24k
return_statement
stringlengths
0
2.17k
docstring
stringlengths
0
5.45k
docstring_summary
stringlengths
0
3.83k
func_begin
int64
1
13.4k
func_end
int64
2
13.4k
function
stringlengths
28
56.4k
url
stringlengths
106
209
project
int64
1
48
executed_lines
list
executed_lines_pc
float64
0
153
missing_lines
list
missing_lines_pc
float64
0
100
covered
bool
2 classes
filecoverage
float64
2.53
100
function_lines
int64
2
1.46k
mccabe
int64
1
253
coverage
float64
0
100
docstring_lines
int64
0
112
function_nodoc
stringlengths
9
56.4k
id
int64
0
29.8k
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
NumberObject.read_from_stream
(stream: StreamType)
return NumberObject(num)
419
423
def read_from_stream(stream: StreamType) -> Union["NumberObject", "FloatObject"]: num = read_until_regex(stream, NumberObject.NumberPattern) if num.find(b".") != -1: return FloatObject(num) return NumberObject(num)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L419-L423
39
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
99.71831
5
2
100
0
def read_from_stream(stream: StreamType) -> Union["NumberObject", "FloatObject"]: num = read_until_regex(stream, NumberObject.NumberPattern) if num.find(b".") != -1: return FloatObject(num) return NumberObject(num)
24,554
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
NumberObject.readFromStream
( stream: StreamType, )
return NumberObject.read_from_stream(stream)
426
430
def readFromStream( stream: StreamType, ) -> Union["NumberObject", "FloatObject"]: # deprecated deprecation_with_replacement("readFromStream", "read_from_stream", "3.0.0") return NumberObject.read_from_stream(stream)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L426-L430
39
[]
0
[]
0
false
99.71831
5
1
100
0
def readFromStream( stream: StreamType, ) -> Union["NumberObject", "FloatObject"]: # deprecated deprecation_with_replacement("readFromStream", "read_from_stream", "3.0.0") return NumberObject.read_from_stream(stream)
24,555
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
TextStringObject.clone
( self, pdf_dest: Any, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), )
return cast("TextStringObject", self._reference_clone(obj, pdf_dest))
clone object into pdf_dest
clone object into pdf_dest
485
495
def clone( self, pdf_dest: Any, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "TextStringObject": """clone object into pdf_dest""" obj = TextStringObject(self) obj.autodetect_pdfdocencoding = self.autodetect_pdfdocencoding obj.autodetect_utf16 = self.autodetect_utf16 return cast("TextStringObject", self._reference_clone(obj, pdf_dest))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L485-L495
39
[ 0, 6, 7, 8, 9, 10 ]
54.545455
[]
0
false
99.71831
11
1
100
1
def clone( self, pdf_dest: Any, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "TextStringObject": obj = TextStringObject(self) obj.autodetect_pdfdocencoding = self.autodetect_pdfdocencoding obj.autodetect_utf16 = self.autodetect_utf16 return cast("TextStringObject", self._reference_clone(obj, pdf_dest))
24,556
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
TextStringObject.original_bytes
(self)
return self.get_original_bytes()
It is occasionally possible that a text string object gets created where a byte string object was expected due to the autodetection mechanism -- if that occurs, this "original_bytes" property can be used to back-calculate what the original encoded bytes were.
It is occasionally possible that a text string object gets created where a byte string object was expected due to the autodetection mechanism -- if that occurs, this "original_bytes" property can be used to back-calculate what the original encoded bytes were.
501
508
def original_bytes(self) -> bytes: """ It is occasionally possible that a text string object gets created where a byte string object was expected due to the autodetection mechanism -- if that occurs, this "original_bytes" property can be used to back-calculate what the original encoded bytes were. """ return self.get_original_bytes()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L501-L508
39
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
99.71831
8
1
100
4
def original_bytes(self) -> bytes: return self.get_original_bytes()
24,557
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
TextStringObject.get_original_bytes
(self)
510
521
def get_original_bytes(self) -> bytes: # We're a text string object, but the library is trying to get our raw # bytes. This can happen if we auto-detected this string as text, but # we were wrong. It's pretty common. Return the original bytes that # would have been used to create this object, based upon the autodetect # method. if self.autodetect_utf16: return codecs.BOM_UTF16_BE + self.encode("utf-16be") elif self.autodetect_pdfdocencoding: return encode_pdfdocencoding(self) else: raise Exception("no information about original bytes")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L510-L521
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11 ]
91.666667
[]
0
false
99.71831
12
3
100
0
def get_original_bytes(self) -> bytes: # We're a text string object, but the library is trying to get our raw # bytes. This can happen if we auto-detected this string as text, but # we were wrong. It's pretty common. Return the original bytes that # would have been used to create this object, based upon the autodetect # method. if self.autodetect_utf16: return codecs.BOM_UTF16_BE + self.encode("utf-16be") elif self.autodetect_pdfdocencoding: return encode_pdfdocencoding(self) else: raise Exception("no information about original bytes")
24,558
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
TextStringObject.write_to_stream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
523
550
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # Try to write the string out as a PDFDocEncoding encoded string. It's # nicer to look at in the PDF file. Sadly, we take a performance hit # here for trying... try: bytearr = encode_pdfdocencoding(self) except UnicodeEncodeError: bytearr = codecs.BOM_UTF16_BE + self.encode("utf-16be") if encryption_key: from .._security import RC4_encrypt bytearr = RC4_encrypt(encryption_key, bytearr) obj = ByteStringObject(bytearr) obj.write_to_stream(stream, None) else: stream.write(b"(") for c in bytearr: if not chr(c).isalnum() and c != b" ": # This: # stream.write(b_(rf"\{c:0>3o}")) # gives # https://github.com/davidhalter/parso/issues/207 stream.write(b_("\\%03o" % c)) else: stream.write(b_(chr(c))) stream.write(b")")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L523-L550
39
[ 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27 ]
78.571429
[]
0
false
99.71831
28
6
100
0
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # Try to write the string out as a PDFDocEncoding encoded string. It's # nicer to look at in the PDF file. Sadly, we take a performance hit # here for trying... try: bytearr = encode_pdfdocencoding(self) except UnicodeEncodeError: bytearr = codecs.BOM_UTF16_BE + self.encode("utf-16be") if encryption_key: from .._security import RC4_encrypt bytearr = RC4_encrypt(encryption_key, bytearr) obj = ByteStringObject(bytearr) obj.write_to_stream(stream, None) else: stream.write(b"(") for c in bytearr: if not chr(c).isalnum() and c != b" ": # This: # stream.write(b_(rf"\{c:0>3o}")) # gives # https://github.com/davidhalter/parso/issues/207 stream.write(b_("\\%03o" % c)) else: stream.write(b_(chr(c))) stream.write(b")")
24,559
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
TextStringObject.writeToStream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
552
556
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L552-L556
39
[]
0
[]
0
false
99.71831
5
1
100
0
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
24,560
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
NameObject.clone
( self, pdf_dest: Any, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), )
return cast("NameObject", self._reference_clone(NameObject(self), pdf_dest))
clone object into pdf_dest
clone object into pdf_dest
570
577
def clone( self, pdf_dest: Any, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "NameObject": """clone object into pdf_dest""" return cast("NameObject", self._reference_clone(NameObject(self), pdf_dest))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L570-L577
39
[ 0, 6, 7 ]
37.5
[]
0
false
99.71831
8
1
100
1
def clone( self, pdf_dest: Any, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "NameObject": return cast("NameObject", self._reference_clone(NameObject(self), pdf_dest))
24,561
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
NameObject.write_to_stream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
579
582
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: stream.write(self.renumber())
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L579-L582
39
[ 0, 3 ]
50
[]
0
false
99.71831
4
1
100
0
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: stream.write(self.renumber())
24,562
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
NameObject.writeToStream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
584
588
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L584-L588
39
[]
0
[]
0
false
99.71831
5
1
100
0
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
24,563
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
NameObject.renumber
(self)
return out
590
603
def renumber(self) -> bytes: out = self[0].encode("utf-8") if out != b"/": logger_warning(f"Incorrect first char in NameObject:({self})", __name__) for c in self[1:]: if c > "~": for x in c.encode("utf-8"): out += f"#{x:02X}".encode() else: try: out += self.renumber_table[c] except KeyError: out += c.encode("utf-8") return out
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L590-L603
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13 ]
92.857143
[]
0
false
99.71831
14
6
100
0
def renumber(self) -> bytes: out = self[0].encode("utf-8") if out != b"/": logger_warning(f"Incorrect first char in NameObject:({self})", __name__) for c in self[1:]: if c > "~": for x in c.encode("utf-8"): out += f"#{x:02X}".encode() else: try: out += self.renumber_table[c] except KeyError: out += c.encode("utf-8") return out
24,564
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
NameObject.unnumber
(sin: bytes)
return sin
606
616
def unnumber(sin: bytes) -> bytes: i = sin.find(b"#", 0) while i >= 0: try: sin = sin[:i] + unhexlify(sin[i + 1 : i + 3]) + sin[i + 3 :] i = sin.find(b"#", i + 1) except ValueError: # if the 2 characters after # can not be converted to hexa # we change nothing and carry on i = i + 1 return sin
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L606-L616
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
99.71831
11
3
100
0
def unnumber(sin: bytes) -> bytes: i = sin.find(b"#", 0) while i >= 0: try: sin = sin[:i] + unhexlify(sin[i + 1 : i + 3]) + sin[i + 3 :] i = sin.find(b"#", i + 1) except ValueError: # if the 2 characters after # can not be converted to hexa # we change nothing and carry on i = i + 1 return sin
24,565
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
NameObject.read_from_stream
(stream: StreamType, pdf: Any)
619
644
def read_from_stream(stream: StreamType, pdf: Any) -> "NameObject": # PdfReader name = stream.read(1) if name != NameObject.surfix: raise PdfReadError("name read error") name += read_until_regex(stream, NameObject.delimiter_pattern, ignore_eof=True) try: # Name objects should represent irregular characters # with a '#' followed by the symbol's hex number name = NameObject.unnumber(name) for enc in ("utf-8", "gbk"): try: ret = name.decode(enc) return NameObject(ret) except Exception: pass raise UnicodeDecodeError("", name, 0, 0, "Code Not Found") except (UnicodeEncodeError, UnicodeDecodeError) as e: if not pdf.strict: logger_warning( f"Illegal character in Name Object ({repr(name)})", __name__ ) return NameObject(name.decode("charmap")) else: raise PdfReadError( f"Illegal character in Name Object ({repr(name)})" ) from e
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L619-L644
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 23 ]
80.769231
[]
0
false
99.71831
26
6
100
0
def read_from_stream(stream: StreamType, pdf: Any) -> "NameObject": # PdfReader name = stream.read(1) if name != NameObject.surfix: raise PdfReadError("name read error") name += read_until_regex(stream, NameObject.delimiter_pattern, ignore_eof=True) try: # Name objects should represent irregular characters # with a '#' followed by the symbol's hex number name = NameObject.unnumber(name) for enc in ("utf-8", "gbk"): try: ret = name.decode(enc) return NameObject(ret) except Exception: pass raise UnicodeDecodeError("", name, 0, 0, "Code Not Found") except (UnicodeEncodeError, UnicodeDecodeError) as e: if not pdf.strict: logger_warning( f"Illegal character in Name Object ({repr(name)})", __name__ ) return NameObject(name.decode("charmap")) else: raise PdfReadError( f"Illegal character in Name Object ({repr(name)})" ) from e
24,566
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_base.py
NameObject.readFromStream
( stream: StreamType, pdf: Any # PdfReader )
return NameObject.read_from_stream(stream, pdf)
647
651
def readFromStream( stream: StreamType, pdf: Any # PdfReader ) -> "NameObject": # deprecated deprecation_with_replacement("readFromStream", "read_from_stream", "3.0.0") return NameObject.read_from_stream(stream, pdf)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_base.py#L647-L651
39
[]
0
[]
0
false
99.71831
5
1
100
0
def readFromStream( stream: StreamType, pdf: Any # PdfReader ) -> "NameObject": # deprecated deprecation_with_replacement("readFromStream", "read_from_stream", "3.0.0") return NameObject.read_from_stream(stream, pdf)
24,567
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_annotations.py
AnnotationBuilder.text
( rect: Union[RectangleObject, Tuple[float, float, float, float]], text: str, open: bool = False, flags: int = 0, )
return text_obj
Add text annotation. Args: rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` open: flags: Returns: A dictionary object representing the annotation.
Add text annotation.
30
60
def text( rect: Union[RectangleObject, Tuple[float, float, float, float]], text: str, open: bool = False, flags: int = 0, ) -> DictionaryObject: """ Add text annotation. Args: rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` open: flags: Returns: A dictionary object representing the annotation. """ # TABLE 8.23 Additional entries specific to a text annotation text_obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Text"), NameObject("/Rect"): RectangleObject(rect), NameObject("/Contents"): TextStringObject(text), NameObject("/Open"): BooleanObject(open), NameObject("/Flags"): NumberObject(flags), } ) return text_obj
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_annotations.py#L30-L60
39
[ 0, 19, 20, 30 ]
12.903226
[]
0
false
98.214286
31
1
100
11
def text( rect: Union[RectangleObject, Tuple[float, float, float, float]], text: str, open: bool = False, flags: int = 0, ) -> DictionaryObject: # TABLE 8.23 Additional entries specific to a text annotation text_obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Text"), NameObject("/Rect"): RectangleObject(rect), NameObject("/Contents"): TextStringObject(text), NameObject("/Open"): BooleanObject(open), NameObject("/Flags"): NumberObject(flags), } ) return text_obj
24,568
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_annotations.py
AnnotationBuilder.free_text
( text: str, rect: Union[RectangleObject, Tuple[float, float, float, float]], font: str = "Helvetica", bold: bool = False, italic: bool = False, font_size: str = "14pt", font_color: str = "000000", border_color: str = "000000", background_color: str = "ffffff", )
return free_text
Add text in a rectangle to a page. Args: text: Text to be added rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` font: Name of the Font, e.g. 'Helvetica' bold: Print the text in bold italic: Print the text in italic font_size: How big the text will be, e.g. '14pt' font_color: Hex-string for the color border_color: Hex-string for the border color background_color: Hex-string for the background of the annotation Returns: A dictionary object representing the annotation.
Add text in a rectangle to a page.
63
122
def free_text( text: str, rect: Union[RectangleObject, Tuple[float, float, float, float]], font: str = "Helvetica", bold: bool = False, italic: bool = False, font_size: str = "14pt", font_color: str = "000000", border_color: str = "000000", background_color: str = "ffffff", ) -> DictionaryObject: """ Add text in a rectangle to a page. Args: text: Text to be added rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` font: Name of the Font, e.g. 'Helvetica' bold: Print the text in bold italic: Print the text in italic font_size: How big the text will be, e.g. '14pt' font_color: Hex-string for the color border_color: Hex-string for the border color background_color: Hex-string for the background of the annotation Returns: A dictionary object representing the annotation. """ font_str = "font: " if bold is True: font_str = f"{font_str}bold " if italic is True: font_str = f"{font_str}italic " font_str = f"{font_str}{font} {font_size}" font_str = f"{font_str};text-align:left;color:#{font_color}" bg_color_str = "" for st in hex_to_rgb(border_color): bg_color_str = f"{bg_color_str}{st} " bg_color_str = f"{bg_color_str}rg" free_text = DictionaryObject() free_text.update( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/FreeText"), NameObject("/Rect"): RectangleObject(rect), NameObject("/Contents"): TextStringObject(text), # font size color NameObject("/DS"): TextStringObject(font_str), # border color NameObject("/DA"): TextStringObject(bg_color_str), # background color NameObject("/C"): ArrayObject( [FloatObject(n) for n in hex_to_rgb(background_color)] ), } ) return free_text
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_annotations.py#L63-L122
39
[ 0, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 ]
55
[]
0
false
98.214286
60
5
100
16
def free_text( text: str, rect: Union[RectangleObject, Tuple[float, float, float, float]], font: str = "Helvetica", bold: bool = False, italic: bool = False, font_size: str = "14pt", font_color: str = "000000", border_color: str = "000000", background_color: str = "ffffff", ) -> DictionaryObject: font_str = "font: " if bold is True: font_str = f"{font_str}bold " if italic is True: font_str = f"{font_str}italic " font_str = f"{font_str}{font} {font_size}" font_str = f"{font_str};text-align:left;color:#{font_color}" bg_color_str = "" for st in hex_to_rgb(border_color): bg_color_str = f"{bg_color_str}{st} " bg_color_str = f"{bg_color_str}rg" free_text = DictionaryObject() free_text.update( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/FreeText"), NameObject("/Rect"): RectangleObject(rect), NameObject("/Contents"): TextStringObject(text), # font size color NameObject("/DS"): TextStringObject(font_str), # border color NameObject("/DA"): TextStringObject(bg_color_str), # background color NameObject("/C"): ArrayObject( [FloatObject(n) for n in hex_to_rgb(background_color)] ), } ) return free_text
24,569
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_annotations.py
AnnotationBuilder.line
( p1: Tuple[float, float], p2: Tuple[float, float], rect: Union[RectangleObject, Tuple[float, float, float, float]], text: str = "", title_bar: str = "", )
return line_obj
Draw a line on the PDF. Args: p1: First point p2: Second point rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` text: Text to be displayed as the line annotation title_bar: Text to be displayed in the title bar of the annotation; by convention this is the name of the author Returns: A dictionary object representing the annotation.
Draw a line on the PDF.
125
178
def line( p1: Tuple[float, float], p2: Tuple[float, float], rect: Union[RectangleObject, Tuple[float, float, float, float]], text: str = "", title_bar: str = "", ) -> DictionaryObject: """ Draw a line on the PDF. Args: p1: First point p2: Second point rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` text: Text to be displayed as the line annotation title_bar: Text to be displayed in the title bar of the annotation; by convention this is the name of the author Returns: A dictionary object representing the annotation. """ line_obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Line"), NameObject("/Rect"): RectangleObject(rect), NameObject("/T"): TextStringObject(title_bar), NameObject("/L"): ArrayObject( [ FloatObject(p1[0]), FloatObject(p1[1]), FloatObject(p2[0]), FloatObject(p2[1]), ] ), NameObject("/LE"): ArrayObject( [ NameObject(None), NameObject(None), ] ), NameObject("/IC"): ArrayObject( [ FloatObject(0.5), FloatObject(0.5), FloatObject(0.5), ] ), NameObject("/Contents"): TextStringObject(text), } ) return line_obj
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_annotations.py#L125-L178
39
[ 0, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 ]
61.111111
[]
0
false
98.214286
54
1
100
14
def line( p1: Tuple[float, float], p2: Tuple[float, float], rect: Union[RectangleObject, Tuple[float, float, float, float]], text: str = "", title_bar: str = "", ) -> DictionaryObject: line_obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Line"), NameObject("/Rect"): RectangleObject(rect), NameObject("/T"): TextStringObject(title_bar), NameObject("/L"): ArrayObject( [ FloatObject(p1[0]), FloatObject(p1[1]), FloatObject(p2[0]), FloatObject(p2[1]), ] ), NameObject("/LE"): ArrayObject( [ NameObject(None), NameObject(None), ] ), NameObject("/IC"): ArrayObject( [ FloatObject(0.5), FloatObject(0.5), FloatObject(0.5), ] ), NameObject("/Contents"): TextStringObject(text), } ) return line_obj
24,570
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_annotations.py
AnnotationBuilder.rectangle
( rect: Union[RectangleObject, Tuple[float, float, float, float]], interiour_color: Optional[str] = None, )
return square_obj
Draw a rectangle on the PDF. Args: rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` rect: interiour_color: Returns: A dictionary object representing the annotation.
Draw a rectangle on the PDF.
181
211
def rectangle( rect: Union[RectangleObject, Tuple[float, float, float, float]], interiour_color: Optional[str] = None, ) -> DictionaryObject: """ Draw a rectangle on the PDF. Args: rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` rect: interiour_color: Returns: A dictionary object representing the annotation. """ square_obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Square"), NameObject("/Rect"): RectangleObject(rect), } ) if interiour_color: square_obj[NameObject("/IC")] = ArrayObject( [FloatObject(n) for n in hex_to_rgb(interiour_color)] ) return square_obj
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_annotations.py#L181-L211
39
[ 0, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ]
51.612903
[]
0
false
98.214286
31
3
100
11
def rectangle( rect: Union[RectangleObject, Tuple[float, float, float, float]], interiour_color: Optional[str] = None, ) -> DictionaryObject: square_obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Square"), NameObject("/Rect"): RectangleObject(rect), } ) if interiour_color: square_obj[NameObject("/IC")] = ArrayObject( [FloatObject(n) for n in hex_to_rgb(interiour_color)] ) return square_obj
24,571
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_annotations.py
AnnotationBuilder.polygon
(vertices: List[Tuple[float, float]])
return obj
214
238
def polygon(vertices: List[Tuple[float, float]]) -> DictionaryObject: if len(vertices) == 0: raise ValueError("A polygon needs at least 1 vertex with two coordinates") x_min, y_min = vertices[0][0], vertices[0][1] x_max, y_max = vertices[0][0], vertices[0][1] for x, y in vertices: x_min = min(x_min, x) y_min = min(y_min, y) x_max = min(x_max, x) y_max = min(y_max, y) rect = RectangleObject((x_min, y_min, x_max, y_max)) coord_list = [] for x, y in vertices: coord_list.append(NumberObject(x)) coord_list.append(NumberObject(y)) obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Polygon"), NameObject("/Vertices"): ArrayObject(coord_list), NameObject("/IT"): NameObject("PolygonCloud"), NameObject("/Rect"): RectangleObject(rect), } ) return obj
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_annotations.py#L214-L238
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 24 ]
68
[]
0
false
98.214286
25
4
100
0
def polygon(vertices: List[Tuple[float, float]]) -> DictionaryObject: if len(vertices) == 0: raise ValueError("A polygon needs at least 1 vertex with two coordinates") x_min, y_min = vertices[0][0], vertices[0][1] x_max, y_max = vertices[0][0], vertices[0][1] for x, y in vertices: x_min = min(x_min, x) y_min = min(y_min, y) x_max = min(x_max, x) y_max = min(y_max, y) rect = RectangleObject((x_min, y_min, x_max, y_max)) coord_list = [] for x, y in vertices: coord_list.append(NumberObject(x)) coord_list.append(NumberObject(y)) obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Polygon"), NameObject("/Vertices"): ArrayObject(coord_list), NameObject("/IT"): NameObject("PolygonCloud"), NameObject("/Rect"): RectangleObject(rect), } ) return obj
24,572
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_annotations.py
AnnotationBuilder.link
( rect: Union[RectangleObject, Tuple[float, float, float, float]], border: Optional[ArrayObject] = None, url: Optional[str] = None, target_page_index: Optional[int] = None, fit: Fit = DEFAULT_FIT, )
return link_obj
Add a link to the document. The link can either be an external link or an internal link. An external link requires the URL parameter. An internal link requires the target_page_index, fit, and fit args. Args: rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` border: if provided, an array describing border-drawing properties. See the PDF spec for details. No border will be drawn if this argument is omitted. - horizontal corner radius, - vertical corner radius, and - border width - Optionally: Dash url: Link to a website (if you want to make an external link) target_page_index: index of the page to which the link should go (if you want to make an internal link) fit: Page fit or 'zoom' option. Returns: A dictionary object representing the annotation.
Add a link to the document.
241
323
def link( rect: Union[RectangleObject, Tuple[float, float, float, float]], border: Optional[ArrayObject] = None, url: Optional[str] = None, target_page_index: Optional[int] = None, fit: Fit = DEFAULT_FIT, ) -> DictionaryObject: """ Add a link to the document. The link can either be an external link or an internal link. An external link requires the URL parameter. An internal link requires the target_page_index, fit, and fit args. Args: rect: or array of four integers specifying the clickable rectangular area ``[xLL, yLL, xUR, yUR]`` border: if provided, an array describing border-drawing properties. See the PDF spec for details. No border will be drawn if this argument is omitted. - horizontal corner radius, - vertical corner radius, and - border width - Optionally: Dash url: Link to a website (if you want to make an external link) target_page_index: index of the page to which the link should go (if you want to make an internal link) fit: Page fit or 'zoom' option. Returns: A dictionary object representing the annotation. """ from ..types import BorderArrayType is_external = url is not None is_internal = target_page_index is not None if not is_external and not is_internal: raise ValueError( "Either 'url' or 'target_page_index' have to be provided. Both were None." ) if is_external and is_internal: raise ValueError( f"Either 'url' or 'target_page_index' have to be provided. url={url}, target_page_index={target_page_index}" ) border_arr: BorderArrayType if border is not None: border_arr = [NameObject(n) for n in border[:3]] if len(border) == 4: dash_pattern = ArrayObject([NameObject(n) for n in border[3]]) border_arr.append(dash_pattern) else: border_arr = [NumberObject(0)] * 3 link_obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Link"), NameObject("/Rect"): RectangleObject(rect), NameObject("/Border"): ArrayObject(border_arr), } ) if is_external: link_obj[NameObject("/A")] = DictionaryObject( { NameObject("/S"): NameObject("/URI"), NameObject("/Type"): NameObject("/Action"), NameObject("/URI"): TextStringObject(url), } ) if is_internal: # This needs to be updated later! dest_deferred = DictionaryObject( { "target_page_index": NumberObject(target_page_index), "fit": NameObject(fit.fit_type), "fit_args": fit.fit_args, } ) link_obj[NameObject("/Dest")] = dest_deferred return link_obj
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_annotations.py#L241-L323
39
[ 0, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82 ]
60.240964
[ 54 ]
1.204819
false
98.214286
83
11
98.795181
25
def link( rect: Union[RectangleObject, Tuple[float, float, float, float]], border: Optional[ArrayObject] = None, url: Optional[str] = None, target_page_index: Optional[int] = None, fit: Fit = DEFAULT_FIT, ) -> DictionaryObject: from ..types import BorderArrayType is_external = url is not None is_internal = target_page_index is not None if not is_external and not is_internal: raise ValueError( "Either 'url' or 'target_page_index' have to be provided. Both were None." ) if is_external and is_internal: raise ValueError( f"Either 'url' or 'target_page_index' have to be provided. url={url}, target_page_index={target_page_index}" ) border_arr: BorderArrayType if border is not None: border_arr = [NameObject(n) for n in border[:3]] if len(border) == 4: dash_pattern = ArrayObject([NameObject(n) for n in border[3]]) border_arr.append(dash_pattern) else: border_arr = [NumberObject(0)] * 3 link_obj = DictionaryObject( { NameObject("/Type"): NameObject("/Annot"), NameObject("/Subtype"): NameObject("/Link"), NameObject("/Rect"): RectangleObject(rect), NameObject("/Border"): ArrayObject(border_arr), } ) if is_external: link_obj[NameObject("/A")] = DictionaryObject( { NameObject("/S"): NameObject("/URI"), NameObject("/Type"): NameObject("/Action"), NameObject("/URI"): TextStringObject(url), } ) if is_internal: # This needs to be updated later! dest_deferred = DictionaryObject( { "target_page_index": NumberObject(target_page_index), "fit": NameObject(fit.fit_type), "fit_args": fit.fit_args, } ) link_obj[NameObject("/Dest")] = dest_deferred return link_obj
24,573
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_utils.py
hex_to_rgb
(value: str)
return tuple(int(value.lstrip("#")[i : i + 2], 16) / 255.0 for i in (0, 2, 4))
10
11
def hex_to_rgb(value: str) -> Tuple[float, float, float]: return tuple(int(value.lstrip("#")[i : i + 2], 16) / 255.0 for i in (0, 2, 4))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_utils.py#L10-L11
39
[ 0, 1 ]
100
[]
0
true
100
2
1
100
0
def hex_to_rgb(value: str) -> Tuple[float, float, float]: return tuple(int(value.lstrip("#")[i : i + 2], 16) / 255.0 for i in (0, 2, 4))
24,574
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_utils.py
read_hex_string_from_stream
( stream: StreamType, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, )
return create_string_object(b_(txt), forced_encoding)
14
35
def read_hex_string_from_stream( stream: StreamType, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union["TextStringObject", "ByteStringObject"]: stream.read(1) txt = "" x = b"" while True: tok = read_non_whitespace(stream) if not tok: raise PdfStreamError(STREAM_TRUNCATED_PREMATURELY) if tok == b">": break x += tok if len(x) == 2: txt += chr(int(x, base=16)) x = b"" if len(x) == 1: x += b"0" if len(x) == 2: txt += chr(int(x, base=16)) return create_string_object(b_(txt), forced_encoding)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_utils.py#L14-L35
39
[ 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
86.363636
[]
0
false
100
22
7
100
0
def read_hex_string_from_stream( stream: StreamType, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union["TextStringObject", "ByteStringObject"]: stream.read(1) txt = "" x = b"" while True: tok = read_non_whitespace(stream) if not tok: raise PdfStreamError(STREAM_TRUNCATED_PREMATURELY) if tok == b">": break x += tok if len(x) == 2: txt += chr(int(x, base=16)) x = b"" if len(x) == 1: x += b"0" if len(x) == 2: txt += chr(int(x, base=16)) return create_string_object(b_(txt), forced_encoding)
24,575
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_utils.py
read_string_from_stream
( stream: StreamType, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, )
return create_string_object(b"".join(txt), forced_encoding)
38
110
def read_string_from_stream( stream: StreamType, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union["TextStringObject", "ByteStringObject"]: tok = stream.read(1) parens = 1 txt = [] while True: tok = stream.read(1) if not tok: raise PdfStreamError(STREAM_TRUNCATED_PREMATURELY) if tok == b"(": parens += 1 elif tok == b")": parens -= 1 if parens == 0: break elif tok == b"\\": tok = stream.read(1) escape_dict = { b"n": b"\n", b"r": b"\r", b"t": b"\t", b"b": b"\b", b"f": b"\f", b"c": rb"\c", b"(": b"(", b")": b")", b"/": b"/", b"\\": b"\\", b" ": b" ", b"%": b"%", b"<": b"<", b">": b">", b"[": b"[", b"]": b"]", b"#": b"#", b"_": b"_", b"&": b"&", b"$": b"$", } try: tok = escape_dict[tok] except KeyError: if b"0" <= tok and tok <= b"7": # "The number ddd may consist of one, two, or three # octal digits; high-order overflow shall be ignored. # Three octal digits shall be used, with leading zeros # as needed, if the next character of the string is also # a digit." (PDF reference 7.3.4.2, p 16) for _ in range(2): ntok = stream.read(1) if b"0" <= ntok and ntok <= b"7": tok += ntok else: stream.seek(-1, 1) # ntok has to be analysed break tok = b_(chr(int(tok, base=8))) elif tok in b"\n\r": # This case is hit when a backslash followed by a line # break occurs. If it's a multi-char EOL, consume the # second character: tok = stream.read(1) if tok not in b"\n\r": stream.seek(-1, 1) # Then don't add anything to the actual string, since this # line break was escaped: tok = b"" else: msg = rf"Unexpected escaped string: {tok.decode('utf8')}" logger_warning(msg, __name__) txt.append(tok) return create_string_object(b"".join(txt), forced_encoding)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_utils.py#L38-L110
39
[ 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72 ]
64.383562
[]
0
false
100
73
15
100
0
def read_string_from_stream( stream: StreamType, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union["TextStringObject", "ByteStringObject"]: tok = stream.read(1) parens = 1 txt = [] while True: tok = stream.read(1) if not tok: raise PdfStreamError(STREAM_TRUNCATED_PREMATURELY) if tok == b"(": parens += 1 elif tok == b")": parens -= 1 if parens == 0: break elif tok == b"\\": tok = stream.read(1) escape_dict = { b"n": b"\n", b"r": b"\r", b"t": b"\t", b"b": b"\b", b"f": b"\f", b"c": rb"\c", b"(": b"(", b")": b")", b"/": b"/", b"\\": b"\\", b" ": b" ", b"%": b"%", b"<": b"<", b">": b">", b"[": b"[", b"]": b"]", b"#": b"#", b"_": b"_", b"&": b"&", b"$": b"$", } try: tok = escape_dict[tok] except KeyError: if b"0" <= tok and tok <= b"7": # "The number ddd may consist of one, two, or three # octal digits; high-order overflow shall be ignored. # Three octal digits shall be used, with leading zeros # as needed, if the next character of the string is also # a digit." (PDF reference 7.3.4.2, p 16) for _ in range(2): ntok = stream.read(1) if b"0" <= ntok and ntok <= b"7": tok += ntok else: stream.seek(-1, 1) # ntok has to be analysed break tok = b_(chr(int(tok, base=8))) elif tok in b"\n\r": # This case is hit when a backslash followed by a line # break occurs. If it's a multi-char EOL, consume the # second character: tok = stream.read(1) if tok not in b"\n\r": stream.seek(-1, 1) # Then don't add anything to the actual string, since this # line break was escaped: tok = b"" else: msg = rf"Unexpected escaped string: {tok.decode('utf8')}" logger_warning(msg, __name__) txt.append(tok) return create_string_object(b"".join(txt), forced_encoding)
24,576
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_utils.py
create_string_object
( string: Union[str, bytes], forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, )
Create a ByteStringObject or a TextStringObject from a string to represent the string. Args: string: forced_encoding: Returns: A ByteStringObject Raises: TypeError: If string is not of type str or bytes.
Create a ByteStringObject or a TextStringObject from a string to represent the string.
113
163
def create_string_object( string: Union[str, bytes], forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union[TextStringObject, ByteStringObject]: """ Create a ByteStringObject or a TextStringObject from a string to represent the string. Args: string: forced_encoding: Returns: A ByteStringObject Raises: TypeError: If string is not of type str or bytes. """ if isinstance(string, str): return TextStringObject(string) elif isinstance(string, bytes): if isinstance(forced_encoding, (list, dict)): out = "" for x in string: try: out += forced_encoding[x] except Exception: out += bytes((x,)).decode("charmap") return TextStringObject(out) elif isinstance(forced_encoding, str): if forced_encoding == "bytes": return ByteStringObject(string) return TextStringObject(string.decode(forced_encoding)) else: try: if string.startswith(codecs.BOM_UTF16_BE): retval = TextStringObject(string.decode("utf-16")) retval.autodetect_utf16 = True return retval else: # This is probably a big performance hit here, but we need to # convert string objects into the text/unicode-aware version if # possible... and the only way to check if that's possible is # to try. Some strings are strings, some are just byte arrays. retval = TextStringObject(decode_pdfdocencoding(string)) retval.autodetect_pdfdocencoding = True return retval except UnicodeDecodeError: return ByteStringObject(string) else: raise TypeError("create_string_object should have str or unicode arg")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_utils.py#L113-L163
39
[ 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50 ]
68.627451
[]
0
false
100
51
10
100
11
def create_string_object( string: Union[str, bytes], forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union[TextStringObject, ByteStringObject]: if isinstance(string, str): return TextStringObject(string) elif isinstance(string, bytes): if isinstance(forced_encoding, (list, dict)): out = "" for x in string: try: out += forced_encoding[x] except Exception: out += bytes((x,)).decode("charmap") return TextStringObject(out) elif isinstance(forced_encoding, str): if forced_encoding == "bytes": return ByteStringObject(string) return TextStringObject(string.decode(forced_encoding)) else: try: if string.startswith(codecs.BOM_UTF16_BE): retval = TextStringObject(string.decode("utf-16")) retval.autodetect_utf16 = True return retval else: # This is probably a big performance hit here, but we need to # convert string objects into the text/unicode-aware version if # possible... and the only way to check if that's possible is # to try. Some strings are strings, some are just byte arrays. retval = TextStringObject(decode_pdfdocencoding(string)) retval.autodetect_pdfdocencoding = True return retval except UnicodeDecodeError: return ByteStringObject(string) else: raise TypeError("create_string_object should have str or unicode arg")
24,577
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_utils.py
decode_pdfdocencoding
(byte_array: bytes)
return retval
166
179
def decode_pdfdocencoding(byte_array: bytes) -> str: retval = "" for b in byte_array: c = _pdfdoc_encoding[b] if c == "\u0000": raise UnicodeDecodeError( "pdfdocencoding", bytearray(b), -1, -1, "does not exist in translation table", ) retval += c return retval
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_utils.py#L166-L179
39
[ 0, 1, 2, 3, 4, 5, 12, 13 ]
57.142857
[]
0
false
100
14
3
100
0
def decode_pdfdocencoding(byte_array: bytes) -> str: retval = "" for b in byte_array: c = _pdfdoc_encoding[b] if c == "\u0000": raise UnicodeDecodeError( "pdfdocencoding", bytearray(b), -1, -1, "does not exist in translation table", ) retval += c return retval
24,578
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.__init__
( self, fit_type: str, fit_args: Tuple[Union[None, float, Any], ...] = tuple() )
5
14
def __init__( self, fit_type: str, fit_args: Tuple[Union[None, float, Any], ...] = tuple() ): from ._base import FloatObject, NameObject, NullObject self.fit_type = NameObject(fit_type) self.fit_args = [ NullObject() if a is None or isinstance(a, NullObject) else FloatObject(a) for a in fit_args ]
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L5-L14
39
[ 0, 3, 4, 5, 6 ]
50
[]
0
false
100
10
3
100
0
def __init__( self, fit_type: str, fit_args: Tuple[Union[None, float, Any], ...] = tuple() ): from ._base import FloatObject, NameObject, NullObject self.fit_type = NameObject(fit_type) self.fit_args = [ NullObject() if a is None or isinstance(a, NullObject) else FloatObject(a) for a in fit_args ]
24,579
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.xyz
( cls, left: Optional[float] = None, top: Optional[float] = None, zoom: Optional[float] = None, )
return Fit(fit_type="/XYZ", fit_args=(left, top, zoom))
Display the page designated by page, with the coordinates ( left , top ) positioned at the upper-left corner of the window and the contents of the page magnified by the factor zoom. A null value for any of the parameters left, top, or zoom specifies that the current value of that parameter is to be retained unchanged. A zoom value of 0 has the same meaning as a null value. Args: left: top: zoom: Returns: The created fit object.
Display the page designated by page, with the coordinates ( left , top ) positioned at the upper-left corner of the window and the contents of the page magnified by the factor zoom.
17
41
def xyz( cls, left: Optional[float] = None, top: Optional[float] = None, zoom: Optional[float] = None, ) -> "Fit": """ Display the page designated by page, with the coordinates ( left , top ) positioned at the upper-left corner of the window and the contents of the page magnified by the factor zoom. A null value for any of the parameters left, top, or zoom specifies that the current value of that parameter is to be retained unchanged. A zoom value of 0 has the same meaning as a null value. Args: left: top: zoom: Returns: The created fit object. """ return Fit(fit_type="/XYZ", fit_args=(left, top, zoom))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L17-L41
39
[ 0, 23, 24 ]
12
[]
0
false
100
25
1
100
16
def xyz( cls, left: Optional[float] = None, top: Optional[float] = None, zoom: Optional[float] = None, ) -> "Fit": return Fit(fit_type="/XYZ", fit_args=(left, top, zoom))
24,580
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.fit
(cls)
return Fit(fit_type="/Fit")
Display the page designated by page, with its contents magnified just enough to fit the entire page within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the page within the window in the other dimension.
Display the page designated by page, with its contents magnified just enough to fit the entire page within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the page within the window in the other dimension.
44
52
def fit(cls) -> "Fit": """ Display the page designated by page, with its contents magnified just enough to fit the entire page within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the page within the window in the other dimension. """ return Fit(fit_type="/Fit")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L44-L52
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
100
9
1
100
5
def fit(cls) -> "Fit": return Fit(fit_type="/Fit")
24,581
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.fit_horizontally
(cls, top: Optional[float] = None)
return Fit(fit_type="/FitH", fit_args=(top,))
Display the page designated by page , with the vertical coordinate top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of the page within the window. A null value for `top` specifies that the current value of that parameter is to be retained unchanged. Args: top: Returns: The created fit object.
Display the page designated by page , with the vertical coordinate top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of the page within the window.
55
71
def fit_horizontally(cls, top: Optional[float] = None) -> "Fit": """ Display the page designated by page , with the vertical coordinate top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of the page within the window. A null value for `top` specifies that the current value of that parameter is to be retained unchanged. Args: top: Returns: The created fit object. """ return Fit(fit_type="/FitH", fit_args=(top,))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L55-L71
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
100
17
1
100
13
def fit_horizontally(cls, top: Optional[float] = None) -> "Fit": return Fit(fit_type="/FitH", fit_args=(top,))
24,582
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.fit_vertically
(cls, left: Optional[float] = None)
return Fit(fit_type="/FitV", fit_args=(left,))
74
75
def fit_vertically(cls, left: Optional[float] = None) -> "Fit": return Fit(fit_type="/FitV", fit_args=(left,))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L74-L75
39
[ 0, 1 ]
100
[]
0
true
100
2
1
100
0
def fit_vertically(cls, left: Optional[float] = None) -> "Fit": return Fit(fit_type="/FitV", fit_args=(left,))
24,583
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.fit_rectangle
( cls, left: Optional[float] = None, bottom: Optional[float] = None, right: Optional[float] = None, top: Optional[float] = None, )
return Fit(fit_type="/FitR", fit_args=(left, bottom, right, top))
Display the page designated by page , with its contents magnified just enough to fit the rectangle specified by the coordinates left , bottom , right , and top entirely within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the rectangle within the window in the other dimension. A null value for any of the parameters may result in unpredictable behavior. Args: left: bottom: right: top: Returns: The created fit object.
Display the page designated by page , with its contents magnified just enough to fit the rectangle specified by the coordinates left , bottom , right , and top entirely within the window both horizontally and vertically.
78
107
def fit_rectangle( cls, left: Optional[float] = None, bottom: Optional[float] = None, right: Optional[float] = None, top: Optional[float] = None, ) -> "Fit": """ Display the page designated by page , with its contents magnified just enough to fit the rectangle specified by the coordinates left , bottom , right , and top entirely within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the rectangle within the window in the other dimension. A null value for any of the parameters may result in unpredictable behavior. Args: left: bottom: right: top: Returns: The created fit object. """ return Fit(fit_type="/FitR", fit_args=(left, bottom, right, top))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L78-L107
39
[ 0, 28, 29 ]
10
[]
0
false
100
30
1
100
20
def fit_rectangle( cls, left: Optional[float] = None, bottom: Optional[float] = None, right: Optional[float] = None, top: Optional[float] = None, ) -> "Fit": return Fit(fit_type="/FitR", fit_args=(left, bottom, right, top))
24,584
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.fit_box
(cls)
return Fit(fit_type="/FitB")
Display the page designated by page , with its contents magnified just enough to fit its bounding box entirely within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the bounding box within the window in the other dimension.
Display the page designated by page , with its contents magnified just enough to fit its bounding box entirely within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the bounding box within the window in the other dimension.
110
118
def fit_box(cls) -> "Fit": """ Display the page designated by page , with its contents magnified just enough to fit its bounding box entirely within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the bounding box within the window in the other dimension. """ return Fit(fit_type="/FitB")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L110-L118
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
100
9
1
100
5
def fit_box(cls) -> "Fit": return Fit(fit_type="/FitB")
24,585
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.fit_box_horizontally
(cls, top: Optional[float] = None)
return Fit(fit_type="/FitBH", fit_args=(top,))
Display the page designated by page , with the vertical coordinate top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of its bounding box within the window. A null value for top specifies that the current value of that parameter is to be retained unchanged. Args: top: Returns: The created fit object.
Display the page designated by page , with the vertical coordinate top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of its bounding box within the window.
121
137
def fit_box_horizontally(cls, top: Optional[float] = None) -> "Fit": """ Display the page designated by page , with the vertical coordinate top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of its bounding box within the window. A null value for top specifies that the current value of that parameter is to be retained unchanged. Args: top: Returns: The created fit object. """ return Fit(fit_type="/FitBH", fit_args=(top,))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L121-L137
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
100
17
1
100
13
def fit_box_horizontally(cls, top: Optional[float] = None) -> "Fit": return Fit(fit_type="/FitBH", fit_args=(top,))
24,586
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.fit_box_vertically
(cls, left: Optional[float] = None)
return Fit(fit_type="/FitBV", fit_args=(left,))
Display the page designated by page , with the horizontal coordinate left positioned at the left edge of the window and the contents of the page magnified just enough to fit the entire height of its bounding box within the window. A null value for left specifies that the current value of that parameter is to be retained unchanged. Args: left: Returns: The created fit object.
Display the page designated by page , with the horizontal coordinate left positioned at the left edge of the window and the contents of the page magnified just enough to fit the entire height of its bounding box within the window.
140
156
def fit_box_vertically(cls, left: Optional[float] = None) -> "Fit": """ Display the page designated by page , with the horizontal coordinate left positioned at the left edge of the window and the contents of the page magnified just enough to fit the entire height of its bounding box within the window. A null value for left specifies that the current value of that parameter is to be retained unchanged. Args: left: Returns: The created fit object. """ return Fit(fit_type="/FitBV", fit_args=(left,))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L140-L156
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]
100
[]
0
true
100
17
1
100
13
def fit_box_vertically(cls, left: Optional[float] = None) -> "Fit": return Fit(fit_type="/FitBV", fit_args=(left,))
24,587
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_fit.py
Fit.__str__
(self)
return f"Fit({self.fit_type}, {self.fit_args})"
158
161
def __str__(self) -> str: if not self.fit_args: return f"Fit({self.fit_type})" return f"Fit({self.fit_type}, {self.fit_args})"
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_fit.py#L158-L161
39
[]
0
[]
0
false
100
4
2
100
0
def __str__(self) -> str: if not self.fit_args: return f"Fit({self.fit_type})" return f"Fit({self.fit_type}, {self.fit_args})"
24,588
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_outline.py
OutlineItem.write_to_stream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
9
29
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: stream.write(b"<<\n") for key in [ NameObject(x) for x in ["/Title", "/Parent", "/First", "/Last", "/Next", "/Prev"] if x in self ]: key.write_to_stream(stream, encryption_key) stream.write(b" ") value = self.raw_get(key) value.write_to_stream(stream, encryption_key) stream.write(b"\n") key = NameObject("/Dest") key.write_to_stream(stream, encryption_key) stream.write(b" ") value = self.dest_array value.write_to_stream(stream, encryption_key) stream.write(b"\n") stream.write(b">>")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_outline.py#L9-L29
39
[ 0, 3, 4, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
71.428571
[]
0
false
100
21
3
100
0
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: stream.write(b"<<\n") for key in [ NameObject(x) for x in ["/Title", "/Parent", "/First", "/Last", "/Next", "/Prev"] if x in self ]: key.write_to_stream(stream, encryption_key) stream.write(b" ") value = self.raw_get(key) value.write_to_stream(stream, encryption_key) stream.write(b"\n") key = NameObject("/Dest") key.write_to_stream(stream, encryption_key) stream.write(b" ") value = self.dest_array value.write_to_stream(stream, encryption_key) stream.write(b"\n") stream.write(b">>")
24,589
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_outline.py
Bookmark.__init__
(self, *args: Any, **kwargs: Any)
33
35
def __init__(self, *args: Any, **kwargs: Any) -> None: deprecation_with_replacement("Bookmark", "OutlineItem", "3.0.0") super().__init__(*args, **kwargs)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_outline.py#L33-L35
39
[]
0
[]
0
false
100
3
1
100
0
def __init__(self, *args: Any, **kwargs: Any) -> None: deprecation_with_replacement("Bookmark", "OutlineItem", "3.0.0") super().__init__(*args, **kwargs)
24,590
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/__init__.py
readHexStringFromStream
( stream: StreamType, )
return read_hex_string_from_stream(stream)
73
79
def readHexStringFromStream( stream: StreamType, ) -> Union["TextStringObject", "ByteStringObject"]: # deprecated deprecate_with_replacement( "readHexStringFromStream", "read_hex_string_from_stream", "4.0.0" ) return read_hex_string_from_stream(stream)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/__init__.py#L73-L79
39
[]
0
[]
0
false
100
7
1
100
0
def readHexStringFromStream( stream: StreamType, ) -> Union["TextStringObject", "ByteStringObject"]: # deprecated deprecate_with_replacement( "readHexStringFromStream", "read_hex_string_from_stream", "4.0.0" ) return read_hex_string_from_stream(stream)
24,591
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/__init__.py
readStringFromStream
( stream: StreamType, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, )
return read_string_from_stream(stream, forced_encoding)
82
89
def readStringFromStream( stream: StreamType, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union["TextStringObject", "ByteStringObject"]: # deprecated deprecate_with_replacement( "readStringFromStream", "read_string_from_stream", "4.0.0" ) return read_string_from_stream(stream, forced_encoding)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/__init__.py#L82-L89
39
[]
0
[]
0
false
100
8
1
100
0
def readStringFromStream( stream: StreamType, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union["TextStringObject", "ByteStringObject"]: # deprecated deprecate_with_replacement( "readStringFromStream", "read_string_from_stream", "4.0.0" ) return read_string_from_stream(stream, forced_encoding)
24,592
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
_reset_node_tree_relationship
(child_obj: Any)
Call this after a node has been removed from a tree. This resets the nodes attributes in respect to that tree. Args: child_obj:
Call this after a node has been removed from a tree.
685
698
def _reset_node_tree_relationship(child_obj: Any) -> None: """ Call this after a node has been removed from a tree. This resets the nodes attributes in respect to that tree. Args: child_obj: """ del child_obj[NameObject("/Parent")] if NameObject("/Next") in child_obj: del child_obj[NameObject("/Next")] if NameObject("/Prev") in child_obj: del child_obj[NameObject("/Prev")]
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L685-L698
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
92.337917
14
3
100
6
def _reset_node_tree_relationship(child_obj: Any) -> None: del child_obj[NameObject("/Parent")] if NameObject("/Next") in child_obj: del child_obj[NameObject("/Next")] if NameObject("/Prev") in child_obj: del child_obj[NameObject("/Prev")]
24,593
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
read_object
( stream: StreamType, pdf: Any, # PdfReader forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, )
1,096
1,148
def read_object( stream: StreamType, pdf: Any, # PdfReader forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union[PdfObject, int, str, ContentStream]: tok = stream.read(1) stream.seek(-1, 1) # reset to start if tok == b"/": return NameObject.read_from_stream(stream, pdf) elif tok == b"<": # hexadecimal string OR dictionary peek = stream.read(2) stream.seek(-2, 1) # reset to start if peek == b"<<": return DictionaryObject.read_from_stream(stream, pdf, forced_encoding) else: return read_hex_string_from_stream(stream, forced_encoding) elif tok == b"[": return ArrayObject.read_from_stream(stream, pdf, forced_encoding) elif tok == b"t" or tok == b"f": return BooleanObject.read_from_stream(stream) elif tok == b"(": return read_string_from_stream(stream, forced_encoding) elif tok == b"e" and stream.read(6) == b"endobj": stream.seek(-6, 1) return NullObject() elif tok == b"n": return NullObject.read_from_stream(stream) elif tok == b"%": # comment while tok not in (b"\r", b"\n"): tok = stream.read(1) # Prevents an infinite loop by raising an error if the stream is at # the EOF if len(tok) <= 0: raise PdfStreamError("File ended unexpectedly.") tok = read_non_whitespace(stream) stream.seek(-1, 1) return read_object(stream, pdf, forced_encoding) elif tok in b"0123456789+-.": # number object OR indirect reference peek = stream.read(20) stream.seek(-len(peek), 1) # reset to start if IndirectPattern.match(peek) is not None: return IndirectObject.read_from_stream(stream, pdf) else: return NumberObject.read_from_stream(stream) else: stream.seek(-20, 1) raise PdfReadError( f"Invalid Elementary Object starting with {tok!r} @{stream.tell()}: {stream.read(80).__repr__()}" )
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L1096-L1148
39
[ 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 47, 49, 50 ]
83.018868
[]
0
false
92.337917
53
16
100
0
def read_object( stream: StreamType, pdf: Any, # PdfReader forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> Union[PdfObject, int, str, ContentStream]: tok = stream.read(1) stream.seek(-1, 1) # reset to start if tok == b"/": return NameObject.read_from_stream(stream, pdf) elif tok == b"<": # hexadecimal string OR dictionary peek = stream.read(2) stream.seek(-2, 1) # reset to start if peek == b"<<": return DictionaryObject.read_from_stream(stream, pdf, forced_encoding) else: return read_hex_string_from_stream(stream, forced_encoding) elif tok == b"[": return ArrayObject.read_from_stream(stream, pdf, forced_encoding) elif tok == b"t" or tok == b"f": return BooleanObject.read_from_stream(stream) elif tok == b"(": return read_string_from_stream(stream, forced_encoding) elif tok == b"e" and stream.read(6) == b"endobj": stream.seek(-6, 1) return NullObject() elif tok == b"n": return NullObject.read_from_stream(stream) elif tok == b"%": # comment while tok not in (b"\r", b"\n"): tok = stream.read(1) # Prevents an infinite loop by raising an error if the stream is at # the EOF if len(tok) <= 0: raise PdfStreamError("File ended unexpectedly.") tok = read_non_whitespace(stream) stream.seek(-1, 1) return read_object(stream, pdf, forced_encoding) elif tok in b"0123456789+-.": # number object OR indirect reference peek = stream.read(20) stream.seek(-len(peek), 1) # reset to start if IndirectPattern.match(peek) is not None: return IndirectObject.read_from_stream(stream, pdf) else: return NumberObject.read_from_stream(stream) else: stream.seek(-20, 1) raise PdfReadError( f"Invalid Elementary Object starting with {tok!r} @{stream.tell()}: {stream.read(80).__repr__()}" )
24,594
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
ArrayObject.clone
( self, pdf_dest: PdfWriterProtocol, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), )
return cast("ArrayObject", arr)
clone object into pdf_dest
clone object into pdf_dest
79
104
def clone( self, pdf_dest: PdfWriterProtocol, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "ArrayObject": """clone object into pdf_dest""" try: if self.indirect_reference.pdf == pdf_dest and not force_duplicate: # type: ignore return self except Exception: pass arr = cast("ArrayObject", self._reference_clone(ArrayObject(), pdf_dest)) for data in self: if isinstance(data, StreamObject): # if not hasattr(data, "indirect_reference"): # data.indirect_reference = None dup = data._reference_clone( data.clone(pdf_dest, force_duplicate, ignore_fields), pdf_dest ) arr.append(dup.indirect_reference) elif hasattr(data, "clone"): arr.append(data.clone(pdf_dest, force_duplicate, ignore_fields)) else: arr.append(data) return cast("ArrayObject", arr)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L79-L104
39
[ 0, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 21, 22, 23, 25 ]
57.692308
[ 9, 17, 20, 24 ]
15.384615
false
92.337917
26
7
84.615385
1
def clone( self, pdf_dest: PdfWriterProtocol, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "ArrayObject": try: if self.indirect_reference.pdf == pdf_dest and not force_duplicate: # type: ignore return self except Exception: pass arr = cast("ArrayObject", self._reference_clone(ArrayObject(), pdf_dest)) for data in self: if isinstance(data, StreamObject): # if not hasattr(data, "indirect_reference"): # data.indirect_reference = None dup = data._reference_clone( data.clone(pdf_dest, force_duplicate, ignore_fields), pdf_dest ) arr.append(dup.indirect_reference) elif hasattr(data, "clone"): arr.append(data.clone(pdf_dest, force_duplicate, ignore_fields)) else: arr.append(data) return cast("ArrayObject", arr)
24,595
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
ArrayObject.items
(self)
return enumerate(self)
Emulate DictionaryObject.items for a list (index, object)
Emulate DictionaryObject.items for a list (index, object)
106
111
def items(self) -> Iterable[Any]: """ Emulate DictionaryObject.items for a list (index, object) """ return enumerate(self)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L106-L111
39
[ 0, 1, 2, 3, 4 ]
83.333333
[ 5 ]
16.666667
false
92.337917
6
1
83.333333
2
def items(self) -> Iterable[Any]: return enumerate(self)
24,596
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
ArrayObject.write_to_stream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
113
120
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: stream.write(b"[") for data in self: stream.write(b" ") data.write_to_stream(stream, encryption_key) stream.write(b" ]")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L113-L120
39
[ 0, 3, 4, 5, 6, 7 ]
75
[]
0
false
92.337917
8
2
100
0
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: stream.write(b"[") for data in self: stream.write(b" ") data.write_to_stream(stream, encryption_key) stream.write(b" ]")
24,597
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
ArrayObject.writeToStream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
122
126
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L122-L126
39
[]
0
[]
0
false
92.337917
5
1
100
0
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
24,598
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
ArrayObject.read_from_stream
( stream: StreamType, pdf: Any, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, )
return arr
129
151
def read_from_stream( stream: StreamType, pdf: Any, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> "ArrayObject": # PdfReader arr = ArrayObject() tmp = stream.read(1) if tmp != b"[": raise PdfReadError("Could not read array") while True: # skip leading whitespace tok = stream.read(1) while tok.isspace(): tok = stream.read(1) stream.seek(-1, 1) # check for array ending peekahead = stream.read(1) if peekahead == b"]": break stream.seek(-1, 1) # read and append obj arr.append(read_object(stream, pdf, forced_encoding)) return arr
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L129-L151
39
[ 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 ]
82.608696
[]
0
false
92.337917
23
5
100
0
def read_from_stream( stream: StreamType, pdf: Any, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> "ArrayObject": # PdfReader arr = ArrayObject() tmp = stream.read(1) if tmp != b"[": raise PdfReadError("Could not read array") while True: # skip leading whitespace tok = stream.read(1) while tok.isspace(): tok = stream.read(1) stream.seek(-1, 1) # check for array ending peekahead = stream.read(1) if peekahead == b"]": break stream.seek(-1, 1) # read and append obj arr.append(read_object(stream, pdf, forced_encoding)) return arr
24,599
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
ArrayObject.readFromStream
( stream: StreamType, pdf: Any # PdfReader )
return ArrayObject.read_from_stream(stream, pdf)
154
158
def readFromStream( stream: StreamType, pdf: Any # PdfReader ) -> "ArrayObject": # deprecated deprecation_with_replacement("readFromStream", "read_from_stream", "3.0.0") return ArrayObject.read_from_stream(stream, pdf)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L154-L158
39
[]
0
[]
0
false
92.337917
5
1
100
0
def readFromStream( stream: StreamType, pdf: Any # PdfReader ) -> "ArrayObject": # deprecated deprecation_with_replacement("readFromStream", "read_from_stream", "3.0.0") return ArrayObject.read_from_stream(stream, pdf)
24,600
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.clone
( self, pdf_dest: PdfWriterProtocol, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), )
return d__
clone object into pdf_dest
clone object into pdf_dest
162
182
def clone( self, pdf_dest: PdfWriterProtocol, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "DictionaryObject": """clone object into pdf_dest""" try: if self.indirect_reference.pdf == pdf_dest and not force_duplicate: # type: ignore return self except Exception: pass d__ = cast( "DictionaryObject", self._reference_clone(self.__class__(), pdf_dest) ) if ignore_fields is None: ignore_fields = [] if len(d__.keys()) == 0: d__._clone(self, pdf_dest, force_duplicate, ignore_fields) return d__
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L162-L182
39
[ 0, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
76.190476
[]
0
false
92.337917
21
6
100
1
def clone( self, pdf_dest: PdfWriterProtocol, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "DictionaryObject": try: if self.indirect_reference.pdf == pdf_dest and not force_duplicate: # type: ignore return self except Exception: pass d__ = cast( "DictionaryObject", self._reference_clone(self.__class__(), pdf_dest) ) if ignore_fields is None: ignore_fields = [] if len(d__.keys()) == 0: d__._clone(self, pdf_dest, force_duplicate, ignore_fields) return d__
24,601
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject._clone
( self, src: "DictionaryObject", pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Union[Tuple[str, ...], List[str]], )
Update the object from src Args: src: "DictionaryObject": pdf_dest: force_duplicate: ignore_fields:
Update the object from src
184
254
def _clone( self, src: "DictionaryObject", pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Union[Tuple[str, ...], List[str]], ) -> None: """ Update the object from src Args: src: "DictionaryObject": pdf_dest: force_duplicate: ignore_fields: """ # First check if this is a chain list, we need to loop to prevent recur if ( ("/Next" not in ignore_fields and "/Next" in src) or ("/Prev" not in ignore_fields and "/Prev" in src) ) or ( ("/N" not in ignore_fields and "/N" in src) or ("/V" not in ignore_fields and "/V" in src) ): ignore_fields = list(ignore_fields) for lst in (("/Next", "/Prev"), ("/N", "/V")): for k in lst: objs = [] if ( k in src and k not in self and isinstance(src.raw_get(k), IndirectObject) ): cur_obj: Optional["DictionaryObject"] = cast( "DictionaryObject", src[k] ) prev_obj: Optional["DictionaryObject"] = self while cur_obj is not None: clon = cast( "DictionaryObject", cur_obj._reference_clone(cur_obj.__class__(), pdf_dest), ) objs.append((cur_obj, clon)) assert prev_obj is not None prev_obj[NameObject(k)] = clon.indirect_reference prev_obj = clon try: if cur_obj == src: cur_obj = None else: cur_obj = cast("DictionaryObject", cur_obj[k]) except Exception: cur_obj = None for (s, c) in objs: c._clone(s, pdf_dest, force_duplicate, ignore_fields + [k]) for k, v in src.items(): if k not in ignore_fields: if isinstance(v, StreamObject): if not hasattr(v, "indirect_reference"): v.indirect_reference = None vv = v.clone(pdf_dest, force_duplicate, ignore_fields) assert vv.indirect_reference is not None self[k.clone(pdf_dest)] = vv.indirect_reference # type: ignore[attr-defined] else: if k not in self: self[NameObject(k)] = ( v.clone(pdf_dest, force_duplicate, ignore_fields) if hasattr(v, "clone") else v )
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L184-L254
39
[ 0, 16, 17, 24, 25, 26, 27, 28, 33, 36, 37, 38, 42, 43, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 65, 66 ]
49.295775
[]
0
false
92.337917
71
25
100
7
def _clone( self, src: "DictionaryObject", pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Union[Tuple[str, ...], List[str]], ) -> None: # First check if this is a chain list, we need to loop to prevent recur if ( ("/Next" not in ignore_fields and "/Next" in src) or ("/Prev" not in ignore_fields and "/Prev" in src) ) or ( ("/N" not in ignore_fields and "/N" in src) or ("/V" not in ignore_fields and "/V" in src) ): ignore_fields = list(ignore_fields) for lst in (("/Next", "/Prev"), ("/N", "/V")): for k in lst: objs = [] if ( k in src and k not in self and isinstance(src.raw_get(k), IndirectObject) ): cur_obj: Optional["DictionaryObject"] = cast( "DictionaryObject", src[k] ) prev_obj: Optional["DictionaryObject"] = self while cur_obj is not None: clon = cast( "DictionaryObject", cur_obj._reference_clone(cur_obj.__class__(), pdf_dest), ) objs.append((cur_obj, clon)) assert prev_obj is not None prev_obj[NameObject(k)] = clon.indirect_reference prev_obj = clon try: if cur_obj == src: cur_obj = None else: cur_obj = cast("DictionaryObject", cur_obj[k]) except Exception: cur_obj = None for (s, c) in objs: c._clone(s, pdf_dest, force_duplicate, ignore_fields + [k]) for k, v in src.items(): if k not in ignore_fields: if isinstance(v, StreamObject): if not hasattr(v, "indirect_reference"): v.indirect_reference = None vv = v.clone(pdf_dest, force_duplicate, ignore_fields) assert vv.indirect_reference is not None self[k.clone(pdf_dest)] = vv.indirect_reference # type: ignore[attr-defined] else: if k not in self: self[NameObject(k)] = ( v.clone(pdf_dest, force_duplicate, ignore_fields) if hasattr(v, "clone") else v )
24,602
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.raw_get
(self, key: Any)
return dict.__getitem__(self, key)
256
257
def raw_get(self, key: Any) -> Any: return dict.__getitem__(self, key)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L256-L257
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def raw_get(self, key: Any) -> Any: return dict.__getitem__(self, key)
24,603
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.__setitem__
(self, key: Any, value: Any)
return dict.__setitem__(self, key, value)
259
264
def __setitem__(self, key: Any, value: Any) -> Any: if not isinstance(key, PdfObject): raise ValueError("key must be PdfObject") if not isinstance(value, PdfObject): raise ValueError("value must be PdfObject") return dict.__setitem__(self, key, value)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L259-L264
39
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
92.337917
6
3
100
0
def __setitem__(self, key: Any, value: Any) -> Any: if not isinstance(key, PdfObject): raise ValueError("key must be PdfObject") if not isinstance(value, PdfObject): raise ValueError("value must be PdfObject") return dict.__setitem__(self, key, value)
24,604
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.setdefault
(self, key: Any, value: Optional[Any] = None)
return dict.setdefault(self, key, value)
266
271
def setdefault(self, key: Any, value: Optional[Any] = None) -> Any: if not isinstance(key, PdfObject): raise ValueError("key must be PdfObject") if not isinstance(value, PdfObject): raise ValueError("value must be PdfObject") return dict.setdefault(self, key, value)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L266-L271
39
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
92.337917
6
3
100
0
def setdefault(self, key: Any, value: Optional[Any] = None) -> Any: if not isinstance(key, PdfObject): raise ValueError("key must be PdfObject") if not isinstance(value, PdfObject): raise ValueError("value must be PdfObject") return dict.setdefault(self, key, value)
24,605
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.__getitem__
(self, key: Any)
return dict.__getitem__(self, key).get_object()
273
274
def __getitem__(self, key: Any) -> PdfObject: return dict.__getitem__(self, key).get_object()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L273-L274
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def __getitem__(self, key: Any) -> PdfObject: return dict.__getitem__(self, key).get_object()
24,606
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.xmp_metadata
(self)
return metadata
Retrieve XMP (Extensible Metadata Platform) data relevant to the this object, if available. Stability: Added in v1.12, will exist for all future v1.x releases. Returns: Returns a {@link #xmp.XmpInformation XmlInformation} instance that can be used to access XMP metadata from the document. Can also return None if no metadata was found on the document root.
Retrieve XMP (Extensible Metadata Platform) data relevant to the this object, if available.
277
300
def xmp_metadata(self) -> Optional[PdfObject]: """ Retrieve XMP (Extensible Metadata Platform) data relevant to the this object, if available. Stability: Added in v1.12, will exist for all future v1.x releases. Returns: Returns a {@link #xmp.XmpInformation XmlInformation} instance that can be used to access XMP metadata from the document. Can also return None if no metadata was found on the document root. """ from ..xmp import XmpInformation metadata = self.get("/Metadata", None) if metadata is None: return None metadata = metadata.get_object() if not isinstance(metadata, XmpInformation): metadata = XmpInformation(metadata) self[NameObject("/Metadata")] = metadata return metadata
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L277-L300
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
100
[]
0
true
92.337917
24
3
100
9
def xmp_metadata(self) -> Optional[PdfObject]: from ..xmp import XmpInformation metadata = self.get("/Metadata", None) if metadata is None: return None metadata = metadata.get_object() if not isinstance(metadata, XmpInformation): metadata = XmpInformation(metadata) self[NameObject("/Metadata")] = metadata return metadata
24,607
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.getXmpMetadata
( self, )
return self.xmp_metadata
.. deprecated:: 1.28.3 Use :meth:`xmp_metadata` instead.
.. deprecated:: 1.28.3
302
311
def getXmpMetadata( self, ) -> Optional[PdfObject]: # deprecated """ .. deprecated:: 1.28.3 Use :meth:`xmp_metadata` instead. """ deprecation_with_replacement("getXmpMetadata", "xmp_metadata", "3.0.0") return self.xmp_metadata
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L302-L311
39
[]
0
[]
0
false
92.337917
10
1
100
3
def getXmpMetadata( self, ) -> Optional[PdfObject]: # deprecated deprecation_with_replacement("getXmpMetadata", "xmp_metadata", "3.0.0") return self.xmp_metadata
24,608
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.xmpMetadata
(self)
return self.xmp_metadata
.. deprecated:: 1.28.3 Use :meth:`xmp_metadata` instead.
.. deprecated:: 1.28.3
314
321
def xmpMetadata(self) -> Optional[PdfObject]: # deprecated """ .. deprecated:: 1.28.3 Use :meth:`xmp_metadata` instead. """ deprecation_with_replacement("xmpMetadata", "xmp_metadata", "3.0.0") return self.xmp_metadata
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L314-L321
39
[]
0
[]
0
false
92.337917
8
1
100
3
def xmpMetadata(self) -> Optional[PdfObject]: # deprecated deprecation_with_replacement("xmpMetadata", "xmp_metadata", "3.0.0") return self.xmp_metadata
24,609
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.write_to_stream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
323
332
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: stream.write(b"<<\n") for key, value in list(self.items()): key.write_to_stream(stream, encryption_key) stream.write(b" ") value.write_to_stream(stream, encryption_key) stream.write(b"\n") stream.write(b">>")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L323-L332
39
[ 0, 3, 4, 5, 6, 7, 8, 9 ]
80
[]
0
false
92.337917
10
2
100
0
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: stream.write(b"<<\n") for key, value in list(self.items()): key.write_to_stream(stream, encryption_key) stream.write(b" ") value.write_to_stream(stream, encryption_key) stream.write(b"\n") stream.write(b">>")
24,610
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.writeToStream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
334
338
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L334-L338
39
[]
0
[]
0
false
92.337917
5
1
100
0
def writeToStream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: # deprecated deprecation_with_replacement("writeToStream", "write_to_stream", "3.0.0") self.write_to_stream(stream, encryption_key)
24,611
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.read_from_stream
( stream: StreamType, pdf: Any, # PdfReader forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, )
341
474
def read_from_stream( stream: StreamType, pdf: Any, # PdfReader forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> "DictionaryObject": def get_next_obj_pos( p: int, p1: int, rem_gens: List[int], pdf: Any ) -> int: # PdfReader l = pdf.xref[rem_gens[0]] for o in l: if p1 > l[o] and p < l[o]: p1 = l[o] if len(rem_gens) == 1: return p1 else: return get_next_obj_pos(p, p1, rem_gens[1:], pdf) def read_unsized_from_steam(stream: StreamType, pdf: Any) -> bytes: # PdfReader # we are just pointing at beginning of the stream eon = get_next_obj_pos(stream.tell(), 2**32, list(pdf.xref), pdf) - 1 curr = stream.tell() rw = stream.read(eon - stream.tell()) p = rw.find(b"endstream") if p < 0: raise PdfReadError( f"Unable to find 'endstream' marker for obj starting at {curr}." ) stream.seek(curr + p + 9) return rw[: p - 1] tmp = stream.read(2) if tmp != b"<<": raise PdfReadError( f"Dictionary read error at byte {hex_str(stream.tell())}: " "stream must begin with '<<'" ) data: Dict[Any, Any] = {} while True: tok = read_non_whitespace(stream) if tok == b"\x00": continue elif tok == b"%": stream.seek(-1, 1) skip_over_comment(stream) continue if not tok: raise PdfStreamError(STREAM_TRUNCATED_PREMATURELY) if tok == b">": stream.read(1) break stream.seek(-1, 1) try: key = read_object(stream, pdf) tok = read_non_whitespace(stream) stream.seek(-1, 1) value = read_object(stream, pdf, forced_encoding) except Exception as exc: if pdf is not None and pdf.strict: raise PdfReadError(exc.__repr__()) logger_warning(exc.__repr__(), __name__) retval = DictionaryObject() retval.update(data) return retval # return partial data if not data.get(key): data[key] = value else: # multiple definitions of key not permitted msg = ( f"Multiple definitions in dictionary at byte " f"{hex_str(stream.tell())} for key {key}" ) if pdf is not None and pdf.strict: raise PdfReadError(msg) logger_warning(msg, __name__) pos = stream.tell() s = read_non_whitespace(stream) if s == b"s" and stream.read(5) == b"tream": eol = stream.read(1) # odd PDF file output has spaces after 'stream' keyword but before EOL. # patch provided by Danial Sandler while eol == b" ": eol = stream.read(1) if eol not in (b"\n", b"\r"): raise PdfStreamError("Stream data must be followed by a newline") if eol == b"\r": # read \n after if stream.read(1) != b"\n": stream.seek(-1, 1) # this is a stream object, not a dictionary if SA.LENGTH not in data: raise PdfStreamError("Stream length not defined") length = data[SA.LENGTH] if isinstance(length, IndirectObject): t = stream.tell() length = pdf.get_object(length) stream.seek(t, 0) pstart = stream.tell() data["__streamdata__"] = stream.read(length) e = read_non_whitespace(stream) ndstream = stream.read(8) if (e + ndstream) != b"endstream": # (sigh) - the odd PDF file has a length that is too long, so # we need to read backwards to find the "endstream" ending. # ReportLab (unknown version) generates files with this bug, # and Python users into PDF files tend to be our audience. # we need to do this to correct the streamdata and chop off # an extra character. pos = stream.tell() stream.seek(-10, 1) end = stream.read(9) if end == b"endstream": # we found it by looking back one character further. data["__streamdata__"] = data["__streamdata__"][:-1] elif not pdf.strict: stream.seek(pstart, 0) data["__streamdata__"] = read_unsized_from_steam(stream, pdf) pos = stream.tell() else: stream.seek(pos, 0) raise PdfReadError( "Unable to find 'endstream' marker after stream at byte " f"{hex_str(stream.tell())} (nd='{ndstream!r}', end='{end!r}')." ) else: stream.seek(pos, 0) if "__streamdata__" in data: return StreamObject.initialize_from_dictionary(data) else: retval = DictionaryObject() retval.update(data) return retval
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L341-L474
39
[ 0, 5, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 27, 28, 29, 30, 31, 32, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 64, 65, 66, 68, 69, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 121, 122, 127, 128, 129, 131, 132, 133 ]
76.119403
[ 24, 40, 57, 58, 59, 60, 61, 62, 63, 84 ]
7.462687
false
92.337917
134
32
92.537313
0
def read_from_stream( stream: StreamType, pdf: Any, # PdfReader forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> "DictionaryObject": def get_next_obj_pos( p: int, p1: int, rem_gens: List[int], pdf: Any ) -> int: # PdfReader l = pdf.xref[rem_gens[0]] for o in l: if p1 > l[o] and p < l[o]: p1 = l[o] if len(rem_gens) == 1: return p1 else: return get_next_obj_pos(p, p1, rem_gens[1:], pdf) def read_unsized_from_steam(stream: StreamType, pdf: Any) -> bytes: # PdfReader # we are just pointing at beginning of the stream eon = get_next_obj_pos(stream.tell(), 2**32, list(pdf.xref), pdf) - 1 curr = stream.tell() rw = stream.read(eon - stream.tell()) p = rw.find(b"endstream") if p < 0: raise PdfReadError( f"Unable to find 'endstream' marker for obj starting at {curr}." ) stream.seek(curr + p + 9) return rw[: p - 1] tmp = stream.read(2) if tmp != b"<<": raise PdfReadError( f"Dictionary read error at byte {hex_str(stream.tell())}: " "stream must begin with '<<'" ) data: Dict[Any, Any] = {} while True: tok = read_non_whitespace(stream) if tok == b"\x00": continue elif tok == b"%": stream.seek(-1, 1) skip_over_comment(stream) continue if not tok: raise PdfStreamError(STREAM_TRUNCATED_PREMATURELY) if tok == b">": stream.read(1) break stream.seek(-1, 1) try: key = read_object(stream, pdf) tok = read_non_whitespace(stream) stream.seek(-1, 1) value = read_object(stream, pdf, forced_encoding) except Exception as exc: if pdf is not None and pdf.strict: raise PdfReadError(exc.__repr__()) logger_warning(exc.__repr__(), __name__) retval = DictionaryObject() retval.update(data) return retval # return partial data if not data.get(key): data[key] = value else: # multiple definitions of key not permitted msg = ( f"Multiple definitions in dictionary at byte " f"{hex_str(stream.tell())} for key {key}" ) if pdf is not None and pdf.strict: raise PdfReadError(msg) logger_warning(msg, __name__) pos = stream.tell() s = read_non_whitespace(stream) if s == b"s" and stream.read(5) == b"tream": eol = stream.read(1) # odd PDF file output has spaces after 'stream' keyword but before EOL. # patch provided by Danial Sandler while eol == b" ": eol = stream.read(1) if eol not in (b"\n", b"\r"): raise PdfStreamError("Stream data must be followed by a newline") if eol == b"\r": # read \n after if stream.read(1) != b"\n": stream.seek(-1, 1) # this is a stream object, not a dictionary if SA.LENGTH not in data: raise PdfStreamError("Stream length not defined") length = data[SA.LENGTH] if isinstance(length, IndirectObject): t = stream.tell() length = pdf.get_object(length) stream.seek(t, 0) pstart = stream.tell() data["__streamdata__"] = stream.read(length) e = read_non_whitespace(stream) ndstream = stream.read(8) if (e + ndstream) != b"endstream": # (sigh) - the odd PDF file has a length that is too long, so # we need to read backwards to find the "endstream" ending. # ReportLab (unknown version) generates files with this bug, # and Python users into PDF files tend to be our audience. # we need to do this to correct the streamdata and chop off # an extra character. pos = stream.tell() stream.seek(-10, 1) end = stream.read(9) if end == b"endstream": # we found it by looking back one character further. data["__streamdata__"] = data["__streamdata__"][:-1] elif not pdf.strict: stream.seek(pstart, 0) data["__streamdata__"] = read_unsized_from_steam(stream, pdf) pos = stream.tell() else: stream.seek(pos, 0) raise PdfReadError( "Unable to find 'endstream' marker after stream at byte " f"{hex_str(stream.tell())} (nd='{ndstream!r}', end='{end!r}')." ) else: stream.seek(pos, 0) if "__streamdata__" in data: return StreamObject.initialize_from_dictionary(data) else: retval = DictionaryObject() retval.update(data) return retval
24,612
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DictionaryObject.readFromStream
( stream: StreamType, pdf: Any # PdfReader )
return DictionaryObject.read_from_stream(stream, pdf)
477
481
def readFromStream( stream: StreamType, pdf: Any # PdfReader ) -> "DictionaryObject": # deprecated deprecation_with_replacement("readFromStream", "read_from_stream", "3.0.0") return DictionaryObject.read_from_stream(stream, pdf)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L477-L481
39
[]
0
[]
0
false
92.337917
5
1
100
0
def readFromStream( stream: StreamType, pdf: Any # PdfReader ) -> "DictionaryObject": # deprecated deprecation_with_replacement("readFromStream", "read_from_stream", "3.0.0") return DictionaryObject.read_from_stream(stream, pdf)
24,613
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.__init__
(self)
485
486
def __init__(self) -> None: DictionaryObject.__init__(self)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L485-L486
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def __init__(self) -> None: DictionaryObject.__init__(self)
24,614
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.hasChildren
(self)
return self.has_children()
488
490
def hasChildren(self) -> bool: # deprecated deprecate_with_replacement("hasChildren", "has_children", "4.0.0") return self.has_children()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L488-L490
39
[]
0
[]
0
false
92.337917
3
1
100
0
def hasChildren(self) -> bool: # deprecated deprecate_with_replacement("hasChildren", "has_children", "4.0.0") return self.has_children()
24,615
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.has_children
(self)
return "/First" in self
492
493
def has_children(self) -> bool: return "/First" in self
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L492-L493
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def has_children(self) -> bool: return "/First" in self
24,616
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.__iter__
(self)
return self.children()
495
496
def __iter__(self) -> Any: return self.children()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L495-L496
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def __iter__(self) -> Any: return self.children()
24,617
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.children
(self)
498
511
def children(self) -> Iterable[Any]: if not self.has_children(): return child_ref = self[NameObject("/First")] child = child_ref.get_object() while True: yield child if child == self[NameObject("/Last")]: return child_ref = child.get(NameObject("/Next")) # type: ignore if child_ref is None: return child = child_ref.get_object()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L498-L511
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
92.337917
14
5
100
0
def children(self) -> Iterable[Any]: if not self.has_children(): return child_ref = self[NameObject("/First")] child = child_ref.get_object() while True: yield child if child == self[NameObject("/Last")]: return child_ref = child.get(NameObject("/Next")) # type: ignore if child_ref is None: return child = child_ref.get_object()
24,618
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.addChild
(self, child: Any, pdf: Any)
513
515
def addChild(self, child: Any, pdf: Any) -> None: # deprecated deprecation_with_replacement("addChild", "add_child", "3.0.0") self.add_child(child, pdf)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L513-L515
39
[]
0
[]
0
false
92.337917
3
1
100
0
def addChild(self, child: Any, pdf: Any) -> None: # deprecated deprecation_with_replacement("addChild", "add_child", "3.0.0") self.add_child(child, pdf)
24,619
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.add_child
(self, child: Any, pdf: PdfWriterProtocol)
517
518
def add_child(self, child: Any, pdf: PdfWriterProtocol) -> None: self.insert_child(child, None, pdf)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L517-L518
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def add_child(self, child: Any, pdf: PdfWriterProtocol) -> None: self.insert_child(child, None, pdf)
24,620
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.insert_child
(self, child: Any, before: Any, pdf: PdfWriterProtocol)
520
573
def insert_child(self, child: Any, before: Any, pdf: PdfWriterProtocol) -> None: def inc_parent_counter( parent: Union[None, IndirectObject, TreeObject], n: int ) -> None: if parent is None: return parent = cast("TreeObject", parent.get_object()) if "/Count" in parent: parent[NameObject("/Count")] = NumberObject( cast(int, parent[NameObject("/Count")]) + n ) inc_parent_counter(parent.get("/Parent", None), n) child_obj = child.get_object() child = child.indirect_reference # get_reference(child_obj) # assert isinstance(child, IndirectObject) prev: Optional[DictionaryObject] if "/First" not in self: # no child yet self[NameObject("/First")] = child self[NameObject("/Count")] = NumberObject(0) self[NameObject("/Last")] = child child_obj[NameObject("/Parent")] = self.indirect_reference inc_parent_counter(self, child_obj.get("/Count", 1)) if "/Next" in child_obj: del child_obj["/Next"] if "/Prev" in child_obj: del child_obj["/Prev"] return else: prev = cast("DictionaryObject", self["/Last"]) while prev.indirect_reference != before: if "/Next" in prev: prev = cast("TreeObject", prev["/Next"]) else: # append at the end prev[NameObject("/Next")] = cast("TreeObject", child) child_obj[NameObject("/Prev")] = prev.indirect_reference child_obj[NameObject("/Parent")] = self.indirect_reference if "/Next" in child_obj: del child_obj["/Next"] self[NameObject("/Last")] = child inc_parent_counter(self, child_obj.get("/Count", 1)) return try: # insert as first or in the middle assert isinstance(prev["/Prev"], DictionaryObject) prev["/Prev"][NameObject("/Next")] = child child_obj[NameObject("/Prev")] = prev["/Prev"] except Exception: # it means we are inserting in first position del child_obj["/Next"] child_obj[NameObject("/Next")] = prev prev[NameObject("/Prev")] = child child_obj[NameObject("/Parent")] = self.indirect_reference inc_parent_counter(self, child_obj.get("/Count", 1))
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L520-L573
39
[ 0, 1, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 26, 28, 30, 31, 32, 33, 36, 37, 38, 39, 40, 41, 42, 43 ]
62.962963
[ 25, 27, 34, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 ]
24.074074
false
92.337917
54
12
75.925926
0
def insert_child(self, child: Any, before: Any, pdf: PdfWriterProtocol) -> None: def inc_parent_counter( parent: Union[None, IndirectObject, TreeObject], n: int ) -> None: if parent is None: return parent = cast("TreeObject", parent.get_object()) if "/Count" in parent: parent[NameObject("/Count")] = NumberObject( cast(int, parent[NameObject("/Count")]) + n ) inc_parent_counter(parent.get("/Parent", None), n) child_obj = child.get_object() child = child.indirect_reference # get_reference(child_obj) # assert isinstance(child, IndirectObject) prev: Optional[DictionaryObject] if "/First" not in self: # no child yet self[NameObject("/First")] = child self[NameObject("/Count")] = NumberObject(0) self[NameObject("/Last")] = child child_obj[NameObject("/Parent")] = self.indirect_reference inc_parent_counter(self, child_obj.get("/Count", 1)) if "/Next" in child_obj: del child_obj["/Next"] if "/Prev" in child_obj: del child_obj["/Prev"] return else: prev = cast("DictionaryObject", self["/Last"]) while prev.indirect_reference != before: if "/Next" in prev: prev = cast("TreeObject", prev["/Next"]) else: # append at the end prev[NameObject("/Next")] = cast("TreeObject", child) child_obj[NameObject("/Prev")] = prev.indirect_reference child_obj[NameObject("/Parent")] = self.indirect_reference if "/Next" in child_obj: del child_obj["/Next"] self[NameObject("/Last")] = child inc_parent_counter(self, child_obj.get("/Count", 1)) return try: # insert as first or in the middle assert isinstance(prev["/Prev"], DictionaryObject) prev["/Prev"][NameObject("/Next")] = child child_obj[NameObject("/Prev")] = prev["/Prev"] except Exception: # it means we are inserting in first position del child_obj["/Next"] child_obj[NameObject("/Next")] = prev prev[NameObject("/Prev")] = child child_obj[NameObject("/Parent")] = self.indirect_reference inc_parent_counter(self, child_obj.get("/Count", 1))
24,621
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.removeChild
(self, child: Any)
575
577
def removeChild(self, child: Any) -> None: # deprecated deprecation_with_replacement("removeChild", "remove_child", "3.0.0") self.remove_child(child)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L575-L577
39
[]
0
[]
0
false
92.337917
3
1
100
0
def removeChild(self, child: Any) -> None: # deprecated deprecation_with_replacement("removeChild", "remove_child", "3.0.0") self.remove_child(child)
24,622
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject._remove_node_from_tree
( self, prev: Any, prev_ref: Any, cur: Any, last: Any )
Adjust the pointers of the linked list and tree node count. Args: prev: prev_ref: cur: last:
Adjust the pointers of the linked list and tree node count.
579
620
def _remove_node_from_tree( self, prev: Any, prev_ref: Any, cur: Any, last: Any ) -> None: """ Adjust the pointers of the linked list and tree node count. Args: prev: prev_ref: cur: last: """ next_ref = cur.get(NameObject("/Next"), None) if prev is None: if next_ref: # Removing first tree node next_obj = next_ref.get_object() del next_obj[NameObject("/Prev")] self[NameObject("/First")] = next_ref self[NameObject("/Count")] = NumberObject( self[NameObject("/Count")] - 1 # type: ignore ) else: # Removing only tree node assert self[NameObject("/Count")] == 1 del self[NameObject("/Count")] del self[NameObject("/First")] if NameObject("/Last") in self: del self[NameObject("/Last")] else: if next_ref: # Removing middle tree node next_obj = next_ref.get_object() next_obj[NameObject("/Prev")] = prev_ref prev[NameObject("/Next")] = next_ref else: # Removing last tree node assert cur == last del prev[NameObject("/Next")] self[NameObject("/Last")] = prev_ref self[NameObject("/Count")] = NumberObject(self[NameObject("/Count")] - 1)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L579-L620
39
[ 0, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41 ]
76.190476
[]
0
false
92.337917
42
7
100
7
def _remove_node_from_tree( self, prev: Any, prev_ref: Any, cur: Any, last: Any ) -> None: next_ref = cur.get(NameObject("/Next"), None) if prev is None: if next_ref: # Removing first tree node next_obj = next_ref.get_object() del next_obj[NameObject("/Prev")] self[NameObject("/First")] = next_ref self[NameObject("/Count")] = NumberObject( self[NameObject("/Count")] - 1 # type: ignore ) else: # Removing only tree node assert self[NameObject("/Count")] == 1 del self[NameObject("/Count")] del self[NameObject("/First")] if NameObject("/Last") in self: del self[NameObject("/Last")] else: if next_ref: # Removing middle tree node next_obj = next_ref.get_object() next_obj[NameObject("/Prev")] = prev_ref prev[NameObject("/Next")] = next_ref else: # Removing last tree node assert cur == last del prev[NameObject("/Next")] self[NameObject("/Last")] = prev_ref self[NameObject("/Count")] = NumberObject(self[NameObject("/Count")] - 1)
24,623
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.remove_child
(self, child: Any)
622
657
def remove_child(self, child: Any) -> None: child_obj = child.get_object() child = child_obj.indirect_reference if NameObject("/Parent") not in child_obj: raise ValueError("Removed child does not appear to be a tree item") elif child_obj[NameObject("/Parent")] != self: raise ValueError("Removed child is not a member of this tree") found = False prev_ref = None prev = None cur_ref: Optional[Any] = self[NameObject("/First")] cur: Optional[Dict[str, Any]] = cur_ref.get_object() # type: ignore last_ref = self[NameObject("/Last")] last = last_ref.get_object() while cur is not None: if cur == child_obj: self._remove_node_from_tree(prev, prev_ref, cur, last) found = True break # Go to the next node prev_ref = cur_ref prev = cur if NameObject("/Next") in cur: cur_ref = cur[NameObject("/Next")] cur = cur_ref.get_object() else: cur_ref = None cur = None if not found: raise ValueError("Removal couldn't find item in tree") _reset_node_tree_relationship(child_obj)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L622-L657
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35 ]
97.222222
[]
0
false
92.337917
36
7
100
0
def remove_child(self, child: Any) -> None: child_obj = child.get_object() child = child_obj.indirect_reference if NameObject("/Parent") not in child_obj: raise ValueError("Removed child does not appear to be a tree item") elif child_obj[NameObject("/Parent")] != self: raise ValueError("Removed child is not a member of this tree") found = False prev_ref = None prev = None cur_ref: Optional[Any] = self[NameObject("/First")] cur: Optional[Dict[str, Any]] = cur_ref.get_object() # type: ignore last_ref = self[NameObject("/Last")] last = last_ref.get_object() while cur is not None: if cur == child_obj: self._remove_node_from_tree(prev, prev_ref, cur, last) found = True break # Go to the next node prev_ref = cur_ref prev = cur if NameObject("/Next") in cur: cur_ref = cur[NameObject("/Next")] cur = cur_ref.get_object() else: cur_ref = None cur = None if not found: raise ValueError("Removal couldn't find item in tree") _reset_node_tree_relationship(child_obj)
24,624
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.remove_from_tree
(self)
remove the object from the tree it is in
remove the object from the tree it is in
659
666
def remove_from_tree(self) -> None: """ remove the object from the tree it is in """ if NameObject("/Parent") not in self: raise ValueError("Removed child does not appear to be a tree item") else: cast("TreeObject", self["/Parent"]).remove_child(self)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L659-L666
39
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
92.337917
8
2
100
1
def remove_from_tree(self) -> None: if NameObject("/Parent") not in self: raise ValueError("Removed child does not appear to be a tree item") else: cast("TreeObject", self["/Parent"]).remove_child(self)
24,625
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.emptyTree
(self)
668
670
def emptyTree(self) -> None: # deprecated deprecate_with_replacement("emptyTree", "empty_tree", "4.0.0") self.empty_tree()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L668-L670
39
[]
0
[]
0
false
92.337917
3
1
100
0
def emptyTree(self) -> None: # deprecated deprecate_with_replacement("emptyTree", "empty_tree", "4.0.0") self.empty_tree()
24,626
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
TreeObject.empty_tree
(self)
672
682
def empty_tree(self) -> None: for child in self: child_obj = child.get_object() _reset_node_tree_relationship(child_obj) if NameObject("/Count") in self: del self[NameObject("/Count")] if NameObject("/First") in self: del self[NameObject("/First")] if NameObject("/Last") in self: del self[NameObject("/Last")]
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L672-L682
39
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
92.337917
11
5
100
0
def empty_tree(self) -> None: for child in self: child_obj = child.get_object() _reset_node_tree_relationship(child_obj) if NameObject("/Count") in self: del self[NameObject("/Count")] if NameObject("/First") in self: del self[NameObject("/First")] if NameObject("/Last") in self: del self[NameObject("/Last")]
24,627
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject.__init__
(self)
702
704
def __init__(self) -> None: self.__data: Optional[str] = None self.decoded_self: Optional["DecodedStreamObject"] = None
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L702-L704
39
[ 0, 1, 2 ]
100
[]
0
true
92.337917
3
1
100
0
def __init__(self) -> None: self.__data: Optional[str] = None self.decoded_self: Optional["DecodedStreamObject"] = None
24,628
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject._clone
( self, src: DictionaryObject, pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Union[Tuple[str, ...], List[str]], )
return
Update the object from src. Args: src: pdf_dest: force_duplicate: ignore_fields:
Update the object from src.
706
732
def _clone( self, src: DictionaryObject, pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Union[Tuple[str, ...], List[str]], ) -> None: """ Update the object from src. Args: src: pdf_dest: force_duplicate: ignore_fields: """ self._data = cast("StreamObject", src)._data try: decoded_self = cast("StreamObject", src).decoded_self if decoded_self is None: self.decoded_self = None else: self.decoded_self = decoded_self.clone(pdf_dest, True, ignore_fields) # type: ignore[assignment] except Exception: pass super()._clone(src, pdf_dest, force_duplicate, ignore_fields) return
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L706-L732
39
[ 0, 15, 16, 17, 18, 19, 20, 21, 22, 25, 26 ]
40.740741
[ 23, 24 ]
7.407407
false
92.337917
27
3
92.592593
7
def _clone( self, src: DictionaryObject, pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Union[Tuple[str, ...], List[str]], ) -> None: self._data = cast("StreamObject", src)._data try: decoded_self = cast("StreamObject", src).decoded_self if decoded_self is None: self.decoded_self = None else: self.decoded_self = decoded_self.clone(pdf_dest, True, ignore_fields) # type: ignore[assignment] except Exception: pass super()._clone(src, pdf_dest, force_duplicate, ignore_fields) return
24,629
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject.hash_value_data
(self)
return data
734
737
def hash_value_data(self) -> bytes: data = super().hash_value_data() data += b_(self._data) return data
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L734-L737
39
[ 0, 1, 2, 3 ]
100
[]
0
true
92.337917
4
1
100
0
def hash_value_data(self) -> bytes: data = super().hash_value_data() data += b_(self._data) return data
24,630
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject.decodedSelf
(self)
return self.decoded_self
740
742
def decodedSelf(self) -> Optional["DecodedStreamObject"]: # deprecated deprecation_with_replacement("decodedSelf", "decoded_self", "3.0.0") return self.decoded_self
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L740-L742
39
[]
0
[]
0
false
92.337917
3
1
100
0
def decodedSelf(self) -> Optional["DecodedStreamObject"]: # deprecated deprecation_with_replacement("decodedSelf", "decoded_self", "3.0.0") return self.decoded_self
24,631
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject.decodedSelf
(self, value: "DecodedStreamObject")
745
747
def decodedSelf(self, value: "DecodedStreamObject") -> None: # deprecated deprecation_with_replacement("decodedSelf", "decoded_self", "3.0.0") self.decoded_self = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L745-L747
39
[]
0
[]
0
false
92.337917
3
1
100
0
def decodedSelf(self, value: "DecodedStreamObject") -> None: # deprecated deprecation_with_replacement("decodedSelf", "decoded_self", "3.0.0") self.decoded_self = value
24,632
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject._data
(self)
return self.__data
750
751
def _data(self) -> Any: return self.__data
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L750-L751
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def _data(self) -> Any: return self.__data
24,633
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject._data
(self, value: Any)
754
755
def _data(self, value: Any) -> None: self.__data = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L754-L755
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def _data(self, value: Any) -> None: self.__data = value
24,634
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject.write_to_stream
( self, stream: StreamType, encryption_key: Union[None, str, bytes] )
757
770
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: self[NameObject(SA.LENGTH)] = NumberObject(len(self._data)) DictionaryObject.write_to_stream(self, stream, encryption_key) del self[SA.LENGTH] stream.write(b"\nstream\n") data = self._data if encryption_key: from .._security import RC4_encrypt data = RC4_encrypt(encryption_key, data) stream.write(data) stream.write(b"\nendstream")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L757-L770
39
[ 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
85.714286
[]
0
false
92.337917
14
2
100
0
def write_to_stream( self, stream: StreamType, encryption_key: Union[None, str, bytes] ) -> None: self[NameObject(SA.LENGTH)] = NumberObject(len(self._data)) DictionaryObject.write_to_stream(self, stream, encryption_key) del self[SA.LENGTH] stream.write(b"\nstream\n") data = self._data if encryption_key: from .._security import RC4_encrypt data = RC4_encrypt(encryption_key, data) stream.write(data) stream.write(b"\nendstream")
24,635
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject.initializeFromDictionary
( data: Dict[str, Any] )
return StreamObject.initialize_from_dictionary(data)
773
776
def initializeFromDictionary( data: Dict[str, Any] ) -> Union["EncodedStreamObject", "DecodedStreamObject"]: # deprecated return StreamObject.initialize_from_dictionary(data)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L773-L776
39
[]
0
[]
0
false
92.337917
4
1
100
0
def initializeFromDictionary( data: Dict[str, Any] ) -> Union["EncodedStreamObject", "DecodedStreamObject"]: # deprecated return StreamObject.initialize_from_dictionary(data)
24,636
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject.initialize_from_dictionary
( data: Dict[str, Any] )
return retval
779
791
def initialize_from_dictionary( data: Dict[str, Any] ) -> Union["EncodedStreamObject", "DecodedStreamObject"]: retval: Union["EncodedStreamObject", "DecodedStreamObject"] if SA.FILTER in data: retval = EncodedStreamObject() else: retval = DecodedStreamObject() retval._data = data["__streamdata__"] del data["__streamdata__"] del data[SA.LENGTH] retval.update(data) return retval
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L779-L791
39
[ 0, 4, 5, 7, 8, 9, 10, 11, 12 ]
69.230769
[]
0
false
92.337917
13
2
100
0
def initialize_from_dictionary( data: Dict[str, Any] ) -> Union["EncodedStreamObject", "DecodedStreamObject"]: retval: Union["EncodedStreamObject", "DecodedStreamObject"] if SA.FILTER in data: retval = EncodedStreamObject() else: retval = DecodedStreamObject() retval._data = data["__streamdata__"] del data["__streamdata__"] del data[SA.LENGTH] retval.update(data) return retval
24,637
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject.flateEncode
(self)
return self.flate_encode()
793
795
def flateEncode(self) -> "EncodedStreamObject": # deprecated deprecation_with_replacement("flateEncode", "flate_encode", "3.0.0") return self.flate_encode()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L793-L795
39
[]
0
[]
0
false
92.337917
3
1
100
0
def flateEncode(self) -> "EncodedStreamObject": # deprecated deprecation_with_replacement("flateEncode", "flate_encode", "3.0.0") return self.flate_encode()
24,638
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
StreamObject.flate_encode
(self)
return retval
797
814
def flate_encode(self) -> "EncodedStreamObject": from ..filters import FlateDecode if SA.FILTER in self: f = self[SA.FILTER] if isinstance(f, ArrayObject): f.insert(0, NameObject(FT.FLATE_DECODE)) else: newf = ArrayObject() newf.append(NameObject("/FlateDecode")) newf.append(f) f = newf else: f = NameObject("/FlateDecode") retval = EncodedStreamObject() retval[NameObject(SA.FILTER)] = f retval._data = FlateDecode.encode(self._data) return retval
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L797-L814
39
[ 0, 1, 2, 3, 13, 14, 15, 16, 17 ]
50
[ 4, 5, 6, 8, 9, 10, 11 ]
38.888889
false
92.337917
18
3
61.111111
0
def flate_encode(self) -> "EncodedStreamObject": from ..filters import FlateDecode if SA.FILTER in self: f = self[SA.FILTER] if isinstance(f, ArrayObject): f.insert(0, NameObject(FT.FLATE_DECODE)) else: newf = ArrayObject() newf.append(NameObject("/FlateDecode")) newf.append(f) f = newf else: f = NameObject("/FlateDecode") retval = EncodedStreamObject() retval[NameObject(SA.FILTER)] = f retval._data = FlateDecode.encode(self._data) return retval
24,639
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DecodedStreamObject.get_data
(self)
return self._data
818
819
def get_data(self) -> Any: return self._data
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L818-L819
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def get_data(self) -> Any: return self._data
24,640
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DecodedStreamObject.set_data
(self, data: Any)
821
822
def set_data(self, data: Any) -> Any: self._data = data
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L821-L822
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def set_data(self, data: Any) -> Any: self._data = data
24,641
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DecodedStreamObject.getData
(self)
return self._data
824
826
def getData(self) -> Any: # deprecated deprecation_with_replacement("getData", "get_data", "3.0.0") return self._data
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L824-L826
39
[]
0
[]
0
false
92.337917
3
1
100
0
def getData(self) -> Any: # deprecated deprecation_with_replacement("getData", "get_data", "3.0.0") return self._data
24,642
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
DecodedStreamObject.setData
(self, data: Any)
828
830
def setData(self, data: Any) -> None: # deprecated deprecation_with_replacement("setData", "set_data", "3.0.0") self.set_data(data)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L828-L830
39
[]
0
[]
0
false
92.337917
3
1
100
0
def setData(self, data: Any) -> None: # deprecated deprecation_with_replacement("setData", "set_data", "3.0.0") self.set_data(data)
24,643
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
EncodedStreamObject.__init__
(self)
834
835
def __init__(self) -> None: self.decoded_self: Optional["DecodedStreamObject"] = None
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L834-L835
39
[ 0, 1 ]
100
[]
0
true
92.337917
2
1
100
0
def __init__(self) -> None: self.decoded_self: Optional["DecodedStreamObject"] = None
24,644
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
EncodedStreamObject.decodedSelf
(self)
return self.decoded_self
838
840
def decodedSelf(self) -> Optional["DecodedStreamObject"]: # deprecated deprecation_with_replacement("decodedSelf", "decoded_self", "3.0.0") return self.decoded_self
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L838-L840
39
[]
0
[]
0
false
92.337917
3
1
100
0
def decodedSelf(self) -> Optional["DecodedStreamObject"]: # deprecated deprecation_with_replacement("decodedSelf", "decoded_self", "3.0.0") return self.decoded_self
24,645
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
EncodedStreamObject.decodedSelf
(self, value: DecodedStreamObject)
843
845
def decodedSelf(self, value: DecodedStreamObject) -> None: # deprecated deprecation_with_replacement("decodedSelf", "decoded_self", "3.0.0") self.decoded_self = value
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L843-L845
39
[]
0
[]
0
false
92.337917
3
1
100
0
def decodedSelf(self, value: DecodedStreamObject) -> None: # deprecated deprecation_with_replacement("decodedSelf", "decoded_self", "3.0.0") self.decoded_self = value
24,646
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
EncodedStreamObject.get_data
(self)
847
862
def get_data(self) -> Union[None, str, bytes]: from ..filters import decode_stream_data if self.decoded_self is not None: # cached version of decoded object return self.decoded_self.get_data() else: # create decoded object decoded = DecodedStreamObject() decoded._data = decode_stream_data(self) for key, value in list(self.items()): if key not in (SA.LENGTH, SA.FILTER, SA.DECODE_PARMS): decoded[key] = value self.decoded_self = decoded return decoded._data
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L847-L862
39
[ 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
93.75
[]
0
false
92.337917
16
4
100
0
def get_data(self) -> Union[None, str, bytes]: from ..filters import decode_stream_data if self.decoded_self is not None: # cached version of decoded object return self.decoded_self.get_data() else: # create decoded object decoded = DecodedStreamObject() decoded._data = decode_stream_data(self) for key, value in list(self.items()): if key not in (SA.LENGTH, SA.FILTER, SA.DECODE_PARMS): decoded[key] = value self.decoded_self = decoded return decoded._data
24,647
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
EncodedStreamObject.getData
(self)
return self.get_data()
864
866
def getData(self) -> Union[None, str, bytes]: # deprecated deprecation_with_replacement("getData", "get_data", "3.0.0") return self.get_data()
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L864-L866
39
[]
0
[]
0
false
92.337917
3
1
100
0
def getData(self) -> Union[None, str, bytes]: # deprecated deprecation_with_replacement("getData", "get_data", "3.0.0") return self.get_data()
24,648
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
EncodedStreamObject.set_data
(self, data: Any)
868
869
def set_data(self, data: Any) -> None: # deprecated raise PdfReadError("Creating EncodedStreamObject is not currently supported")
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L868-L869
39
[]
0
[]
0
false
92.337917
2
1
100
0
def set_data(self, data: Any) -> None: # deprecated raise PdfReadError("Creating EncodedStreamObject is not currently supported")
24,649
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
EncodedStreamObject.setData
(self, data: Any)
return self.set_data(data)
871
873
def setData(self, data: Any) -> None: # deprecated deprecation_with_replacement("setData", "set_data", "3.0.0") return self.set_data(data)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L871-L873
39
[]
0
[]
0
false
92.337917
3
1
100
0
def setData(self, data: Any) -> None: # deprecated deprecation_with_replacement("setData", "set_data", "3.0.0") return self.set_data(data)
24,650
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
ContentStream.__init__
( self, stream: Any, pdf: Any, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, )
877
907
def __init__( self, stream: Any, pdf: Any, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> None: self.pdf = pdf # The inner list has two elements: # [0] : List # [1] : str self.operations: List[Tuple[Any, Any]] = [] # stream may be a StreamObject or an ArrayObject containing # multiple StreamObjects to be cat'd together. if stream is not None: stream = stream.get_object() if isinstance(stream, ArrayObject): data = b"" for s in stream: data += b_(s.get_object().get_data()) if len(data) == 0 or data[-1] != b"\n": data += b"\n" stream_bytes = BytesIO(data) else: stream_data = stream.get_data() assert stream_data is not None stream_data_bytes = b_(stream_data) stream_bytes = BytesIO(stream_data_bytes) self.forced_encoding = forced_encoding self.__parse_content_stream(stream_bytes)
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L877-L907
39
[ 0, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30 ]
80.645161
[]
0
false
92.337917
31
7
100
0
def __init__( self, stream: Any, pdf: Any, forced_encoding: Union[None, str, List[str], Dict[int, str]] = None, ) -> None: self.pdf = pdf # The inner list has two elements: # [0] : List # [1] : str self.operations: List[Tuple[Any, Any]] = [] # stream may be a StreamObject or an ArrayObject containing # multiple StreamObjects to be cat'd together. if stream is not None: stream = stream.get_object() if isinstance(stream, ArrayObject): data = b"" for s in stream: data += b_(s.get_object().get_data()) if len(data) == 0 or data[-1] != b"\n": data += b"\n" stream_bytes = BytesIO(data) else: stream_data = stream.get_data() assert stream_data is not None stream_data_bytes = b_(stream_data) stream_bytes = BytesIO(stream_data_bytes) self.forced_encoding = forced_encoding self.__parse_content_stream(stream_bytes)
24,651
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
ContentStream.clone
( self, pdf_dest: Any, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), )
return d__
Clone object into pdf_dest. Args: pdf_dest: force_duplicate: ignore_fields: Returns: The cloned ContentStream
Clone object into pdf_dest.
909
938
def clone( self, pdf_dest: Any, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "ContentStream": """ Clone object into pdf_dest. Args: pdf_dest: force_duplicate: ignore_fields: Returns: The cloned ContentStream """ try: if self.indirect_reference.pdf == pdf_dest and not force_duplicate: # type: ignore return self except Exception: pass d__ = cast( "ContentStream", self._reference_clone(self.__class__(None, None), pdf_dest) ) if ignore_fields is None: ignore_fields = [] d__._clone(self, pdf_dest, force_duplicate, ignore_fields) return d__
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L909-L938
39
[ 0, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 28, 29 ]
43.333333
[ 19, 27 ]
6.666667
false
92.337917
30
5
93.333333
9
def clone( self, pdf_dest: Any, force_duplicate: bool = False, ignore_fields: Union[Tuple[str, ...], List[str], None] = (), ) -> "ContentStream": try: if self.indirect_reference.pdf == pdf_dest and not force_duplicate: # type: ignore return self except Exception: pass d__ = cast( "ContentStream", self._reference_clone(self.__class__(None, None), pdf_dest) ) if ignore_fields is None: ignore_fields = [] d__._clone(self, pdf_dest, force_duplicate, ignore_fields) return d__
24,652
py-pdf/pypdf
d942a49074de9fb89ea374cd7f36f6d74a4a3451
pypdf/generic/_data_structures.py
ContentStream._clone
( self, src: DictionaryObject, pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Union[Tuple[str, ...], List[str]], )
return
Update the object from src. Args: src: pdf_dest: force_duplicate: ignore_fields:
Update the object from src.
940
961
def _clone( self, src: DictionaryObject, pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Union[Tuple[str, ...], List[str]], ) -> None: """ Update the object from src. Args: src: pdf_dest: force_duplicate: ignore_fields: """ self.pdf = pdf_dest self.operations = list(cast("ContentStream", src).operations) self.forced_encoding = cast("ContentStream", src).forced_encoding # no need to call DictionaryObjection or any # super(DictionaryObject,self)._clone(src, pdf_dest, force_duplicate, ignore_fields) return
https://github.com/py-pdf/pypdf/blob/d942a49074de9fb89ea374cd7f36f6d74a4a3451/project39/pypdf/generic/_data_structures.py#L940-L961
39
[ 0, 15, 16, 17, 18, 19, 20, 21 ]
36.363636
[]
0
false
92.337917
22
1
100
7
def _clone( self, src: DictionaryObject, pdf_dest: PdfWriterProtocol, force_duplicate: bool, ignore_fields: Union[Tuple[str, ...], List[str]], ) -> None: self.pdf = pdf_dest self.operations = list(cast("ContentStream", src).operations) self.forced_encoding = cast("ContentStream", src).forced_encoding # no need to call DictionaryObjection or any # super(DictionaryObject,self)._clone(src, pdf_dest, force_duplicate, ignore_fields) return
24,653