Пример #1
0
def test_simple_embed(incremental):
    if incremental:
        w = IncrementalPdfFileWriter(BytesIO(MINIMAL))
    else:
        r = PdfFileReader(BytesIO(MINIMAL))
        w = writer.copy_into_new_writer(r)

    modified = datetime.now(tz=tzlocal.get_localzone())
    created = modified - timedelta(days=1)
    _embed_test(w,
                fname='vector-test.pdf',
                ufname='テスト.pdf',
                data=VECTOR_IMAGE_PDF,
                created=created,
                modified=modified)

    out = BytesIO()
    w.write(out)

    r = PdfFileReader(out)
    assert r.input_version == (1, 7)
    emb_lst = r.root['/Names']['/EmbeddedFiles']['/Names']
    assert len(emb_lst) == 2
    assert emb_lst[0] == 'vector-test.pdf'
    spec_obj = emb_lst[1]
    assert spec_obj['/Desc'] == 'Embedding test'
    assert spec_obj['/UF'] == 'テスト.pdf'
    stream = spec_obj['/EF']['/F']
    assert stream.data == VECTOR_IMAGE_PDF

    assert stream['/Subtype'] == '/application/pdf'

    assert stream['/Params']['/CheckSum'] \
           == binascii.unhexlify('caaf24354fd2e68c08826d65b309b404')
    assert generic.parse_pdf_date(stream['/Params']['/ModDate']) == modified
    assert generic.parse_pdf_date(
        stream['/Params']['/CreationDate']) == created

    assert '/AF' not in r.root
Пример #2
0
    def self_reported_timestamp(self) -> Optional[datetime]:
        """
        :return:
            The signing time as reported by the signer, if embedded in the
            signature's signed attributes.
        """
        ts = extract_self_reported_ts(self.signer_info)
        if ts is not None:
            return ts

        try:
            st_as_pdf_date = self.sig_object['/M']
            return generic.parse_pdf_date(st_as_pdf_date)
        except KeyError:  # pragma: nocover
            pass
Пример #3
0
def test_date_parsing_errors(date_str):
    with pytest.raises(misc.PdfReadError):
        generic.parse_pdf_date(date_str)
Пример #4
0
def test_date_parsing(date_str, expected_dt):
    assert generic.parse_pdf_date(date_str) == expected_dt