
    h5j'                    h   U d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	 ddl
mZ ddlmZmZmZ erddl
mZ d	gZi d
ddddddddddddddddddddddddd d!d"d#d$d%d%d&d'i d(d)d*d+d,d-d.d/d0d1d2d2d3d4d5d6d7d8d9d:d;d;d<d=d>d?d@dAdBdBdCdDdEdFi dGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d]d^d_d`dadbdcdddedfdgi dhdidjdkdldldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddddddddi ddddddddddddddddddddddddddddddddddZded<    eh d      Z eh d      Z eej/                               ez  ez  ZdZddZddZddZ G d d	      Z	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)aM  A Pythonic builder for qpdf jobs.

qpdf exposes a large amount of functionality through its "job" interface: the
same operations the ``qpdf`` command line tool performs (encrypt, decrypt,
merge/split pages, linearize, compress, manage attachments, overlay/underlay,
and so on). pikepdf binds this as :class:`pikepdf.Job`, which accepts a job
specified as a JSON string, a Python ``dict``, or command line arguments.

Writing that JSON by hand is awkward: the keys are camelCase, the encryption
block has ``40bit``/``128bit``/``256bit`` variants with their own restriction
vocabulary, and permission flags are expressed as restrictions rather than
grants. :class:`JobBuilder` provides a fluent, snake_case, Pythonic API that
assembles a valid job specification and hands it to :class:`pikepdf.Job`.

qpdf's JSON job format is a complete representation of any job configuration --
``initializeFromJson``, ``initializeFromArgv`` and qpdf's own fluent C++
``config()`` builder all funnel through the same handlers -- so nothing is lost
by building the specification in Python.

Example:
    >>> from pikepdf import JobBuilder, Permissions
    >>> (
    ...     JobBuilder()
    ...     .input('in.pdf')
    ...     .output('out.pdf')
    ...     .encrypt(owner_password='secret', allow=Permissions(extract=False))
    ...     .run()
    ... )  # doctest: +SKIP
    )annotationsN)deepcopy)TYPE_CHECKINGAnyLiteral)Job)DEFAULT_PERMISSIONS
EncryptionPermissions)Pdf
JobBuilder
input_file	inputFilepasswordpassword_filepasswordFileempty
json_input	jsonInputoutput_file
outputFilereplace_inputreplaceInputqdfpreserve_unreferencedpreserveUnreferencednewline_before_endstreamnewlineBeforeEndstreamnormalize_contentnormalizeContentstream_data
streamDatacompress_streamscompressStreamsrecompress_flaterecompressFlatedecode_leveldecodeLeveldecryptdeterministic_iddeterministicIdstatic_aes_ivstaticAesIv	static_idstaticIdno_original_object_idsnoOriginalObjectIdscopy_encryptioncopyEncryptionencryption_file_passwordencryptionFilePassword	linearizelinearize_pass1linearizePass1object_streamsobjectStreamsmin_version
minVersionforce_versionforceVersionprogresssplit_pages
splitPagesjson_output
jsonOutputremove_restrictionsremoveRestrictionscheckcheck_linearizationcheckLinearizationfiltered_stream_datafilteredStreamDataraw_stream_datarawStreamDatashow_encryptionshowEncryptionshow_encryption_keyshowEncryptionKeyshow_linearizationshowLinearizationshow_npages
showNpagesshow_object
showObject
show_pages	showPages	show_xrefshowXrefwith_images
withImageslist_attachmentslistAttachmentsshow_attachmentshowAttachmentjsonjson_stream_datajsonStreamDatajson_stream_prefixjsonStreamPrefixupdate_from_jsonupdateFromJsonallow_weak_cryptoallowWeakCryptokeep_files_openkeepFilesOpenkeep_files_open_thresholdkeepFilesOpenThresholdno_warnnoWarnverbosetest_json_schematestJsonSchemaignore_xref_streamsignoreXrefStreamspassword_is_hex_keypasswordIsHexKeypassword_modepasswordModesuppress_password_recoverysuppressPasswordRecoverysuppress_recoverysuppressRecoverycoalesce_contentscoalesceContentscompression_levelcompressionLeveljpeg_qualityjpegQualityexternalize_inline_imagesexternalizeInlineImagesii_min_bytes
iiMinBytesremove_unreferenced_resourcesremoveUnreferencedResourcescollateflatten_annotationsflattenAnnotationsflatten_rotationflattenRotationgenerate_appearancesgenerateAppearanceskeep_inline_imageskeepInlineImagesoi_min_area	oiMinAreaoi_min_heightoiMinHeightoi_min_width
oiMinWidthoptimize_imagesoptimizeImagesremove_acroformremoveAcroformremove_info
removeInforemove_metadataremoveMetadataremove_page_labelsremovePageLabelsremove_structureremoveStructurereport_memory_usagereportMemoryUsagewarning_exit0warningExit0preserve_unreferenced_resourcespreserveUnreferencedResourcesrequires_passwordrequiresPasswordis_encryptedisEncrypteddict[str, str]_KEY_MAP>   form40bitprint128bit256bitmodifyuseAesencryptextractforceR5forceV4annotateassemblemodifyOtheruserPasswordaccessibilityallowInsecureownerPasswordcleartextMetadata>   tokeyfilefrompagesrangeglobalprefixrepeatrotatemoddateoverlayreplacefilenamemimetypeunderlaydescriptioncreationdateaddAttachmentsetPageLabelsnoDefaultLimitsparserMaxErrorsmaxStreamFiltersparserMaxNestingremoveAttachmentcopyAttachmentsFromparserMaxContainerSizeparserMaxContainerSizeDamaged c                    t        | t        j                        rt        j                  |       } t        | t              rt        j
                  |       S t        |       S )z9Coerce a path-like to the str form qpdf job JSON expects.)
