
    ic                         d Z ddlmZmZmZmZ ddl ddlZddlZddZ	d Z
ej                  Zedk  rddlZd Zd
 ZyddlZd	 Zd
 Zy)a  
    podgen.util
    ~~~~~~~~~~~~

    This file contains helper functions for the feed generator module.

    :copyright: 2013, Lars Kiesow <lkiesow@uos.de> and 2016, Thorben Dahl
        <thorben@sjostrom.no>
    :license: FreeBSD and LGPL, see license.* for more details.
    )absolute_importdivisionprint_functionunicode_literals)*Nc                    | sy|i }|i }t        | t              s| g} | D ]  }t        |t              st        d      t        j
                  d   }|dk(  r|j                         }n|j                         }|D ]  \  }}	|j                  ||	      ||<    t        |j                               |k  st        d      t        |j                               |k\  st        d      |dk(  r|j                         }
n|j                         }
|
D ],  \  }}	|j                  |      s||   |	vs t        d|z          | S )a  Takes a dictionary or a list of dictionaries and check if all keys are in
    the set of allowed keys, if all required keys are present and if the values
    of a specific key are ok.

    :param val:            Dictionaries to check.
    :param allowed:        Set of allowed keys.
    :param required:       Set of required keys.
    :param allowed_values: Dictionary with keys and sets of their allowed values.
    :param defaults:       Dictionary with default values.
    :returns:              List of checked dictionaries.
    Nz%Invalid data (value is no dictionary)r      zData contains invalid keysz#Data contains not all required keyszInvalid value for %s)
isinstancelistdict
ValueErrorsysversion_info	iteritemsitemsgetsetkeys)valallowedrequiredallowed_valuesdefaultselemversionr   kvvaluess              D/root/podcast_feed/.venv/lib/python3.12/site-packages/podgen/util.pyensure_formatr       sA    c4 e$%DEE ""1%a<&&(ENN$ECAahhq!nDG 499;7*9::499;8+BCCa<#--/F#))+FCAaxx{47a< !7!!;== 1 6 J    c                     t        j                  t         j                        }t        j                  t         j                  d       | j                  d      } t        j                  t         j                  |       | S )a  Format a datetime according to RFC2822.

    This implementation exists as a workaround to ensure that the locale setting
    does not interfere with the time format. For example, day names might get
    translated to your local language, which would break with the standard.

    :param d: Time and date you want to format according to RFC2822.
    :type d: datetime.datetime
    :returns: The datetime formatted according to the RFC2822.
    :rtype: str
    Cz%a, %d %b %Y %H:%M:%S %z)locale	setlocaleLC_ALLstrftime)dls     r   formatRFC2822r*   G   sT     	'A
V]]C(	

-.A
V]]A&Hr!   )   r	   c                 0    t        j                  | d      S )Encode the given string so its content won't be confused as HTML
        markup.

        This function exists as a cross-version compatibility alias.T)quote)cgiescapess    r   
htmlencoder3   `   s    
 zz!4((r!   c                 ,    t        j                  |       S )r-   )htmlr0   r1   s    r   r3   r3   i   s    
 {{1~r!   c                     t        |       }| D cg c]  }t        |       } }|dk(  ry|dk(  r| d   S dj                  | dd       dz   | d   z   S c c}w )uP  Create a human-readable string out of the given iterable.

    Example::

        >>> from podgen.util import listToHumanreadableStr
        >>> listToHumanreadableStr([1, 2, 3])
        1, 2 and 3

    The string ``(empty)`` is returned if the list is empty – it is assumed
    that you check whether the list is empty yourself.
    r   z(empty)   z, Nz and )lenstrjoin)r)   lengthes      r   listToHumanreadableStrr>   q   sg     VFAQA{	1tyy3B 7*QrU22 	s   A)NN)__doc__
__future__r   r   r   r   builtinsr   r$   r    r*   r   verr/   r3   r5   r>    r!   r   <module>rD      sT   	 S R  1h& 
<)"3 3r!   