MOON
Server: Apache
System: Linux server30c.hostingraja.org 3.10.0-962.3.2.lve1.5.63.el7.x86_64 #1 SMP Fri Oct 8 12:03:35 UTC 2021 x86_64
User: jibhires (1887)
PHP: 8.1.30
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open, allow_url_fopen, symlink, escapeshellcmd, pcntl_exec
Upload Files
File: //opt/alt/python38/lib/python3.8/site-packages/asn1crypto/__pycache__/util.cpython-38.pyc
U

�ґX{F�
@sXdZddlmZmZmZmZddlZddlZddlmZm	Z	m
Z
ddlmZddl
mZmZddlmZdd	lmZejd
kr�ddlmZmZnddlmZmZejdkr�dd
lmZmZdZd#dd�Zd$dd�ZGdd�de�ZGdd�d�Z n$ddlm Z dZd%dd�Zd&dd�Zddddddddddddd�Z!Gdd �d e"�Z#Gd!d"�d"e"�Z$dS)'a
Miscellaneous data helpers, including functions for converting integers to and
from bytes and UTC timezone. Exports the following items:

 - OrderedDict()
 - int_from_bytes()
 - int_to_bytes()
 - timezone.utc
 - inet_ntop()
 - inet_pton()
 - uri_to_iri()
 - iri_to_uri()
�)�unicode_literals�division�absolute_import�print_functionN)�datetime�date�time�)�unwrap)�
iri_to_uri�
uri_to_iri)�OrderedDict)�	type_nameZwin32)�	inet_ntop�	inet_pton)�)�	timedelta�tzinfoTFcCs�d}|rJ|dkrJd}tt�tdt|��d�d�}|d|>d|>}d|}t|�d@rfd|}|�d	�}|r�|s�t|dd��d
@r�d|}|dk	r�|r�d
}nd}||t|�|}n$|r�t|dd��d
@dkr�d
|}|S)�u
        Converts an integer to a byte string

        :param value:
            The integer to convert

        :param signed:
            If the byte string should be encoded using two's complement

        :param width:
            None == auto, otherwise an integer of the byte width for the return
            value

        :return:
            A byte string
        FrT�%xg@�r	�0�hex��N��)�int�math�ceil�len�abs�decode�ord)�value�signed�widthZis_neg�bitsZhex_str�outputZpad_char�r(�/util.py�int_to_bytes)s&"
r*cCsT|dkrdSt|�d�d�}|s$|St|dd��d@rPt|�d}|d|>S|S)�
        Converts a byte string to an integer

        :param value:
            The byte string to convert

        :param signed:
            If the byte string should be interpreted using two's complement

        :return:
            An integer
        �rr�r	rr)Zlong�encoder"r)r#r$ZnumZbit_lenr(r(r)�int_from_bytesVsr/c@s$eZdZdd�Zdd�Zdd�ZdS)�utccCsdS)Ns	UTC+00:00r(��self�_r(r(r)�tznameusz
utc.tznamecCstd�S�Nr�rr1r(r(r)�	utcoffsetxsz
utc.utcoffsetcCstd�Sr5r6r1r(r(r)�dst{szutc.dstN)�__name__�
__module__�__qualname__r4r7r8r(r(r(r)r0ssr0c@seZdZe�ZdS)�timezoneN)r9r:r;r0r(r(r(r)r<~sr<)r<cCsn|dkr^|rD|dkr&t|d���}n|��}|ddkrL|d7}n|��}t�|d�p\d}|j|d|d�S)rNrr	r�big)�	byteorderr$)r �
bit_lengthrr�to_bytes)r#r$r%Z
bits_requiredr(r(r)r*�s
cCstj|d|d�S)r+r=)r$)r�
from_bytes)r#r$r(r(r)r/�s���)r	�r����r�	�
��c@s�eZdZdZdZdZdZdd�Zdd�Zdd�Z	d	d
�Z
d#dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�ZdS)$�
extended_datez�
    A datetime.date-like object that can represent the year 0. This is just
    to handle 0000-01-01 found in some certificates.
    NcCsZ|dkrtd��|dks |dkr(td��|dks<|t|krDtd��||_||_||_dS)z�
        :param year:
            The integer 0

        :param month:
            An integer from 1 to 12

        :param day:
            An integer from 1 to 31
        r�year must be 0r	rM�month is out of range�day is out of rangeN)�
ValueError�_DAYS_PER_MONTH_YEAR_0�year�month�day)r2rTrUrVr(r(r)�__init__�szextended_date.__init__cCs�|�dd�}td|j|j�}d|krR|�d�}|�dd�}|�dd�}|�d|�}d|kr�|�d�}|�dd�}|�dd�}|�d|�}|�|�S)	z�
        Performs strftime(), always returning a unicode string

        :param format:
            A strftime() format string

        :return:
            A unicode string of the formatted date
        �%Y�0000���%c�2000�%�%%r)�replacerrUrV�strftime�r2�formatZtempZc_outZx_outr(r(r)�_format�s

zextended_date._formatcCs
|�d�S)z�
        Formats the date as %Y-%m-%d

        :return:
            The date formatted to %Y-%m-%d as a unicode string in Python 3
            and a byte string in Python 2
        z
0000-%m-%d)r`�r2r(r(r)�	isoformats	zextended_date.isoformatcCs|�|�}tr|�d�S|S�z�
        Formats the date using strftime()

        :param format:
            The strftime() format string

        :return:
            The formatted date as a unicode string in Python 3 and a byte
            string in Python 2
        �utf-8�rc�py2r.�r2rbr'r(r(r)r`s

zextended_date.strftimecCsH|dkr|j}|dkr|j}|dkr*|j}|dkr8t}nt}||||�S)z�
        Returns a new datetime.date or asn1crypto.util.extended_date
        object with the specified components replaced

        :return:
            A datetime.date or asn1crypto.util.extended_date object
        Nr)rTrUrVrrN)r2rTrUrV�clsr(r(r)r_'s	�zextended_date.replacecCstr|��S|��SdS�N�ri�	__bytes__�__unicode__rdr(r(r)�__str__Bszextended_date.__str__cCs|���d�S�Nrg�ror.rdr(r(r)rnHszextended_date.__bytes__cCs
|�d�S)Nz%Y-%m-%d)rcrdr(r(r)roKszextended_date.__unicode__cCst||j�sdS|�|�dkS�NFr��
isinstance�	__class__�__cmp__�r2�otherr(r(r)�__eq__Nszextended_date.__eq__cCs|�|�Srl�rzrxr(r(r)�__ne__Sszextended_date.__ne__cCsttdt|����dS)Nz�
            An asn1crypto.util.extended_date object can only be compared to
            an asn1crypto.util.extended_date or datetime.date object, not %s
            ��	TypeErrorr
rrxr(r(r)�_comparison_errorVs�zextended_date._comparison_errorcCs`t|t�rdSt||j�s$|�|�|j|j|jf}|j|j|jf}||krPdS||kr\dSdS)N���r	r)rurrvrrTrUrV)r2ry�st�otr(r(r)rw_s"

��zextended_date.__cmp__cCs|�|�dkSr5�rwrxr(r(r)�__lt__wszextended_date.__lt__cCs|�|�dkSr5r�rxr(r(r)�__le__zszextended_date.__le__cCs|�|�dkSr5r�rxr(r(r)�__gt__}szextended_date.__gt__cCs|�|�dkSr5r�rxr(r(r)�__ge__�szextended_date.__ge__)NNN)r9r:r;�__doc__rTrUrVrWrcrer`r_rprnrorzr|rrwr�r�r�r�r(r(r(r)rN�s(
	rNc@s�eZdZdZdZdZdZdZdZdZ	dZ
dZd/dd�Zdd�Z
dd	�Zd
d�Zdd
�Zdd�Zdd�Zd0dd�Zdd�Zd1dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Z dS)2�extended_datetimez�
    A datetime.datetime-like object that can represent the year 0. This is just
    to handle 0000-01-01 found in some certificates.
    Nrc		Cs�|dkrtd��|dks |dkr(td��|dks<|t|krDtd��|dksT|dkr\td��|dksl|d	krttd
��|dks�|d	kr�td��|dks�|dkr�td
��||_||_||_||_||_||_||_||_	dS)a�
        :param year:
            The integer 0

        :param month:
            An integer from 1 to 12

        :param day:
            An integer from 1 to 31

        :param hour:
            An integer from 0 to 23

        :param minute:
            An integer from 0 to 59

        :param second:
            An integer from 0 to 59

        :param microsecond:
            An integer from 0 to 999999
        rrOr	rMrPrQ�zhour is out of range�;zminute is out of rangezsecond is out of rangei?Bzmicrosecond is out of rangeN)
rRrSrTrUrV�hour�minute�second�microsecondr)	r2rTrUrVr�r�r�r�rr(r(r)rW�s,zextended_datetime.__init__cCst|j|j|j�S)zS
        :return:
            An asn1crypto.util.extended_date of the date
        )rNrTrUrVrdr(r(r)r�szextended_datetime.datecCst|j|j|j|j|j�S)zI
        :return:
            A datetime.time object of the time
        )rr�r�r�r�rrdr(r(r)r�szextended_datetime.timecCs"|jdkrdS|j�|jdd��S)z\
        :return:
            None or a datetime.timedelta() of the offset from UTC
        NrZ�rT)rr7r_rdr(r(r)r7�s
zextended_datetime.utcoffsetcCs"|jdkrdS|j�|jdd��S)zi
        :return:
            None or a datetime.timedelta() of the daylight savings time offset
        NrZr�)rr8r_rdr(r(r)r8�s
zextended_datetime.dstcCs"|jdkrdS|j�|jdd��S)z�
        :return:
            None or the name of the timezone as a unicode string in Python 3
            and a byte string in Python 2
        NrZr�)rr4r_rdr(r(r)r4�s
zextended_datetime.tznamec	Cs�|�dd�}td|j|j|j|j|j|j|j�}d|krf|�	d�}|�dd�}|�dd�}|�d|�}d|kr�|�	d�}|�dd�}|�dd�}|�d|�}|�	|�S)	z�
        Performs strftime(), always returning a unicode string

        :param format:
            A strftime() format string

        :return:
            A unicode string of the formatted datetime
        rXrYrZr[r\r]r^r)