isinstanceosPathLikefspathbytesfsdecodestr)ps    B/var/www/html/qr/venv/lib/python3.12/site-packages/pikepdf/jobs.py_pathr      s>    !R[[!IIaL!U{{1~q6M    c                    | rdS dS )Nyn )alloweds    r   _ynr      s    3"s"r   c                (    | dk\  ry| dk(  ry| dk(  ryy)zEMap an :class:`Encryption` security-handler revision to a key length.               (   r   )Rs    r   _bits_for_Rr      s#    AvAvAvr   c                     e Zd ZU dZded<   dBdZdddCdZdDdZdEd	ZdDd
Z		 dFdddddddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dGdZ
dDdZdDdZdDdZ	 dFdd	 	 	 	 	 	 	 dHdZdFdIdZdFdJdZdFdKdZdDdZdDdZddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 dLdZdddddd	 	 	 	 	 	 	 	 	 	 	 dMdZdddNdZ	 dO	 	 	 dPdZdDd ZdDd!ZdDd"ZdDd#ZdDd$ZdDd%ZdDd&ZdDd'ZdDd(Z dQd)Z!dRd*Z"dRd+Z#dDd,Z$dDd-Z%dd.dSd/Z&dddddddd0	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dTd1Z'ddd2	 	 	 	 	 	 	 dUd3Z(dVd4Z)ddddd5	 	 	 	 	 	 	 	 	 	 	 dWd6Z*ddddd5	 	 	 	 	 	 	 	 	 	 	 dWd7Z+ddddddd8	 	 	 	 	 	 	 	 	 	 	 	 	 dXd9Z,dYd:Z-dZd;Z.d[d<Z/d\d=Z0dd>d]d?Z1d^d@Z2d[dAZ3y)_r   a^  Fluently assemble a qpdf job and run it.

    Each method records part of the job specification and returns ``self`` so
    calls can be chained. List-valued sections (pages, attachments,
    overlay/underlay) use repeatable ``add_*`` methods. Terminal methods
    :meth:`build`, :meth:`run` and :meth:`create_pdf` hand the assembled
    specification to :class:`pikepdf.Job`.

    The builder performs minimal local validation; qpdf is the source of truth
    and will raise :class:`pikepdf.JobUsageError` (or ``RuntimeError`` for
    malformed JSON) for invalid configurations when the job is built.
    dict[str, Any]_specc                    i | _         y)z"Create an empty job specification.Nr   selfs    r   __init__zJobBuilder.__init__   s	    
r   N)r   c                   d| j                   v rt        d      t        |      | j                   d<   ||| j                   d<   | S )zSet the input file, optionally with a password.

        Args:
            file: Path to the input PDF.
            password: Password for an encrypted input file.
        r   z&Cannot set an input file after empty()r   r   )r   
