+
    ^|iq&                        R t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ]P                  ! R4      t] ! R R]P                  4      4       t ! R	 R
]P                  4      tR tRR/R ltR t ! R R4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t. ROtR# )a  A decorator-based method of constructing IPython magics with `argparse`
option handling.

New magic functions can be defined like so::

    from IPython.core.magic_arguments import (argument, magic_arguments,
        parse_argstring)

    @magic_arguments()
    @argument('-o', '--option', help='An optional argument.')
    @argument('arg', type=int, help='An integer positional argument.')
    def magic_cool(self, arg):
        """ A really cool magic command.

    """
        args = parse_argstring(magic_cool, arg)
        ...

The `@magic_arguments` decorator marks the function as having argparse arguments.
The `@argument` decorator adds an argument using the same syntax as argparse's
`add_argument()` method. More sophisticated uses may also require the
`@argument_group` or `@kwds` decorator to customize the formatting and the
parsing.

Help text for the magic is automatically generated from the docstring and the
arguments::

    In[1]: %cool?
        %cool [-o OPTION] arg

        A really cool magic command.

        positional arguments:
          arg                   An integer positional argument.

        optional arguments:
          -o OPTION, --option OPTION
                                An optional argument.

Here is an elaborated example that uses default parameters in `argument` and calls the `args` in the cell magic::

    from IPython.core.magic import register_cell_magic
    from IPython.core.magic_arguments import (argument, magic_arguments,
                                            parse_argstring)


    @magic_arguments()
    @argument(
        "--option",
        "-o",
        help=("Add an option here"),
    )
    @argument(
        "--style",
        "-s",
        default="foo",
        help=("Add some style arguments"),
    )
    @register_cell_magic
    def my_cell_magic(line, cell):
        args = parse_argstring(my_cell_magic, line)
        print(f"{args.option=}")
        print(f"{args.style=}")
        print(f"{cell=}")

In a jupyter notebook, this cell magic can be executed like this::

    %%my_cell_magic -o Hello
    print("bar")
    i = 42

Inheritance diagram:

.. inheritance-diagram:: IPython.core.magic_arguments
   :parts: 3

N
UsageError)undoc)	arg_split)dedentz[a-zA-Z][a-zA-Z0-9_-]*$c                   F   a a ] tR t^`t oRtR tR tRV 3R lltRtVt	V ;t
# )MagicHelpFormatterz@A HelpFormatter with a couple of changes to meet our needs.
    c                V    \         P                  P                  V \        V4      W#4      # N)argparseRawDescriptionHelpFormatter
_fill_textr   )selftextwidthindents   &&&&>/usr/lib/python3/dist-packages/IPython/core/magic_arguments.pyr   MagicHelpFormatter._fill_texte   s"    33>>tVD\SXaa    c                   VP                   '       g&   V P                  WP                  4      ! ^4      w  pV# . pVP                  ^ 8X  d   VP	                  VP                   4       MzVP                  P                  4       pV P                  W4      p\        P                  V4      '       g
   RV,          pVP                    F  pVP                  V: RV: 24       K  	  RP                  V4      # )   z<%s> z, )option_strings_metavar_formatterdestnargsextendupper_format_argsNAME_REmatchappendjoin)r   actionmetavarpartsdefaultargs_stringoption_strings   &&     r   _format_action_invocation,MagicHelpFormatter._format_action_invocationi   s    $$$..v{{CAFHGN E ||q V223
 !++++-"//@ }}[11"(;"6K%+%:%:MLLM;!GH &; 99U##r   c                0   < \         \        V `  WW44       R # r
   )superr   	add_usage)r   usageactionsgroupsprefix	__class__s   &&&&&r   r-   MagicHelpFormatter.add_usage   s     $1%&Qr    )z::

  %)__name__
__module____qualname____firstlineno____doc__r   r)   r-   __static_attributes____classdictcell____classcell__r2   __classdict__s   @@r   r   r   `   s!     b$:R Rr   r   c            
       b   a a ] tR t^t oRtRRRRR]RRRR3
V 3R lltR tRR/R	 ltR
t	Vt
V ;t# )MagicArgumentParserz9An ArgumentParser tweaked for use by IPython magics.
    N-errorFc                D   < Vf   . p\         \        V `  WW4WVWxWR7
       R # )N)
progr.   descriptionepilogparentsformatter_classprefix_charsargument_defaultconflict_handleradd_help)r,   r@   __init__)r   rD   r.   rE   rF   rG   rH   rI   rJ   rK   rL   r2   s   &&&&&&&&&&&r   rM   MagicArgumentParser.__init__   s3     ?G!41t#%-	 	2 	Br   c                    \        V4      h)z4Raise a catchable error instead of exiting.
        r   )r   messages   &&r   rB   MagicArgumentParser.error   s     !!r   partialc               x    \        W'       * R7      pV'       d   V P                  V4      # V P                  V4      # )zKSplit a string into an argument list and parse that argument list.
        )strict)r   parse_known_args
parse_args)r   	argstringrR   argvs   &&$ r   parse_argstring#MagicArgumentParser.parse_argstring   s3     ;7((..t$$r   r4   )r5   r6   r7   r8   r9   r   rM   rB   rY   r:   r;   r<   r=   s   @@r   r@   r@      sF      !!3!"&")B&"
%E % %r   r@   c                   \        V R/ 4      pRV9  d   \        V RR4      VR&   \        V 4      p\        V3/ VB pRpV P                  RRR1,           F  pVP	                  W44      pVf   K  TpK  	  VP                  4       V n        V# )zAConstruct an argument parser using the function decorations.
    argcmd_kwdsrE   r9   N)getattr	real_namer@   
