
    cwi.                        S r SSKrSSKJr  SSKJrJrJrJrJ	r	  SSK
JrJrJrJrJrJrJr  SSKJr  SSKJr  SS	KJr  / S
Qr " S S5      r " S S\S9r\R6                  " \SS9S 5       r " S S\S9r S)S\S\\	\      S\4S jjr \R6                  " \SS9S 5       r!\R6                  " \SS9S 5       r"\R6                  " \SS9S 5       r#\R6                  " \SS9S  5       r$\R6                  " \S!S9S" 5       r%\R6                  " \S#S9S$ 5       r&\R6                  " \S%S9S& 5       r'\R6                  " \S'S9S( 5       r(g)*aW  
Functions and classes to implement applications based on clingo.

Examples
--------
The following example reproduces the default clingo application:

    import sys
    from clingo.application import Application, clingo_main

    class ClingoApp(Application):
        def __init__(self, name):
            self.program_name = name

        def main(self, ctl, files):
            for f in files:
                ctl.load(f)
            if not files:
                ctl.load("-")
            ctl.ground([("base", [])])
            ctl.solve()

    clingo_main(ClingoApp(sys.argv[0]), sys.argv[1:])
    N)ABCMeta)AnyCallableListOptionalSequence   )_cb_error_panic_cb_error_print_ffi_handle_error_lib_overwritten_to_str)Control)MessageCode)Model)ApplicationApplicationOptionsFlagclingo_mainc                   t    \ rS rSrSrSS\4S jjrS r\S\4S j5       r	\	R                  S\4S j5       r	S	rg
)r   .   zl
Helper object to parse command-line flags.

Parameters
----------
value
    The initial value of the flag.
valuec                 <    [         R                  " SU5      U l        g )Nzbool*)r   new_flagselfr   s     L/home/james-whalen/.local/lib/python3.13/site-packages/clingo/application.py__init__Flag.__init__8   s    XXgu-
    c                     U R                   $ N)flagr   s    r    __bool__Flag.__bool__;   s    yyr#   returnc                      U R                   S   $ )z
The value of the flag.
r   r   r'   s    r    r&   	Flag.flag>   s    
 zz!}r#   c                      XR                   S'   g Nr   r,   r   s     r    r&   r-   E   s    

1r#   r,   N)F)__name__
__module____qualname____firstlineno____doc__boolr!   r(   propertyr&   setter__static_attributes__ r#   r    r   r   .   sR    .d . d   
[[$  r#   r   c                   |    \ rS rSrSrS r  SS\S\S\S\\/\4   S	\S
\	\   SS4S jjr
S\S\S\S\SS4
S jrSrg)r   J   z=
Object to add custom options to a clingo based application.
c                     Xl         X l        g r%   )_rep_mem)r   repmems      r    r!   ApplicationOptions.__init__O   s    		r#   Ngroupoptiondescriptionparsermultiargumentr*   c                 x   [         R                  " U5      nU R                  R                  U5        [	        [
        R                  " U R                  UR                  5       UR                  5       UR                  5       [
        R                  UUUb  UR                  5       O[         R                  5      5        g)a  
Add an option that is processed with a custom parser.

Parameters
----------
group
    Options are grouped into sections as given by this string.
option
    Parameter option specifies the name(s) of the option. For example,
    `"ping,p"` adds the short option `-p` and its long form `--ping`. It is
    also possible to associate an option with a help level by adding `",@l"` to
    the option specification. Options with a level greater than zero are only
    shown if the argument to help is greater or equal to `l`.
description
    The description of the option shown in the help output.
parser
    An option parser is a function that takes a string as input and returns
    true or false depending on whether the option was parsed successively.
multi
    Whether the option can appear multiple times on the command-line.
argument
    Optional string to change the value name in the generated help.

Notes
-----
The parser callback has to take care of storing the semantic value of
the option somewhere.
N)r   
new_handler>   appendr   r   clingo_options_addr=   encode"pyclingo_application_options_parseNULL)r   rB   rC   rD   rE   rF   rG   c_datas           r    addApplicationOptions.addS   s    L (		 ##		""$77%-%9!tyy		
r#   targetc           	          U R                   R                  U5        [        [        R                  " U R
                  UR                  5       UR                  5       UR                  5       UR                  5      5        g)a  
