← Back
Editing: context.cpython-38.pyc
U �!�W, � @ s4 d Z ddlmZ G dd� de�ZG dd� de�ZdS )z4 parsedatetime/context.py Context related classes � )�localc @ sD e Zd ZdZdd� Zedd� �Zdd� Zdd � Zd d� Z dd � Z dS )�pdtContextStackz\ A thread-safe stack to store context(s) Internally used by L{Calendar} object c C s t � | _d S �N)r �_pdtContextStack__local��self� r �7/usr/lib/python3/dist-packages/parsedatetime/context.py�__init__ s zpdtContextStack.__init__c C s t | jd�sg | j_| jjS )N�stack)�hasattrr r r r r r Z__stack s zpdtContextStack.__stackc C s | j �|� d S r )�_pdtContextStack__stack�append�r Zctxr r r �push s zpdtContextStack.pushc C s( z| j �� W S tk r" Y d S X d S r )r �pop� IndexErrorr r r r r s zpdtContextStack.popc C s. z| j d W S tk r( td��Y nX d S )N���zcontext stack is empty)r r �RuntimeErrorr r r r �last% s zpdtContextStack.lastc C s | j S r )r r r r r �isEmpty+ s zpdtContextStack.isEmptyN)�__name__� __module__�__qualname__�__doc__r �propertyr r r r r r r r r r s r c @ s* e Zd ZdZdZdZdZdZdZdZ dZ d Zd ZdZ eeB eB eB Ze e B eB eB e B Zedfed fedfedfe dfe dfedfedfe dfg Zeeeeeeeee e e e e e e e e eeeeeeeee d�Zd*dd�Zdd� Zdd� Zedd� �Zedd � �Zed!d"� �Zed#d$� �Zd%d&� Zd'd(� Zd)S )+� pdtContexta� Context contains accuracy flag detected by L{Calendar.parse()} Accuracy flag uses bitwise-OR operation and is combined by: ACU_YEAR - "next year", "2014" ACU_MONTH - "March", "July 2014" ACU_WEEK - "last week", "next 3 weeks" ACU_DAY - "tomorrow", "July 4th 2014" ACU_HALFDAY - "morning", "tonight" ACU_HOUR - "18:00", "next hour" ACU_MIN - "18:32", "next 10 minutes" ACU_SEC - "18:32:55" ACU_NOW - "now" ��accuracy� � � � � � �@ � � �year�month�week�day�halfday�hour�min�sec�now)r( Zyearsr) Zmonthsr* Zweeksr+ Zdaysr, ZmorningZ afternoonZeveningZnightZtonightZmidnightr- Zhoursr. ZminuteZminsZminutesr/ �secondZsecsZsecondsr0 r c C s || _ dS )z� Default constructor of L{pdtContext} class. @type accuracy: integer @param accuracy: Accuracy flag @rtype: object @return: L{pdtContext} instance Nr )r r r r r r w s zpdtContext.__init__c G s0 |D ]&}t |t�s| j| }| j|O _qdS )z/ Updates current accuracy flag N)� isinstance�int�_ACCURACY_REVERSE_MAPPINGr )r r �accr r r �updateAccuracy� s zpdtContext.updateAccuracyc C s | � |j� dS )zK Uses another L{pdtContext} instance to update current one N)r6 r )r �contextr r r �update� s zpdtContext.updatec C s t | j| j@ �S )zE Returns True if current context is accurate to date )�boolr �ACU_DATEr r r r �hasDate� s zpdtContext.hasDatec C s t | j| j@ �S )zE Returns True if current context is accurate to time )r9 r �ACU_TIMEr r r r �hasTime� s zpdtContext.hasTimec C s t | jo d�t | jod�B S )z5 Returns the old date/time flag code r r )r3 r; r= r r r r �dateTimeFlag� s zpdtContext.dateTimeFlagc C s t | j�S )zJ Returns True if current context is accurate to date/time )r9 r r r r r � hasDateOrTime� s zpdtContext.hasDateOrTimec C sP g }| j D ]$\}}|| j@ r |�d|�� � q |rDdd�|� }nd}d| S )NzpdtContext.ACU_%sz accuracy=z | � zpdtContext(%s))�_ACCURACY_MAPPINGr r �upper�join)r Z accuracy_reprr5 �namer r r �__repr__� s zpdtContext.__repr__c C s | j |j kS r r r r r r �__eq__� s zpdtContext.__eq__N)r )r r r r � __slots__ZACU_YEARZ ACU_MONTHZACU_WEEKZACU_DAYZACU_HALFDAYZACU_HOURZACU_MINZACU_SECZACU_NOWr: r<