ValueErrorr   )r  r   r   s      r   inputzJobBuilder.input   sG     djj EFF"'+

;%-DJJz"r   c                ^    d| j                   v rt        d      t        | j                   d<   | S )z3Use an empty PDF as input instead of an input file.r   z,Cannot use empty() when an input file is setr   )r   r  _ENABLEr   s    r   r   zJobBuilder.empty  s-    $**$KLL%

7r   c                6    t        |      | j                  d<   | S )zSet the output file.

        Args:
            file: Path to write. For :meth:`split_pages`, include a ``%d``
                placeholder for the page group number.
        r   )r   r   )r  r   s     r   outputzJobBuilder.output  s     $);

< r   c                ,    t         | j                  d<   | S )z4Overwrite the input file with the output (in place).r   r  r   r   s    r   r   zJobBuilder.replace_input  s    %,

>"r   r   TF)	owner_passworduser_passwordbitsallowmetadataaesforce_v4allow_insecureforce_r5c       	        ~   |qt        d |||fD              rt        d      |j                  }|j                  }|j                  }|j
                  }|j                  }t        |j                        }|dvrt        d      |t        }| d}d|xs dd|xs d|t        ||||||	|
	      i| j                  d
<   | S )a  Encrypt the output.

        Either pass a :class:`pikepdf.Encryption` object positionally, or use
        the keyword arguments. The two forms are mutually exclusive.

        Args:
            encryption: A :class:`pikepdf.Encryption` describing passwords,
                permissions and algorithm. If given, the keyword arguments
                must not be used.
            owner_password: Owner password (full access).
            user_password: User password (restricted access).
            bits: Key length: 40, 128 or 256 (default). 40 and 128-bit RC4
                are weak and require :meth:`allow_weak_crypto`.
            allow: A :class:`pikepdf.Permissions` describing what the user
                password is permitted to do. Permissions default to
                :data:`pikepdf.models.encryption.DEFAULT_PERMISSIONS`.
            metadata: If False, document metadata is left unencrypted
                (128/256-bit only).
            aes: For 128-bit, request AES rather than RC4.
            force_v4: For 128-bit, force ``V=4`` in the encryption dictionary.
            allow_insecure: For 256-bit, allow an insecure empty owner password.
            force_r5: For 256-bit, use the deprecated ``R=5`` algorithm.
        c              3  $   K   | ]  }|d u 
 y wNr   ).0vs     r   	<genexpr>z%JobBuilder.encrypt.<locals>.<genexpr>I  s     QQ1D=Qs   z?Pass either an Encryption object or keyword arguments, not both)r   r   r   zbits must be 40, 128 or 256bitr   r   r   )r  r  r  r  r  r   )anyr  owneruserr  r  r  r   r   r	   _encrypt_flagsr   )r  
encryptionr  r  r  r  r  r  r  r  r  variants               r   r   zJobBuilder.encrypt#  s    J !Q>=%*PQQ U  (--N&OOM$$E!**H..Cz||,D~%:;;='EF#,M/R^1r^!!-!!


9 r   c                ,    t         | j                  d<   | S )z&Remove encryption from the input file.r)   r  r   s    r   r)   zJobBuilder.decrypti  s     '

9r   c                ,    t         | j                  d<   | S )zFRemove security restrictions, recovering the encryption key if needed.rE   r  r   s    r   rD   zJobBuilder.remove_restrictionsn  s    +2