Add an option that is a simple flag.

This function is similar to `ApplicationOptions.add` but simpler because
it only supports flags, which do not have values. Note that the target
parameter must be of type Flag, which is set to true if the flag is passed on
the command line.

Parameters
----------
group
    Options are grouped into sections as given by this string.
option
    Same as for `ApplicationOptions.add`.
description
    The description of the option shown in the help output.
target
    The object that receives the value.
N)r>   rJ   r   r   clingo_options_add_flagr=   rL   r   )r   rB   rC   rD   rR   s        r    add_flagApplicationOptions.add_flag   sX    * 			 ((		""$	
r#   )r>   r=   )FN)r0   r1   r2   r3   r4   r!   strr   r5   r   rP   r   rU   r8   r9   r#   r    r   r   J   s     "&4
4
 4
 	4

 #%4
 4
 3-4
 
4
l
c 
3 
S 
$ 
SW 
r#   r   )	metaclassrM   )onerrornamec                 L    [         R                  " U5      " [        U 5      5      $ r%   )r   from_handler   )r   datas     r    #_pyclingo_application_options_parser^      s    D!'%.11r#   c                       \ rS rSr% Sr\\S'    \\S'    \\S'    S\S\	\   SS	4S
 jr
S\SS	4S jrS\4S jrS\S\/ S	4   SS	4S jrS\S\SS	4S jrSrg	)r      z;
Interface that has to be implemented to customize clingo.
program_nameversionmessage_limitcontrolfilesr*   Nc                     g)z
Function to replace clingo's default main function.

If this function is not implemented, clingo's default is used.

Parameters
----------
control
    The main control object.
files
    The files passed to clingo_main.
Nr9   )r   rd   re   s      r    mainApplication.main       r#   optionsc                     g)zo
Function to register custom options.

Parameters
----------
options
    Object to register additional options
Nr9   )r   rj   s     r    register_optionsApplication.register_options   ri   r#   c                     g)zu
Function to validate custom options.

Returns
-------
This function should return false if option validation fails.
Nr9   r'   s    r    validate_optionsApplication.validate_options   ri   r#   modelprinterc                     g)a
  
Function to print additional information when the text output is used.

To avoid entangled output, `sys.stdout.flush` is automatically called
after this function.

Parameters
----------
model
    The current model
printer
    The default printer as used in clingo.
Nr9   )r   rq   rr   s      r    print_modelApplication.print_model   ri   r#   codemessagec                     g)a  
Function to intercept messages normally printed to standard error.

By default, messages are printed to standard error.

Parameters
----------
code
    The message code.
message
    The message string.

