o
    .j                     @   s^   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ G dd deZdgZd	S )
zINT values from :rfc:`5545`.    )AnyClassVar)Self)JCalParsingError)
Parameters)	ICAL_TYPEc                       s   e Zd ZU dZdZee ed< eed< ddde	ee
f dB f fddZd	efd
dZed	efddZedefddZed	ee fddZddlmZ ded	efddZeded	efddZede
d	efddZ  ZS )vInta  Integer

    Value Name:
        INTEGER

    Purpose:
        This value type is used to identify properties that contain a
        signed integer value.

    Format Definition:
        This value type is defined by the following notation:

        .. code-block:: text

            integer    = (["+"] / "-") 1*DIGIT

    Description:
        If the property permits, multiple "integer" values are
        specified by a COMMA-separated list of values.  The valid range
        for "integer" is -2147483648 to 2147483647.  If the sign is not
        specified, then the value is assumed to be positive.

    The ``__new__`` method creates a vInt instance:

    Parameters:
        value: Integer value to encode. Can be positive or negative within
            the range -2147483648 to 2147483647.
        params: Optional parameter dictionary for the property.

    Returns:
        vInt instance

    Examples:

        .. code-block:: text

            1234567890
            -1234567890
            +1234567890
            432109876

        .. code-block:: pycon

            >>> from icalendar.prop import vInt
            >>> integer = vInt.from_ical('1234567890')
            >>> integer
            1234567890
            >>> integer = vInt.from_ical('-1234567890')
            >>> integer
            -1234567890
            >>> integer = vInt.from_ical('+1234567890')
            >>> integer
            1234567890
            >>> integer = vInt.from_ical('432109876')
            >>> integer
            432109876

        Create a PRIORITY property (1 = highest priority):

        .. code-block:: pycon

            >>> priority = vInt(1)
            >>> priority
            1
            >>> priority.to_ical()
            b'1'

        Create SEQUENCE property (for versioning):

        .. code-block:: pycon

            >>> sequence = vInt(3)
            >>> sequence.to_ical()
            b'3'
    INTEGERdefault_valueparamsNr   c                   s(   t  j| g|R i |}t||_|S )N)super__new__r   r   )clsr   argskwargsself	__class__ K/home/thesage/.local/lib/python3.10/site-packages/icalendar/prop/integer.pyr   [   s   
zvInt.__new__returnc                 C   s   t | dS )Nzutf-8)strencoder   r   r   r   to_ical`   s   zvInt.to_icalc                 C   s   t | S )z<INTEGER property type according to :rfc:`5545#section-3.3.8`)intr   r   r   r   
ical_valuec   s   zvInt.ical_valueicalc              
   C   s4   z| |W S  t y } ztd| |d }~ww )NzExpected int, got: )	Exception
ValueError)r   r   er   r   r   	from_icalh   s   
zvInt.from_icalc                 C   s   t dt dgS )zExamples of vInt.i  i)r   )r   r   r   r   exampleso   s   zvInt.examplesr   )VALUEnamec                 C   s   || j  | j t| gS )zBThe jCal representation of this property according to :rfc:`7265`.)r   to_jcalr$   lowerr   )r   r%   r   r   r   r&   v   s   zvInt.to_jcaljcal_propertyc                 C   s6   t ||  t |d t| d | |d t|dS )zParse jCal from :rfc:`7265`.

        Parameters:
            jcal_property: The jCal property to parse.

        Raises:
            ~error.JCalParsingError: If the provided jCal is invalid.
           r   )r   validate_propertyvalidate_value_typer   r   from_jcal_property)r   r(   r   r   r   	from_jcalz   s   
zvInt.from_jcalvaluec                 C   s   t |t|  | |S )zwParse a jCal value for vInt.

        Raises:
            ~error.JCalParsingError: If the value is not an int.
        )r   r+   r   )r   r.   r   r   r   parse_jcal_value   s   zvInt.parse_jcal_value)__name__
__module____qualname____doc__r
   r   r   __annotations__r   dictr   r   bytesr   propertyr   r   classmethodr   r"   listr   r#   icalendar.paramr$   r&   r-   r/   __classcell__r   r   r   r   r      s$   
 L$r   N)r3   typingr   r   icalendar.compatibilityr   icalendar.errorr   icalendar.parserr   icalendar.parser_toolsr   r   r   __all__r   r   r   r   <module>   s     