'(r   c                ,    t         | j                  d<   | S )z2Permit writing files with weak (RC4) cryptography.ri   r  r   s    r   rh   zJobBuilder.allow_weak_cryptos      (/

$%r   c                   dt        |      i}|||d<   |||d<   | j                  j                  dg       j                  |       | S )ab  Append pages from a file to the page-selection (merge/split) operation.

        Args:
            file: Source PDF. Use ``'.'`` to refer to the primary input file.
            page_range: qpdf page range, e.g. ``'1-5'`` or ``'z-1'`` (reversed).
                Omit to use all pages.
            password: Password for an encrypted source file.
        r   r   r   r   r   r   
setdefaultappend)r  r   
page_ranger   entrys        r   	add_pageszJobBuilder.add_pagesz  sU     "(t 5!'E'N (E*

gr*11%8r   c                >    |dn
t        |      | j                  d<   | S )zWrite pages to separate files.

        Args:
            group: Number of pages per output file. The output filename should
                contain a ``%d`` placeholder.
        r   rA   r   r   )r  groups     r   r@   zJobBuilder.split_pages  s!     */2CJ

< r   c                >    |dn
t        |      | j                  d<   | S )zCollate rather than concatenate the page selection.

        Args:
            n: Number of pages to take from each file per round.
        r   r   r.  )r  r   s     r   r   zJobBuilder.collate  s!     '(iSV

9r   c                    |t        |      n| d| }| j                  j                  dg       j                  |       | S )a  Rotate pages.

        Args:
            angle: Rotation in degrees: ``90``, ``180``, ``270``; prefix with
                ``+`` or ``-`` to rotate relative to the current rotation.
            page_range: Page range to rotate. Omit to rotate all pages.
        :r   )r   r   r(  r)  )r  angler*  specs       r   r   zJobBuilder.rotate  sC     (/s5zwa
|5L

h+2248r   c                ,    t         | j                  d<   | S )z$Linearize (web-optimize) the output.r6   r  r   s    r   r6   zJobBuilder.linearize  s    ")

;r   c                ,    t         | j                  d<   | S )z<Produce QDF output suitable for inspection in a text editor.r   r  r   s    r   r   zJobBuilder.qdf  s    #

5r   )r#   r9   r%   r   r'   r!   c                   |t        |      | j                  d<   ||| j                  d<   |rt        | j                  d<   |t        |      | j                  d<   ||| j                  d<   ||| j                  d<   | S )a  Configure stream and object-stream compression.

        Args:
            compress_streams: Compress uncompressed streams.
            object_streams: Control use of object streams.
            recompress_flate: Uncompress and recompress flate streams.
            compression_level: Flate compression level (1-9).
            decode_level: Which streams to uncompress before recompressing.
            stream_data: Legacy combined stream compression control.
        r$   r:   r&   r   r(   r"   )r   r   r  r   )r  r#   r9   r%   r   r'   r!   s          r   compresszJobBuilder.compress  s    * ',/0@,ADJJ()%*8DJJ',3DJJ()(-01B-CDJJ)*#(4DJJ}%"'2DJJ|$r   )min_area	min_width
min_heightr   r   c               &   t         | j                  d<   |t        |      | j                  d<   |t        |      | j                  d<   |t        |      | j                  d<   |rt         | j                  d<   |t        |      | j                  d<   | S )a  Recompress images using more efficient compression where possible.

        Args:
            min_area: Skip images smaller than this many pixels in area.
            min_width: Skip images narrower than this many pixels.
            min_height: Skip images shorter than this many pixels.
            keep_inline_images: Also consider inline images (excluded by default).
            jpeg_quality: JPEG quality level to use when recompressing.
        r   r   r   r   r   r   r  r   r   )r  r9  r:  r;  r   r   s         r   r   zJobBuilder.optimize_images  s    $ (/

#$&)(mDJJ{# '*9~DJJ|$!(+JDJJ}%-4DJJ)*#(+L(9DJJ}%r   )	min_bytesc               `    t         | j                  d<   |t        |      | j                  d<   | S )zConvert inline images to regular (external) images.

        Args:
            min_bytes: Only externalize inline images at least this large.
        r   r   r=  )r  r>  s     r   r   z$JobBuilder.externalize_inline_images  s0     18

