Ë
    ëSûeÔ.  ã                   ó¾   — d Z ddlZddlmZ  ej                  e«      Z G d„ dej                  «      Zde	de
fd	„Zd
e	de	fd„Zd
e	de	fd„Zde	defd„Z G d„ d«      Zy)aÅ  
Copyright (c) 2022, Ian Santopietro
All rights reserved.

This file is part of RepoLib.

RepoLib is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

RepoLib is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with RepoLib.  If not, see <https://www.gnu.org/licenses/>.
é    Né   )Úutilc                   ó(   ‡ — e Zd ZdZddœˆ fd„
Zˆ xZS )ÚDebParseErrorz) Exceptions related to parsing deb lines.r   )Úcodec                ó2   •— t        ‰| �  |i |¤Ž || _        y)z‹Exceptions related to parsing deb lines.

        Arguments:
            code (:obj:`int`, optional, default=1): Exception error code.
    N)ÚsuperÚ__init__r   )Úselfr   ÚargsÚkwargsÚ	__class__s       €ú2/usr/lib/python3/dist-packages/repolib/parsedeb.pyr
   zDebParseError.__init__    s   ø€ ô 	‰Ñ˜$Ð) &Ò)Øˆ�	ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   Ú__classcell__)r   s   @r   r   r      s   ø„ Ù3à#$÷ ò r   r   ÚlineÚreturnc                 ó¾  — | j                  «       } | j                  «       }|D ]5  }t        j                  |«      sŒt	        |«      ||j                  |«      <   Œ7 dj                  |«      } g }d}d}| D ]G  }|dk(  rd}||z  }Œ|dk(  rd}||z  }Œ|j                  «       r|s|j                  |«       d}ŒC||z  }ŒI t        |«      dkD  r|j                  |«       |S )z¡ Improved string.split() with support for things like [] options. 
    
    Adapted from python-apt

    Arguments:
        line(str): The line to split up.
    ú Ú Fú[Tú]r   )
ÚstripÚsplitr   Úurl_validatorÚdecode_bracketsÚindexÚjoinÚisspaceÚappendÚlen)r   Ú	line_listÚiÚpiecesÚtmpÚp_foundÚchars          r   Údebsplitr,   )   sí   € ð �:‰:‹<€DØ—
‘
“€IØò ?ˆÜ×Ñ˜aÕ Ü,;¸AÓ,>ˆI�i—o‘o aÓ(Ò)ð?ð �8‰8�IÓ€DØ€FØ€Cà€GØò ˆØ�3Š;ØˆGØ�4‰K‰CØ�SŠ[ØˆGØ�4‰K‰CØ�\‰\Œ^¡GØ�M‰M˜#ÔØˆCØà�4‰K‰Cðô ˆ3ƒx�!‚|Ø�‰�cÔØ€Mr   Úwordc                 óN   — | j                  dd«      } | j                  dd«      } | S )aŽ   Encodes any [ and ] brackets into URL-safe form

    Technically we should never be recieving these, and there are other things 
    which should technically be encoded as well. However, square brackets 
    actively break the URL parsing, and must be strictly avoided.

    Arguments:
        word (str): the string to encode brackets in.
    
    Returns:
        `str`: the encoded string.
    r   ú%5Br   ú%5D©Úreplace©r-   s    r   Úencode_bracketsr4   M   s)   € ð �<‰<˜˜UÓ#€DØ�<‰<˜˜UÓ#€DØ€Kr   c                 óN   — | j                  dd«      } | j                  dd«      } | S )aK   Un-encodes [ and ] from the input

    Since our downstream libraries should also be encoding these correctly, it 
    is better to retain these as the user entered, as that ensures they can 
    recognize it properly.

    Arguments:
        word (str): The string to decode.

    Returns:
        `str`: the decoded string.
    r/   r   r0   r   r1   r3   s    r   r    r    ^   s)   € ð �<‰<˜˜sÓ#€DØ�<‰<˜˜sÓ#€DØ€Kr   Útailc                 ó$  — t        j                  | «      } d| v }t        j                  d|«       d| v }t        j                  d|«       | j	                  «       }d}d}d}d}d}|D ]È  }	t        j                  d|	«       |	j                  d«      j                  «       j                  d«      }
|	j                  d«      j                  «       j                  d«      }d|	v r	|
s|sd}d}n|
rd	}d}Œ‰|rd}d	}Œ�|r|
s	||	› d
�z  }Œ�|r|s	||	› z  }d}Œª|rŒ­|rŒ°|	j                  d«      }||› d
�z  }ŒÊ |j                  «       }|j                  «       }|j                  «       }|s|r|}|r|st        d|› d�«      ‚|r|st        d|› d�«      ‚|||fS )aµ   Find a Repolib name within the given comment string.

    The name should be headed with "X-Repolib-Name:" and is not space terminated.
    The ident should be headed with "X-Repolib-ID:" and is space terminated.

    Either field ends at the end of a line, or at a subsequent definition of a
    different field, or at a subsequent ' #' substring. Additionally, the ident
    field ends with a subsequent space.

    Arguments:
        tail (str): The comment to search within.
    
    Returns: tuple(name, ident, comment):
        name (str): The detected name, or None
        ident (str): The detected ident, or None
        comment (str): The string with the name and ident removed
    zX-Repolib-NamezLine name found: %szX-Repolib-IDzLine ident found: %sFr   zChecking line item: %sú#Tr   z-Could not parse repository name from comment z;. Make sure you have a space between the colon and the Namez.Could not parse repository ident from comment z<. Make sure you have a space between the colon and the Ident)r   Ústrip_hashesÚlogÚdebugr   r   Ú
