U
    ڲg                     @  sX   d Z ddlmZ ddlmZmZmZ ddlmZ er@ddl	m
Z
 G dd dee Zd	S )
z)
The Column object in Cursor.description
    )annotations)AnySequenceTYPE_CHECKING
attrgetter   )
BaseCursorc                   @  s   e Zd ZdZdddddZedd d	 D Zd
dddZddddZe	d
dddZ
dddddZe	d
dddZe	ddddZe	ddddZe	ddddZe	dddd Ze	ddd!d"Ze	d#dd$d%Zd&S )'ColumnZpsycopgzBaseCursor[Any, Any]int)cursorindexc                 C  sv   |j }|st||}|r,||j| _nd|d  | _||| _|jj	
| j| _||| _||| _d S )NZcolumn_r   )ZpgresultAssertionErrorfnamedecode	_encoding_nameZftype_ftypeadapterstypesget_typefmod_fmodfsize_fsize)selfr   r   resr    r   3/tmp/pip-unpacked-wheel-b_ea6rx_/psycopg/_column.py__init__   s    
zColumn.__init__c                 c  s   | ]}t |V  qd S Nr   ).0attrr   r   r   	<genexpr>#   s   zColumn.<genexpr>z[
            name type_code display_size internal_size precision scale null_ok
            str)returnc                 C  s   d| j d| j d| j dS )Nz<Column z, type: z (oid: z)>)nametype_display	type_coder   r   r   r   __repr__*   s    zColumn.__repr__c                 C  s   dS )N   r   r*   r   r   r   __len__0   s    zColumn.__len__c                 C  s$   | j st| jS | j j| j| jdS )zA pretty representation of the column type.

        It is composed by the type name, followed by eventual modifiers and
        brackets to signify arrays, e.g. :sql:`text`, :sql:`varchar(42)`,
        :sql:`date[]`.
        )oidr   )r   r%   r)   Zget_type_displayr   r*   r   r   r   r(   3   s    
zColumn.type_displayr   )r   r&   c                   s8   t |tr&t fdd j| D S  j|  S d S )Nc                 3  s   | ]}| V  qd S r!   r   )r"   getterr*   r   r   r$   B   s     z%Column.__getitem__.<locals>.<genexpr>)
isinstanceslicetuple_attrs)r   r   r   r*   r   __getitem__@   s    
zColumn.__getitem__c                 C  s   | j S )zThe name of the column.)r   r*   r   r   r   r'   F   s    zColumn.namec                 C  s   | j S )zThe numeric OID of the column.)r   r*   r   r   r   r)   K   s    zColumn.type_codez
int | Nonec                 C  s   | j r| j | jS dS )z;The field size, for string types such as :sql:`varchar(n)`.N)r   Zget_display_sizer   r*   r   r   r   display_sizeP   s    zColumn.display_sizec                 C  s   | j }|dkr|S dS )z=The internal field size for fixed-size types, None otherwise.r   N)r   )r   r   r   r   r   internal_sizeU   s    zColumn.internal_sizec                 C  s   | j r| j | jS dS )z/The number of digits for fixed precision types.N)r   Zget_precisionr   r*   r   r   r   	precision[   s    zColumn.precisionc                 C  s   | j r| j | jS dS )z:The number of digits after the decimal point if available.N)r   Z	get_scaler   r*   r   r   r   scale`   s    zColumn.scalezbool | Nonec                 C  s   dS )zAlways `!None`Nr   r*   r   r   r   null_oke   s    zColumn.null_okN)__name__
__module____qualname__r    r2   splitr3   r+   r-   propertyr(   r4   r'   r)   r5   r6   r7   r8   r9   r   r   r   r   r
      s0   r
   N)__doc__
__future__r   typingr   r   r   operatorr   Z_cursor_baser	   r
   r   r   r   r   <module>   s   