B
    Afxa  ใ               @   sด   d Z dZdZdddZG dd deZG dd deeZG d	d
 d
eeZ	G dd de
eZG dd deeZG dd deZG dd deZG dd deZG dd deeZdS )z฿
    pint.errors
    ~~~~~~~~~~~

    Functions and classes related to unit definitions and conversions.

    :copyright: 2016 by Pint Authors, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
z2https://pint.readthedocs.io/en/latest/nonmult.htmlNc             C   sJ   | r|d k	rd|  d| dS | r.d|  dS |d k	rBd| dS dS d S )NzWhile opening z
, in line z: zIn line ฺ ฉ )ฺfilenameฺlinenor   r   ๚*lib/python3.7/site-packages/pint/errors.pyฺ_file_prefix   s    r   c               @   s   e Zd ZdZdS )ฺ	PintErrorz#Base exception for all Pint errors.N)ฺ__name__ฺ
__module__ฺ__qualname__ฺ__doc__r   r   r   r   r      s   r   c                   sD   e Zd ZdZddd fdd
Zdd Zedd	 Zd
d Z  Z	S )ฺDefinitionSyntaxErrorz4Raised when a textual definition has a syntax error.N)r   r   c               s   t   |ก || _|| _d S )N)ฺsuperฺ__init__r   r   )ฺselfฺmsgr   r   )ฺ	__class__r   r   r   !   s    zDefinitionSyntaxError.__init__c             C   s   t | j| jt| jd  S )N้    )r   r   r   ฺstrฺargs)r   r   r   r   ฺ__str__&   s    zDefinitionSyntaxError.__str__c             C   s   | j | jdS )N)r   r   )r   r   )r   r   r   r   ฺ__dict__)   s    zDefinitionSyntaxError.__dict__c             C   s   t | j| jfS )N)r   r   r   )r   r   r   r   ฺ
__reduce__0   s    z DefinitionSyntaxError.__reduce__)
r   r	   r
   r   r   r   ฺpropertyr   r   ฺ__classcell__r   r   )r   r   r      s
   r   c                   s8   e Zd ZdZddd fdd
Zdd Zdd	 Z  ZS )
ฺRedefinitionErrorz*Raised when a unit or prefix is redefined.N)r   r   c               s   t   ||ก || _|| _d S )N)r   r   r   r   )r   ฺnameZdefinition_typer   r   )r   r   r   r   7   s    zRedefinitionError.__init__c             C   s0   d| j d  d| j d  d}t| j| j| S )NzCannot redefine 'r   z' (้   ๚))r   r   r   r   )r   r   r   r   r   r   <   s    zRedefinitionError.__str__c             C   s   t | j| jfS )N)r   r   r   )r   r   r   r   r   @   s    zRedefinitionError.__reduce__)r   r	   r
   r   r   r   r   r   r   r   )r   r   r   4   s   r   c                   s(   e Zd ZdZ fddZdd Z  ZS )ฺUndefinedUnitErrorz;Raised when the units are not defined in the unit registry.c                s2   t |dkr"t|d ts"|d }t j|  d S )Nr   r   )ฺlenฺ
isinstancer   r   r   )r   Z
unit_names)r   r   r   r   G   s    zUndefinedUnitError.__init__c             C   s,   t | jdkr d| jd  dS | j dS )Nr   ๚'r   z%' is not defined in the unit registryz% are not defined in the unit registry)r   r   )r   r   r   r   r   L   s    zUndefinedUnitError.__str__)r   r	   r
   r   r   r   r   r   r   )r   r   r   D   s   r   c               @   s   e Zd ZdS )ฺPintTypeErrorN)r   r	   r
   r   r   r   r   r"   R   s   r"   c                   s8   e Zd ZdZd
dd fddZdd Zdd	 Z  ZS )ฺDimensionalityErrorz9Raised when trying to convert between incompatible units.r   )ฺ	extra_msgc               s,   t   ก  || _|| _|| _|| _|| _d S )N)r   r   ฺunits1ฺunits2ฺdim1ฺdim2r$   )r   r%   r&   r'   r(   r$   )r   r   r   r   Y   s    
zDimensionalityError.__init__c          	   C   sX   | j s| jr*d| j  d}d| j d}nd}d}d| j d| d| j d| | j 	S )Nz (r   r   zCannot convert from 'r!   z to ')r'   r(   r%   r&   r$   )r   r'   r(   r   r   r   r   a   s    zDimensionalityError.__str__c             C   s   t jtf| jfS )N)ฺ	TypeErrorฺ__new__r#   r   )r   r   r   r   r   n   s    zDimensionalityError.__reduce__)r   r   )r   r	   r
   r   r   r   r   r   r   r   )r   r   r#   V   s   r#   c               @   s   e Zd ZdZdd ZdS )ฺOffsetUnitCalculusErrorz1Raised on ambiguous operations with offset units.c             C   s&   dd  dd | jD ก d t d S )Nz*Ambiguous operation with offset unit (%s).z, c             s   s   | ]}t |V  qd S )N)r   )ฺ.0ฺur   r   r   ๚	<genexpr>x   s    z2OffsetUnitCalculusError.__str__.<locals>.<genexpr>z See z for guidance.)ฺjoinr   ฺOFFSET_ERROR_DOCS_HTML)r   r   r   r   r   u   s    zOffsetUnitCalculusError.__str__N)r   r	   r
   r   r   r   r   r   r   r+   r   s   r+   c               @   s   e Zd ZdZdd ZdS )ฺLogarithmicUnitCalculusErrorz:Raised on inappropriate operations with logarithmic units.c             C   s&   dd  dd | jD ก d t d S )Nz/Ambiguous operation with logarithmic unit (%s).z, c             s   s   | ]}t |V  qd S )N)r   )r,   r-   r   r   r   r.      s    z7LogarithmicUnitCalculusError.__str__.<locals>.<genexpr>z See z for guidance.)r/   r   ฺLOG_ERROR_DOCS_HTML)r   r   r   r   r      s    z$LogarithmicUnitCalculusError.__str__N)r   r	   r
   r   r   r   r   r   r   r1      s   r1   c               @   s   e Zd ZdS )ฺUnitStrippedWarningN)r   r	   r
   r   r   r   r   r3      s   r3   )NN)r   r0   r2   r   ฺ	Exceptionr   ฺSyntaxErrorr   ฺ
ValueErrorr   ฺAttributeErrorr   r)   r"   r#   r+   r1   ฺUserWarningr3   r   r   r   r   ฺ<module>	   s   