startswithr   )r6   Úhas_nameÚ	has_identÚpartsÚ
name_foundÚident_foundÚnameÚidentÚcommentÚitemÚitem_is_nameÚitem_is_identÚcs                r   Úparse_name_identrI   o   sß  € ô$ ×Ñ˜TÓ"€Dð   4Ð'€HÜ‡I�IÐ# XÔ.Ø $Ð&€IÜ‡I�IÐ$ iÔ0à—*‘*“,€EØ€JØ€KØ€DØ€EØ€GØò ˆÜ�	‰	Ð*¨DÔ1Ø—z‘z #“×,Ñ,Ó.×9Ñ9Ð:JÓKˆØŸ
™
 3›×-Ñ-Ó/×:Ñ:¸>ÓJˆà�$‰;™|±MØˆJØ‰KáØˆJØˆKØáØˆJØˆKØá™lØ�t�f˜A�JÑˆDØá¡Ø˜�vÑˆEØˆKØâ¢KØ—
‘
˜3“ˆAØ˜!˜˜A�wÑ‰Gð=ð@ �:‰:‹<€DØ�K‰K‹M€EØ�m‰m‹o€GáÙØˆDñ ™ÜØ;¸G¸9ð E>ð >ó
ð 	
ñ ™ÜØ<¸W¸Ið F?ð ?ó
ð 	
ð
 �˜ÐÐr   c                   óB   — e Zd ZdZd
deddfd„Zdedefd„Zdedefd	„Z	y)ÚParseDebz] Parsing for source entries. 

    Contains parsing helpers for one-line format sources.
    r;   r   Nc                 óJ   — || _         d| _        d| _        d| _        d| _        y)zº
        Arguments:
            debug (bool): In debug mode, the structured data is always returned
                at the end, instead of checking for sanity (default: `False`)
        r   FN)r;   Ú	last_lineÚlast_line_validÚ	curr_lineÚcurr_line_valid)r   r;   s     r   r
   zParseDeb.__init__Ì   s)   € ð ˆŒ
Ø ˆŒØ%*ˆÔØ ˆŒØ%*ˆÕr   Úoptc           	      ón  — |j                  «       }|dd j                  «       }|j                  «       }i }|D ]Q  }|j                  d«      \  }}|j                  d«      }dj                  |«      }	 t        j                  |   }|||<   ŒS |S # t
        $ r t        d| j                  › d|› d�«      ‚w xY w)	a   Parses a string of options into a dictionary that repolib can use.

        Arguments:
            opt(str): The string with options returned from the line parser.
        
        Returns:
            `dict`: The dictionary of options with key:val pairs (may be {})
        r   éÿÿÿÿú=ú,r   zCould not parse line z	: option z; is not a valid debian repository option or is unsupported.)r   r   r"   r   Úoptions_inmapÚKeyErrorr   rO   )r   rQ   ÚoptionsÚparsed_optionsÚpre_keyÚvaluesÚvalueÚkeys           r   Úparse_optionszParseDeb.parse_optionsØ   sÓ   € ð �i‰i‹kˆØ�!�Bˆi�o‰oÓˆØ—)‘)“+ˆà ˆàò 	(ˆCØ!Ÿi™i¨›n‰OˆG�VØ—\‘\ #Ó&ˆFØŸ™ Ó(ˆEðÜ×,Ñ,¨WÑ5�ð #(ˆN˜3Òð	(ð Ðøô ò Ü#Ø+¨D¯N©NÐ+;¸9ÀSÀEð JNð Nóð ðús   Á2BÂ&B4r   c                 ón  — | j                   | _        | j                  | _        |j	                  «       | _         g }| j                   dk(  }| j                   dk(  }|s|rt        d| j                   › d�«      ‚i }d|d<   d|d<   d|d<   g |d	<   d|d