decoratorsadd_to_parserformat_helpr9   )
magic_funckwdsarg_nameparsergroupdecoresults   &      r   construct_parserrj      s     :}b1DD %j)TB]$H 2T2F E%%dd++##F2E ,  ++-JMr   rR   Fc               :    V P                   P                  WR7      # )z@Parse the string of arguments for the given magic function.
    )rR   )rf   rY   )rc   rW   rR   s   &&$r   rY   rY      s     ,,Y,HHr   c                ~    V P                   pVP                  R4      '       d   V\        R4      R p\        V RV4      # )z%Find the real name of the magic.
    magic_Nargcmd_name)r5   
startswithlenr^   )rc   
magic_names   & r   r_   r_      s?     $$JX&&H/
:}j99r   c                   0   a  ] tR t^t o RtR tR tRtV tR# )ArgDecoratorzMBase class for decorators to add ArgumentParser information to a method.
    c                ~    \        VR R4      '       g   RVn        . Vn        VP                  P                  V 4       V# has_argumentsFT)r^   rv   r`   r!   r   funcs   &&r   __call__ArgDecorator.__call__   s7    t_e44!%D DOt$r   c                    R# )zCAdd this object's information to the parser, if necessary.
        Nr4   r   rf   rg   s   &&&r   ra   ArgDecorator.add_to_parser   s     	r   r4   N)	r5   r6   r7   r8   r9   ry   ra   r:   r;   r>   s   @r   rs   rs      s      r   rs   c                   4   a  ] tR t^t o RtRR ltR tRtV tR# )magic_argumentszJMark the magic as having argparse arguments and possibly adjust the
name.
Nc                    Wn         R # r
   name)r   r   s   &&r   rM   magic_arguments.__init__       	r   c                    \        VR R4      '       g   RVn        . Vn        V P                  e   V P                  Vn        \        V4      Vn        V# ru   )r^   rv   r`   r   rn   rj   rf   rw   s   &&r   ry   magic_arguments.__call__   sI    t_e44!%D DO99 #yyD 't,r   r   r
   )	r5   r6   r7   r8   r9   rM   ry   r:   r;   r~   s   @r   r   r      s     	 	r   r   c                   <   a  ] tR t^t o RtR tR tV 3R ltRtV t	R# )ArgMethodWrapperz
Base class to define a wrapper for ArgumentParser method.

Child class must define either `_method_name` or `add_to_parser`.

c                    Wn         W n        R # r
   argsrd   )r   r   rd   s   &*,r   rM   ArgMethodWrapper.__init__  s    		r   c                p    Ve   Tp\        WP                  4      ! V P                  / V P                  B  R# )5Add this object's information to the parser.
        N)r^   _method_namer   rd   r|   s   &&&r   ra   ArgMethodWrapper.add_to_parser  s2     F))*DIICCr   c                &   < V ^8  d   Qh/ S[ ;R&   # )   r   )str)formatr>   s   "r   __annotate__ArgMethodWrapper.__annotate__   s       r   r   N)
r5   r6   r7   r8   r9   rM   ra   __annotate_func__r:   r;   r~   s   @r   r   r      s       r   r   c                       ] tR tRtRtRtRtR# )argumenti  zkStore arguments and keywords to pass to add_argument().

Instances also serve to decorate command methods.
add_argumentr4   Nr5   r6   r7   r8   r9   r   r:   r4   r   r   r   r          "Lr   r   c                       ] tR tRtRtRtRtR# )defaultsi  zkStore arguments and keywords to pass to set_defaults().

Instances also serve to decorate command methods.
set_defaultsr4   Nr   r4   r   r   r   r     r   r   r   c                   *   a  ] tR tRt o RtR tRtV tR# )argument_groupi  zqStore arguments and keywords to pass to add_argument_group().

Instances also serve to decorate command methods.
c                N    VP                   ! V P                  / V P                  B # )r   )add_argument_groupr   rd   r|   s   &&&r   ra   argument_group.add_to_parser%  s"     (($))AtyyAAr   r4   N)r5   r6   r7   r8   r9   ra   r:   r;   r~   s   @r   r   r     s     
B Br   r   c                   <   a a ] tR tRt oRtR tV 3R ltRtVtV ;t	# )rd   i+  z:Provide other keywords to the sub-parser constructor.
    c                    Wn         R # r
   rd   )r   rd   s   &,r   rM   kwds.__init__.  r   r   c                P   < \         \        V `  V4      pV P                  Vn        V# r
   )r,   rd   ry   r\   )r   rx   r2   s   &&r   ry   kwds.__call__1  s%    T4)$/99r   r   )
r5   r6   r7   r8   r9   rM   ry   r:   r;   r<   r=   s   @@r   rd   rd   +  s      r   rd   )r   r   r   rd   rY   )r9   r   reIPython.core.errorr   IPython.utils.decoratorsr   IPython.utils.processr   IPython.utils.textr   compiler   r   r   ArgumentParserr@   rj   rY   r_   rs   r   r   r   r   r   rd   __all__r4   r   r   <module>r      s   Lh  	 * * + %
**/
0&R== &R &RP!%(11 !%H,Ie I: "l (| 0" "" "	B% 	B	< 	r   