,- '*9~DJJ|$r   c                $    || j                   d<   | S )a  Push annotations into page content streams.

        Args:
            mode: Which annotations to flatten: ``'all'`` (default), ``'print'``
                (only those marked for printing) or ``'screen'`` (exclude those
                marked hidden on screen).
        r   r   )r  modes     r   r   zJobBuilder.flatten_annotations  s     ,0

'(r   c                ,    t         | j                  d<   | S )z;Bake each page's ``/Rotate`` value into its content stream.r   r  r   s    r   r   zJobBuilder.flatten_rotation  r%  r   c                ,    t         | j                  d<   | S )z;Generate appearance streams for form fields that lack them.r   r  r   s    r   r   zJobBuilder.generate_appearances  s    ,3

()r   c                ,    t         | j                  d<   | S )z3Combine a page's multiple content streams into one.r~   r  r   s    r   r}   zJobBuilder.coalesce_contents      )0

%&r   c                ,    t         | j                  d<   | S )zCNormalize newlines in content streams (for readability/inspection).r    r  r   s    r   r   zJobBuilder.normalize_content#  rE  r   c                ,    t         | j                  d<   | S )z*Remove the document's XMP metadata stream.r   r  r   s    r   r   zJobBuilder.remove_metadata*      '.

#$r   c                ,    t         | j                  d<   | S )z+Remove the document information dictionary.r   r  r   s    r   r   zJobBuilder.remove_info/  s    #*

< r   c                ,    t         | j                  d<   | S )z2Remove the interactive form (AcroForm) dictionary.r   r  r   s    r   r   zJobBuilder.remove_acroform4  rH  r   c                ,    t         | j                  d<   | S )z/Remove the document's structure (tagging) tree.r   r  r   s    r   r   zJobBuilder.remove_structure9  r%  r   c                ,    t         | j                  d<   | S )z-Remove explicit page labels (page numbering).r   r  r   s    r   r   zJobBuilder.remove_page_labels>  rE  r   c                6    t        |      | j                  d<   | S )a  Set page labels (explicit page numbering) for the whole document.

        Args:
            labels: A list of qpdf label specs of the form
                ``first-page:[type][/start[/prefix]]``, e.g. ``['1:r', '5:D/1']``
                to number the first four pages with lower-case Roman numerals and
                restart with Arabic numerals from page 5. The first spec must
                start at page 1.
        r   )listr   )r  labelss     r   set_page_labelszJobBuilder.set_page_labelsE  s     '+6l

?#r   c                $    || j                   d<   | S )zSet the minimum PDF version of the output.

        Args:
            version: A PDF version such as ``'1.7'``, optionally with an
                extension level as ``'1.7:8'``.
        r<   r   r  versions     r   r;   zJobBuilder.min_versionT  s     $+

< r   c                $    || j                   d<   | S )zForce the output PDF version, even if features require a higher one.

        Args:
            version: A PDF version such as ``'1.7'``, optionally with an
                extension level as ``'1.7:8'``.
        r>   r   rR  s     r   r=   zJobBuilder.force_version^  s     &-

>"r   c                ,    t         | j                  d<   | S )zDGenerate the document ID deterministically from the output contents.r+   r  r   s    r   r*   zJobBuilder.deterministic_idj  r%  r   c                ,    t         | j                  d<   | S )zAUse a fixed document ID (for testing; not for production output).r/   r  r   s    r   r.   zJobBuilder.static_ido  s    !(

:r   )linearizationc               V    t         | j                  d<   |rt         | j                  d<   | S )zCheck the PDF for problems, reporting via the job's output.

        Args:
            linearization: Also check the linearization (hint) tables.
        rF   rH   r  )r  rW  s     r   rF   zJobBuilder.checkt  s)     &

