Ejemplo n.º 1
0
 def marked_content_property_list(self, txt) -> generic.DictionaryObject:
     result = generic.DictionaryObject({
         pdf_name('/ActualText'): generic.TextStringObject(txt)
     })
     if self.bcp47_lang_code is not None:
         result['/Lang'] = pdf_string(self.bcp47_lang_code)
     return result
Ejemplo n.º 2
0
def test_wrong_password(legacy):
    w = writer.PdfFileWriter()
    ref = w.add_object(generic.TextStringObject("Blah blah"))
    if legacy:
        sh = StandardSecurityHandler.build_from_pw_legacy(
            StandardSecuritySettingsRevision.RC4_OR_AES128,
            w._document_id[0].original_bytes,
            "ownersecret",
            "usersecret",
            keylen_bytes=16,
            use_aes128=True)
    else:
        sh = StandardSecurityHandler.build_from_pw("ownersecret", "usersecret")
    w.security_handler = sh
    w._encrypt = w.add_object(sh.as_pdf_object())
    out = BytesIO()
    w.write(out)
    r = PdfFileReader(out)
    with pytest.raises(misc.PdfReadError):
        r.get_object(ref.reference)
    assert r.decrypt("thispasswordiswrong") == AuthResult.FAILED
    assert r.security_handler._auth_failed
    assert r.security_handler.get_string_filter()._auth_failed
    with pytest.raises(misc.PdfReadError):
        r.get_object(ref.reference)
Ejemplo n.º 3
0
def test_preallocate():
    w = writer.PdfFileWriter()
    with pytest.raises(misc.PdfWriteError):
        w.add_object(generic.NullObject(), idnum=20)

    alloc = w.allocate_placeholder()
    assert isinstance(alloc.get_object(), generic.NullObject)
    w.add_object(generic.TextStringObject("Test Test"), idnum=alloc.idnum)
    assert alloc.get_object() == "Test Test"
Ejemplo n.º 4
0
 def get_object(self, ref, *_args, **_kwargs):
     if ref.idnum == 0:
         return generic.TextStringObject('OK')
     else:
         return generic.ArrayObject([generic.NumberObject(7)])