Notes
-----
This function should not raise exceptions.
Nr9   )r   rv   rw   s      r    loggerApplication.logger   ri   r#   r9   )r0   r1   r2   r3   r4   rW   __annotations__intr   r   rg   r   rl   r5   ro   r   r   rt   r   ry   r8   r9   r#   r    r   r      s      L G HSM d (: t $  "d(1C  ;   r#   r   application	argumentsr*   c                    Uc  [         R                  SS n[        R                  " S[	        [
        U S5      (       a  [        R                  O[        R                  [	        [
        U S5      (       a  [        R                  O[        R                  [	        [
        U S5      (       a  [        R                  O[        R                  [	        [
        U S5      (       a  [        R                  O[        R                  [	        [
        U S5      (       a  [        R                  O[        R                  [	        [
        U S	5      (       a  [        R                  O[        R                  [	        [
        U S
5      (       a  [        R                  O[        R                  [	        [
        U S5      (       a  [        R                  O[        R                  45      n/ n[        R                   " X45      n[        R"                  " UU Vs/ s H(  n[        R                  " SUR%                  5       5      PM*     sn['        U5      U5      $ s  snf )a/  
Runs the given application using clingo's default output and signal handling.

The application can overwrite clingo's default behaviour by registering
additional options and overriding its default main function.

Parameters
----------
application
    The application object.
arguments
    The command line arguments excluding the program name.

    If omitted, then `sys.argv[1:]` is used.

Returns
-------
The exit code of the application.

Notes
-----
The main function of the `Application` interface has to be implemented. All
other members are optional.
Nr	   zclingo_application_t*ra   rb   rc   rg   ry   rt   rl   ro   char[])sysargvr   r   r   r   r   !pyclingo_application_program_namerN   pyclingo_application_version"pyclingo_application_message_limitpyclingo_application_mainpyclingo_application_logger pyclingo_application_print_model%pyclingo_application_register_options%pyclingo_application_validate_optionsrI   r   rL   len)r}   r~   c_applicationr@   rO   args         r    r   r     s   6 HHQRL	 HH  [.II 66YY  [)DD 11YY  [/JJ 77YY  [&AA ..YY  [(CC 00YY  [-HH 55YY  [:LMM ::YY  [:LMM ::YYO)	
,M\ C__k/0F5>?Yc(CJJL	)Y?I	 ?s   /I
r   c                     [         R                  " U 5      u  pUR                  [         R                  " SUR                  R                  5       5      5        US   $ Nr   )r   r\   rJ   r   ra   rL   r]   appr@   s      r    "_pyclingo_application_program_namer   \  sC    %HCJJtxx#"2"2"9"9";<=r7Nr#   r   c                     [         R                  " U 5      u  pUR                  [         R                  " SUR                  R                  5       5      5        US   $ r   )r   r\   rJ   r   rb   rL   r   s      r    _pyclingo_application_versionr   c  sA    %HCJJtxx#++"4"4"678r7Nr#   r   c                 L    [         R                  " U 5      S   nUR                  $ r/   )r   r\   rc   r]   r   s     r    #_pyclingo_application_message_limitr   j  s#    


4
 
#Cr#   r   c                 |    [         R                  " U5      S   nUR                  [        U 5      [	        U5      5      $ r/   )r   r\   ry   r   r   )rv   rw   r]   r   s       r    _pyclingo_application_loggerr   p  s2    


4
 
#C::k$')9::r#   r   c           
          [         R                  " U5      S   nUR                  [        U 5      [	        U5       Vs/ s H  n[        X   5      PM     sn5        gs  snf )Nr   T)r   r\   rg   r   ranger   )rd   re   sizer]   r   is         r    _pyclingo_application_mainr   v  sM    


4
 
#CHHWW5;G;a 1;GH  Hs   A
r   c                    ^^ UU4S jn[         R                  " U5      S   nUR                  [        U 5      U5        [        R
                  R                  5         g)Nc                  (   > [        T " T5      5        g r%   )r   )rr   printer_datas   r    
py_printer5_pyclingo_application_print_model.<locals>.py_printer  s    gl+,r#   r   T)r   r\   rt   r   r   stdoutflush)rq   rr   r   r]   r   r   s    ``   r    !_pyclingo_application_print_modelr   }  sD    - 

4
 
#COOE%L*-JJr#   r   c                 h    [         R                  " U5      u  p#UR                  [        X5      5        g)NT)r   r\   rl   r   )rj   r]   r   r@   s       r    &_pyclingo_application_register_optionsr     s+    %HC+G9:r#   r   c                 T    [         R                  " U 5      S   nUR                  5       $ r/   )r   r\   ro   r   s     r    &_pyclingo_application_validate_optionsr     s&    


4
 
#C!!r#   r%   ))r4   r   abcr   typingr   r   r   r   r   	_internalr
   r   r   r   r   r   r   rd   r   corer   solvingr   __all__r   r   
def_externr^   r   rW   r|   r   r   r   r   r   r   r   r   r   r9   r#   r    <module>r      s  2   : :     
F 8]
7 ]
@ /ST2 U2RG Rl DHUU)1(3-)@UUp /RS T /MN O /ST U
 /LM; N;
 /JK L /QR S /VW X /VW" X"r#   