7/6DJJ+,r   )r   r   r   r   r   r   r   c                   dt        |      i}	|||	d<   |||	d<   |||	d<   |||	d<   |||	d<   |||	d<   |r	t        |	d<   | j                  j                  d	g       j	                  |	       | S )
a  Attach (embed) a file in the output.

        Args:
            file: Path to the file to attach.
            key: Attachment key; defaults to the filename.
            filename: Displayed filename of the attachment.
            mimetype: MIME type, e.g. ``'application/pdf'``.
            description: Human-readable description.
            creationdate: Creation date (PDF date string).
            moddate: Modification date (PDF date string).
            replace: Replace an existing attachment with the same key.
        r   r   r   r   r   r   r   r   r   )r   r  r   r(  r)  )
r  r   r   r   r   r   r   r   r   r+  s
             r   add_attachmentzJobBuilder.add_attachment  s    0 "(t 5?E%L (E* (E*"#.E- #$0E.!&E)&E)

or299%@r   )r   r   c                   dt        |      i}|||d<   |||d<   | j                  j                  dg       j                  |       | S )a  Copy all attachments from another PDF.

        Args:
            file: Source PDF to copy attachments from.
            prefix: Prefix to disambiguate keys that collide with existing ones.
            password: Password for an encrypted source file.
        r   r   r   r   r'  )r  r   r   r   r+  s        r   copy_attachments_fromz JobBuilder.copy_attachments_from  sV     "(t 5$E(O (E*

3R8??Fr   c                \    | j                   j                  dg       j                  |       | S )zbRemove an embedded file by key.

        Args:
            key: Attachment key to remove.
        r   )r   r(  r)  )r  r   s     r   remove_attachmentzJobBuilder.remove_attachment  s)     	

0"5<<SAr   )r   from_r   r   c          	     v    | j                   j                  dg       j                  t        |||||             | S )au  Overlay pages from another file on top of the output pages.

        Args:
            file: Source PDF for the overlay.
            to: Destination page range in the output.
            from_: Source page range in ``file``.
            repeat: Source pages to repeat across remaining destination pages.
            password: Password for an encrypted source file.
        r   r   r(  r)  _underlay_overlay_entryr  r   r   r_  r   r   s         r   add_overlayzJobBuilder.add_overlay  s:    $ 	

i,33#D"eVXF	
 r   c          	     v    | j                   j                  dg       j                  t        |||||             | S )zUnderlay pages from another file beneath the output pages.

        See :meth:`add_overlay` for argument descriptions.
        r   ra  rc  s         r   add_underlayzJobBuilder.add_underlay  s:     	

j"-44#D"eVXF	
 r   )no_default_limitsparser_max_container_size!parser_max_container_size_damagedparser_max_errorsparser_max_nestingmax_stream_filtersc                   | j                   j                  di       }|r	t        |d<   |t        |      |d<   |t        |      |d<   |t        |      |d<   |t        |      |d<   |t        |      |d<   | S )aA  Set global parser limits (useful for hardening against malicious PDFs).

        Args:
            no_default_limits: Disable qpdf's optional default limits.
            parser_max_container_size: Maximum container size while parsing.
            parser_max_container_size_damaged: Maximum container size while
                parsing damaged files.
            parser_max_errors: Maximum number of errors before giving up.
            parser_max_nesting: Maximum object nesting depth.
            max_stream_filters: Maximum number of filters when filtering a stream.
        r   r   r   r   r   r   r   )r   r(  r  r   )r  rg  rh  ri  rj  rk  rl  gs           r   limitszJobBuilder.limits  s    * !JJ11(B?#*A $0*-.G*HA&',8145V1WA-.(#&'8#9A )$'(:$;A !)$'(:$;A !r   c                    |j                         D ];  \  }}	 t        |   }|du rt        | j
                  |<   (|du r-|| j
                  |<   = | S # t        $ r t        d|      dw xY w)a  Set arbitrary scalar top-level options not covered by other methods.

        Keyword names are snake_case Python aliases for qpdf's camelCase job
        keys (e.g. ``no_warn`` -> ``noWarn``). A boolean ``True`` enables a
        flag (emitted as an empty string); other values are stringified.

        Args:
            **kwargs: Option names and values.

        Raises:
            ValueError: If a keyword does not correspond to a known option.
        zUnknown job option: NTF)itemsr   KeyErrorr  r  r   )r  kwargsnamevaluejson_keys        r   setzJobBuilder.set  s     "<<> 
	-KD%L#D> }'.

