o
    JPZ                     @   sp   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZ d dl
mZ G dd deZdS )    N)AbstractWriter)encodedecode)debug)errorc                   @   sx   e Zd ZdZdZdZi Ze D ]\Z	Z
Zeevrg ee< ee ee	e
f qdd Zdd Zdd
dZdd ZdS )PyFileWriterzStores transformed MIB modules as Python files at specified location.

       User is expected to pass *PyFileWriter* class instance to
       *MibCompiler* on instantiation. The rest is internal to *MibCompiler*.
    Tc                 C   s   t tj|| _dS )zCreates an instance of *PyFileWriter* class.

           Args:
               path: writable directory to store Python modules
        N)r   ospathnormpath_path)selfr
    r   5/usr/lib/python3/dist-packages/pysmi/writer/pyfile.py__init__#   s   zPyFileWriter.__init__c                 C   s   d| j j| jf S )Nz%s{"%s"})	__class____name__r   )r   r   r   r   __str__+   s   zPyFileWriter.__str__r   Fc           	      C   s>  |rt jt j@ ot d d S  d S tj| js9zt| j W n ty8   t	j
d| jt d f | dw |rKdddd |D  d | }tj| jt|| jtj d	 d	  }d }ztj| jd
\}}t|t| t| t|| W n/ tttfy   t }|rzt| W n	 ty   Y nw t	j
d||d f || dw t jt j@ ot d|  | jrztjd	d dkrtj|d| jd ntj|dd W n/ t tj!fy   Y n$   zt| W n	 t"y   Y nw t	j
d|t d f || dt jt j@ ot d|  d S  d S )Nzdry run modez-failure creating destination directory %s: %s   )writerz#
 c                 S   s   g | ]}d | qS )z# %s
r   ).0xr   r   r   
<listcomp><   s    z(PyFileWriter.putData.<locals>.<listcomp>r   )dirzfailure writing file %s: %s)filer   zcreated file %s   )   r   T)doraiseoptimize)r   zfailure compiling %s: %sz	%s stored)#r   loggerZ
flagWriterr	   r
   existsr   makedirsOSErrorr   ZPySmiWriterErrorsysexc_infojoinr   suffixesimpZ	PY_SOURCEtempfileZmkstempwriter   closerenameIOErrorUnicodeEncodeErrorunlink	pyCompileversion_info
py_compilecompilepyOptimizationLevelSyntaxErrorPyCompileError	Exception)	r   ZmibnamedataZcommentsZdryRunZpyfileZtfilefdexcr   r   r   putData.   sd    (
 &zPyFileWriter.putDatac                 C   s   dS )Nr   r   )r   filenamer   r   r   getDatak   s   zPyFileWriter.getDataN)r   F)r   
__module____qualname____doc__r0   r4   r'   r(   Zget_suffixesZsfxmodetypappendr   r   r   r;   r=   r   r   r   r   r      s    
=r   )r	   r$   r(   r)   r2   Zpysmi.writer.baser   Zpysmi.compatr   r   Zpysmir   r   r   r   r   r   r   <module>   s   