r_rrUrVr�r�r�r�rr`rar(r(r)rc�s,�


zextended_datetime._format�TcCs&|jdkr|�d|�S|�d|�S)aj
        Formats the date as "%Y-%m-%d %H:%M:%S" with the sep param between the
        date and time portions

        :param set:
            A single character of the separator to place between the date and
            time

        :return:
            The formatted datetime as a unicode string in Python 3 and a byte
            string in Python 2
        rz0000-%%m-%%d%s%%H:%%M:%%Sz0000-%%m-%%d%s%%H:%%M:%%S.%%f)r�r`)r2�sepr(r(r)res
zextended_datetime.isoformatcCs|�|�}tr|�d�S|Srfrhrjr(r(r)r`1s

zextended_datetime.strftimec	
	Cs�|dkr|j}|dkr|j}|dkr*|j}|dkr8|j}|dkrF|j}|dkrT|j}|dkrb|j}|dkrp|j}|dkr~t}	nt	}	|	||||||||�S)z�
        Returns a new datetime.datetime or asn1crypto.util.extended_datetime
        object with the specified components replaced

        :return:
            A datetime.datetime or asn1crypto.util.extended_datetime object
        Nr)
rTrUrVr�r�r�r�rrr�)
r2rTrUrVr�r�r�r�rrkr(r(r)r_Bs:
�zextended_datetime.replacecCstr|��S|��SdSrlrmrdr(r(r)rpmszextended_datetime.__str__cCs|���d�Srqrrrdr(r(r)rnsszextended_datetime.__bytes__cCs d}|jdkr|d7}|�|�S)Nz%Y-%m-%d %H:%M:%Srz.%f)r�rc)r2rbr(r(r)rovs
zextended_datetime.__unicode__cCst||j�sdS|�|�dkSrsrtrxr(r(r)rz|szextended_datetime.__eq__cCs|�|�Srlr{rxr(r(r)r|�szextended_datetime.__ne__cCsttdt|����dS)z�
        Raises a TypeError about the other object not being suitable for
        comparison

        :param other:
            The object being compared to
        z�
            An asn1crypto.util.extended_datetime object can only be compared to
            an asn1crypto.util.extended_datetime or datetime.datetime object,
            not %s
            Nr}rxr(r(r)r�s	�z#extended_datetime._comparison_errorcCs�|��}|��}|dk	r |dks0|dkr8|dk	r8td��t|t�rFdSt||j�s\|�|�|j|j|j|j	|j
|j|j|f}|j|j|j|j	|j
|j|j|f}||kr�dS||kr�dSdS)Nz5can't compare offset-naive and offset-aware datetimesr�r	r)
r7r~rurrvrrTrUrVr�r�r�r�)r2ryZsoZoor�r�r(r(r)rw�s> 

��zextended_datetime.__cmp__cCs|�|�dkSr5r�rxr(r(r)r��szextended_datetime.__lt__cCs|�|�dkSr5r�rxr(r(r)r��szextended_datetime.__le__cCs|�|�dkSr5r�rxr(r(r)r��szextended_datetime.__gt__cCs|�|�dkSr5r�rxr(r(r)r��szextended_datetime.__ge__)rrrrN)r�)NNNNNNNN)!r9r:r;r�rTrUrVr�r�r�r�rrWrrr7r8r4rcrer`r_rprnrorzr|rrwr�r�r�r�r(r(r(r)r��sD
6

'
�
+(r�)FN)F)FN)F)%r�Z
__future__rrrrr�sysrrrZ_errorsr
Z_irirrZ_ordereddictr
Z_typesr�platformZ_inetrrZsocket�version_inforrrir*r/r0r<rS�objectrNr�r(r(r(r)�<module>sL


-


�;