8$%',

8$
	-   L #7x!@AtKLs   	AA*c                ,    t        | j                        S )z@Return a deep copy of the assembled job specification as a dict.)r   r   r   s    r   to_jsonzJobBuilder.to_json5  s    

##r   c                @    ddl }|j                  | j                        S )z8Return the assembled job specification as a JSON string.r   N)ra   dumpsr   )r  ra   s     r   to_json_strzJobBuilder.to_json_str9  s    zz$**%%r   c                ,    t        | j                        S )a<  Construct a :class:`pikepdf.Job` from the specification.

        The job is validated by qpdf during construction but not executed.

        Raises:
            pikepdf.JobUsageError: If the configuration is semantically invalid.
            RuntimeError: If the JSON is malformed or contains unknown keys.
        )r   r   r   s    r   buildzJobBuilder.build?  s     4::r   )validatec               j    | j                         }|r|j                          |j                          |S )aa  Build and run the job.

        Args:
            validate: If True (default), call ``check_configuration()`` before
                running to fail fast on invalid configurations.

        Returns:
            The :class:`pikepdf.Job` after running, so callers can inspect
            ``exit_code``, ``has_warnings`` and ``encryption_status``.
        )r~  check_configurationrun)r  r  jobs      r   r  zJobBuilder.runJ  s,     jjl##%	
r   c                >    | j                         j                         S )a3  Build the job and run only its first stage, returning a :class:`pikepdf.Pdf`.

        This is the staged workflow: the returned PDF can be modified before
        calling :meth:`pikepdf.Job.write_pdf` on the same job. Use :meth:`build`
        to retain a reference to the job for the write stage.
        )r~  