<   d|d<   d|d<   g |d<   i |d<   |j                  d«      rJd|d<   t        j                  |«      }|j                  «       }|d   dvrt        d| j                   › d�«      ‚|j                  d«      }|dkD  rD||dz   d j	                  «       }t        |«      \  |d<   |d<   }|d	   j                  |«       |d| }t        |«      }t        |«      dk  rt        d| j                   › d�«      ‚|j                  d«      }	|	dv rt        j                   |	«      |d
<   nt        d| j                   › d�«      ‚d}
d}|D ].  }|j                  d«      sŒd|v rd}|j#                  |«      }
Œ-d}
Œ0 |rt        d«      ‚|
dk7  r#| j%                  |j                  d«      «      |d<   t        |«      dk  rt        d| j                   › d�«      ‚|j                  d«      }t        j&                  |«      r||d<   nt        d| j                   › d|› �«      ‚|j                  d«      |d<   g }|D ]  }|d   j                  |«       Œ |d
   }|d   }|d   }|r|r|r|j)                  «       S | j*                  r|j)                  «       S t        d| j                   › d�«      ‚) zî Parse a deb line into its individual parts.

        Adapted from python-apt

        Arguments:
            line (str): The line input to parse
        
        Returns:
            (dict): a dict containing the requisite data.
        r8   r   zCurrent line "z
" is emptyTÚenabledrB   rC   ÚcommentsÚ	repo_typeÚuriÚsuiteÚ
componentsrX   Fr   )Údebzdeb-srcz" is invalidr   Né   z
The line "z(" does not have enough pieces to bevalidz" is of invalid type.r   Úcdromz-Repolib cannot currently accept CDROM Sourcesé   z" has invalid URI: z	The line zd could not be parsed due to an unknown error (Probably missing the repo type, URI, or a suite/path).)rO   rM   rP   rN   r   r   r<   r   r9   r   ÚfindrI   r$   r,   r%   ÚpopÚ
SourceTyper!   r^   r   Úcopyr;   )r   r   r?   Úline_is_commentÚline_is_emptyÚline_parsedÚcomments_indexÚraw_commentsra   rb   Ú	uri_indexÚis_cdromÚpartÚline_uriÚline_componentsÚcompÚhas_typeÚhas_uriÚ	has_suites                      r   Ú
parse_linezParseDeb.parse_line÷   s³  € ð Ÿ™ˆŒØ#×3Ñ3ˆÔØŸ™›ˆŒØˆàŸ.™.¨CÑ/ˆØŸ™¨"Ñ,ˆÙ™mÜ .°·±Ð0@À
Ð KÓLÐLàˆØ!%ˆ�IÑØ ˆ�FÑØ!ˆ�GÑØ"$ˆ�JÑØ#%ˆ�KÑ Øˆ�EÑØ!ˆ�GÑØ$&ˆ�LÑ!Ø!#ˆ�IÑà�?‰?˜3ÔØ%*ˆK˜	Ñ"Ü×$Ñ$ TÓ*ˆDØ—J‘J“LˆEØ˜‘8Ð1Ñ1Ü# n°T·^±^Ð4DÀLÐ$QÓRÐRàŸ™ 3›ˆØ˜AÒØ# N°QÑ$6Ð$7Ð8×>Ñ>Ó@ˆLô
 ! Ó.ñ	Ø˜FÑ#Ø˜GÑ$Øà˜
Ñ#×*Ñ*¨8Ô4Ø˜˜Ð(ˆDä˜“ˆÜˆu‹:˜Š>ÜØ˜TŸ^™^Ð,ð -ð óð ð
 Ÿ	™	 !›ˆ	ØÐ*Ñ*Ü'+§¡°yÓ'AˆK˜Ò$ä *¨T¯^©^Ð,<Ð<QÐ RÓSÐSð ˆ	Øˆð
 ò 	"ˆDØ�‰˜sÕ#Ø˜d‘?Ø#�HØ %§¡¨DÓ 1‘Ià !‘Ið	"ñ ô  Ð OÓPÐPà˜Š>Ø%)×%7Ñ%7¸¿	¹	À!»Ó%EˆK˜	Ñ"äˆ{Ó˜aÒÜØ˜TŸ^™^Ð,ð -ð óð ð
 —9‘9˜Q“<ˆÜ×Ñ˜hÔ'Ø!)ˆK˜Òô  Ø˜TŸ^™^Ð,Ð,?À¸zÐJóð ð  %Ÿy™y¨›|ˆ�GÑà!ˆØò 	3ˆDØ˜Ñ%×,Ñ,¨TÕ2ð	3ð ˜{Ñ+ˆØ˜eÑ$ˆØ Ñ(ˆ	á™¡Ið ×#Ñ#Ó%Ð%à�:Š:Ø×#Ñ#Ó%Ð%äØ˜Ÿ™Ð'ð (ð ó
ð 	
r   )F)
r   r   r   r   Úboolr
   ÚstrÚdictr^   r|   © r   r   rK   rK   Æ   sC   „ ññ

+˜Tð 
+¨dó 
+ð ð ¨ó ð>|
˜cð |
 dô |
r   rK   )r   Úloggingr   r   Ú	getLoggerr   r:   Ú	RepoErrorr   r~   Úlistr,   r4   r    ÚtuplerI   rK   r€   r   r   ú<module>r†      s‘   ðñó( å à€g×Ñ˜Ó!€ô
�D—N‘Nô 
ð"�#ð "˜$ó "ðH˜ð  ó ð"˜ð  ó ð"T ˜#ð T  %ó T ÷nm
ò m
r   