create_pdfr   s    r   r  zJobBuilder.create_pdf[  s     zz|&&((r   c                "    d| j                   dS )Nz<pikepdf.JobBuilder >r   r   s    r   __repr__zJobBuilder.__repr__d  s    %djj^155r   )returnNone)r   r   r   
str | Noner  r   )r  r   )r   r   r  r   r  )r   zEncryption | Noner  r  r  r  r  zLiteral[40, 128, 256]r  zPermissions | Noner  boolr  bool | Noner  r  r  r  r  r  r  r   )r   r   r*  r  r   r  r  r   )r/  
int | Noner  r   )r   r  r  r   )r3  z	int | strr*  r  r  r   )r#   r  r9   z1Literal['generate', 'preserve', 'disable'] | Noner%   r  r   r  r'   z;Literal['none', 'generalized', 'specialized', 'all'] | Noner!   z4Literal['compress', 'preserve', 'uncompress'] | Noner  r   )r9  r  r:  r  r;  r  r   r  r   r  r  r   )r>  r  r  r   )all)rA  z!Literal['all', 'print', 'screen']r  r   )rO  z	list[str]r  r   )rS  r   r  r   )rW  r  r  r   )r   r   r   r  r   r  r   r  r   r  r   r  r   r  r   r  r  r   )r   r   r   r  r   r  r  r   )r   r   r  r   )r   r   r   r  r_  r  r   r  r   r  r  r   )rg  r  rh  r  ri  r  rj  r  rk  r  rl  r  r  r   )rs  r   r  r   )r  r   )r  r   )r  r   )r  r  r  r   )r  r   )4__name__
__module____qualname____doc____annotations__r  r  r   r	  r   r   r)   rD   rh   r,  r@   r   r   r6   r   r8  r   r   r   r   r   r}   r   r   r   r   r   r   rP  r;   r=   r*   r.   rF   rZ  r\  r^  rd  rf  ro  rw  ry  r|  r~  r  r  r  r   r   r   r   r      s     :>  )-D &*$(&)$($D%D #	D
 "D $D "D D D D D D 
DL

 37RV%/EO	&

 )-LP!&(,LP! &! J	!
 ! &!! J! 
!L  $ $!%#(#'  	
  ! ! 
> DH 	 9>5	








 .3 	" ##"&#'"(( 	(
 ( (  ( !( ( ( 
(V 26d$.AK	$  !# 	
    
6  !# 	
    
. *.048<(,)-)-" '" $.	"
 ,6" &" '" '" 
"L8$&	 '+ ")6r   c                X    dt        |       i}|||d<   |||d<   |||d<   |||d<   |S )Nr   r   r   r   r   )r   )r   r   r_  r   r   r+  s         r   rb  rb  h  sS     $U4[1E	~df h$jLr   c               
   i }|j                   sd|d<   n|j                  sd|d<   nd|d<   | dk(  rt        |j                        |d<   t        |j                        |d<   |j
                  rd|d	<   |S |j                  rd
|d	<   |S |j                  rd|d	<   |S |j                  rd|d	<   |S d|d	<   |S t        |j                        |d<   t        |j                        |d<   t        |j                        |d<   t        |j                        |d<   t        |j                        |d
<   t        |j
                        |d<   |s	t        |d<   | dk(  r|rd|d<   |r	t        |d<   |S | dk(  r|r	t        |d<   |r	t        |d<   |S )a  Translate a :class:`Permissions` grant into qpdf restriction flags.

    pikepdf's :class:`Permissions` is allow-oriented; qpdf's flags are
    restrictions. Every flag is emitted explicitly so the result is fully
    determined by ``allow`` rather than qpdf's defaults.
    noner   lowfullr   r   r   r  r   r   assemblyr   r   r   r   r   r   r   r   r   r   r   )
print_lowresprint_highresr   r   modify_annotationmodify_othermodify_formmodify_assemblyr   r  )r  r  r  r  r  r  r  flagss           r   r  r  {  s     E g  ggrzu}}-i 7 78j#E(O  $E(O  $$(E(O
 	 ""(E(O  %E(O !!4!45E/5==)E)E334E*E112E*))*E&Mu112E-%,!"s{!E(O&E) L 
%,E/"&E)Lr   )r   r   r  r   )r   r  r  zLiteral['y', 'n'])r   intr  r  )r   r   r   r  r_  r  r   r  r   r  r  r   )r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r   ) r  
__future__r   r   copyr   typingr   r   r   pikepdf._corer   pikepdf.models.encryptionr	   r
   r   r   __all__r   r  	frozenset_ENCRYPT_KEYS_BLOCK_KEYSvaluesALL_JSON_KEYSr  r   r   r   r   rb  r  r   r   r   <module>r     s  < # 	  . .  R R!.V+V
V ^V W	V
 +V <V ^V 
5V 3V  8V +V <V )V )V MV  y!V" )#V$ ]%V& 'V( 3)V* '+V,  8-V. /V0 '1V2 o3V4 <5V6 ^7V8 
9V: <;V< <=V> /?V@ WAVB /CVD 0EVF GVH 'IVJ .KVL -MVN <OVP <QVR +SVT UVV <WVX )YVZ '[V\ F]V^ (_V` ,aVb (cVd *eVf gVh  !9iVj xkVl ymVn (oVp .qVr -sVt ^uVv !"<wVx +yVz +{V| +}V~ MV@  !:AVB LCVD $%BEVF yGVH /IVJ )KVL 1MVN ,OVP ;QVR ]SVT LUVV 'WVX 'YVZ <[V\ ']V^ ,_V` )aVb .cVd ^eVf &'FgVh +iVj MkV. Vt . D (//+,}<{J #~	6 ~	6B
  	
  &=
== 	=
 
= = = = =r   