Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pyfakefs/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pyfakefs/__pycache__/helpers.cpython-37.opt-1.pyc

B

��\$6�@s�dZddlZddlZddlZddlZddlmZddlmZddlZej	ddkZ
e��dkZejdkZ
yeZWnek
r�eZYnXdd	�Zd
d�Zdd
�Zdd�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)z7Helper classes use for fake file system implementation.�N)�copy)�S_IFLNK�ZPyPy�win32cCs.yt|ttf�Stk
r(t|t�SXdS)z(Return True if `val` is of integer type.N)�
isinstance�int�long�	NameError)�val�r�A/opt/alt/python37/lib/python3.7/site-packages/pyfakefs/helpers.py�is_int_type!sr
cCstst|d�St|ttf�S)zLReturn True if `val` is a bytes-like object, False for a unicode
    string.�encode)�IS_PY2�hasattrr�
memoryview�str)r
rrr�is_byte_string)srcCs*y
t|t�Stk
r$t|d�SXdS)zLReturn True if `val` is a unicode string, False for a bytes-like
    object.rN)r�unicoder	r)r
rrr�is_unicode_string1s
rcCstjdkrt�|�}|S)N)r�)�sys�version_info�os�fspath)Zdir_namerrr�make_string_path:s

rc@sXeZdZdZyeZWnek
r,eZYnXej	dkZ
d+dd�Zedd��Z
e
jdd��Z
d	d
�Zdd�Zd
d�Zdd�Zed,dd��Zedd��Zedd��Zedd��Zejdd��Zejdd��Zejdd��Zedd��Zejdd��Zdd �Zej	d!k�rTed"d#��Zed$d%��Zed&d'��Zejd(d#��Zejd)d%��Zejd*d'��ZdS)-�FakeStatResultz�Mimics os.stat_result for use as return type of `stat()` and similar.
    This is needed as `os.stat_result` has no possibility to set
    nanosecond times directly.
    )��NcCsjd|_d|_d|_d|_d|_||_||_d|_||_|dk	rP|�	|d�|_
nd|_
|j
|_|j
|_dS)Nrge��A)
�
_use_float�st_mode�st_ino�st_dev�st_nlink�st_uid�st_gid�_st_size�
is_windows�	long_type�_st_atime_ns�_st_mtime_ns�_st_ctime_ns)�selfr'Zuser_idZgroup_idZinitial_timerrr�__init__KszFakeStatResult.__init__cCs|jdkr|��S|jS)N)r�stat_float_times)r,rrr�	use_float\s
zFakeStatResult.use_floatcCs
||_dS)N)r)r,r
rrrr/bscCs�t|t�o�|j|jko�|j|jko�|j|jko�|j|jko�|j|jko�|j|jko�|j|jko�|j	|j	ko�|j
|j
ko�|j|jkS)N)rrr)r+r*�st_sizer%r$r#r"r!r )r,�otherrrr�__eq__fs
zFakeStatResult.__eq__cCs
||kS)Nr)r,r1rrr�__ne__uszFakeStatResult.__ne__cCst|�}|j|_|S)ztReturn a copy where the float usage is hard-coded to mimic the
        behavior of the real os.stat_result.
        )rr/)r,�stat_resultrrrrxszFakeStatResult.copycCs~|j|_|j|_|j|_|j|_tjdkrb|�|jd�|_	|�|j
d�|_|�|jd�|_
n|j|_	|j|_|j|_
dS)z�Set values from a real os.stat_result.
        Note: values that are controlled by the fake filesystem are not set.
        This includes st_ino, st_dev and st_nlink.
        )rrge��AN)r r$r%r0r&rrr(�st_atimer)�st_mtimer*�st_ctimer+�st_atime_ns�st_mtime_ns�st_ctime_ns)r,r4rrr�set_from_stat_result�s
z#FakeStatResult.set_from_stat_resultcCs|dk	rt|�|_|jS)auDetermine whether a file's time stamps are reported as floats
        or ints.

        Calling without arguments returns the current value.
        The value is shared by all instances of FakeOsModule.

        Args:
            newvalue: If `True`, mtime, ctime, atime are reported as floats.
                Otherwise, they are returned as ints (rounding down).
        N)�bool�_stat_float_times)�clsZnewvaluerrrr.�s
zFakeStatResult.stat_float_timescCs|jd}|jr|St|�S)z$Return the creation time in seconds.ge��A)r+r/r)r,�ctimerrrr7�s
zFakeStatResult.st_ctimecCs|jd}|jr|St|�S)z"Return the access time in seconds.ge��A)r)r/r)r,Zatimerrrr5�s
zFakeStatResult.st_atimecCs|jd}|jr|St|�S)z(Return the modification time in seconds.ge��A)r*r/r)r,�mtimerrrr6�s
zFakeStatResult.st_mtimecCs|�|d�|_dS)z!Set the creation time in seconds.ge��AN)r(r+)r,r
rrrr7�scCs|�|d�|_dS)zSet the access time in seconds.ge��AN)r(r))r,r
rrrr5�scCs|�|d�|_dS)z%Set the modification time in seconds.ge��AN)r(r*)r,r
rrrr6�scCs|jt@tkr|jrdS|jS)Nr)r rr'r&)r,rrrr0�szFakeStatResult.st_sizecCs
||_dS)N)r&)r,r
rrrr0�scCs�ddl}||jkr|jS||jkr(|jS||jkr8|jS||jkrH|jS||j	krX|j
S||jkrh|jS||j
krx|jS||jkr�t|j�S||jkr�t|j�S||jkr�t|j�Std��dS)z9Implement item access to mimic `os.stat_result` behavior.rNzInvalid item)�stat�ST_MODEr �ST_INOr!�ST_DEVr"�ST_NLINKr#�ST_UIDr$�ST_GIDr%�ST_SIZEr0�ST_ATIMErr5�ST_MTIMEr6�ST_CTIMEr7�
ValueError)r,�itemrArrr�__getitem__�s,












zFakeStatResult.__getitem__)rrcCs|jS)z&Return the access time in nanoseconds.)r))r,rrrr8�szFakeStatResult.st_atime_nscCs|jS)z,Return the modification time in nanoseconds.)r*)r,rrrr9�szFakeStatResult.st_mtime_nscCs|jS)z(Return the creation time in nanoseconds.)r+)r,rrrr:�szFakeStatResult.st_ctime_nscCs
||_dS)z#Set the access time in nanoseconds.N)r))r,r
rrrr8�scCs
||_dS)z:Set the modification time of the fake file in nanoseconds.N)r*)r,r
rrrr9�scCs
||_dS)z6Set the creation time of the fake file in nanoseconds.N)r+)r,r
rrrr:s)N)N)�__name__�
__module__�__qualname__�__doc__rr(r	rrrr=r-�propertyr/�setterr2r3rr;�classmethodr.r7r5r6r0rNr8r9r:rrrrr@s>


rc@s�eZdZdZd)dd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	d*dd�Z
d+dd�Zdd�Zd,dd�Z
dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�ZdS)-�FileBufferIOa.Stream class that handles both Python2 and Python3 string and
    byte contents for files. The standard io.StringIO cannot be used
    for strings due to the slightly different handling of newline mode.
    Uses an io.BytesIO stream for the raw data and adds handling of encoding
    and newlines.
    N�
F�strictcCsJ||_||_||_||_||_t��|_|dk	rF|�|�|j�	d�dS)Nr)
�_newline�	_encoding�errors�_linesep�binary�io�BytesIO�_bytestream�putvalue�seek)r,�contents�linesepr]�newline�encodingr[rrrr-s

zFileBufferIO.__init__cCs|jpt�d�S)NF)rZ�locale�getpreferredencoding)r,rrrrfszFileBufferIO.encodingcCst|�r|S|�|��|j�S)N)rrrfr[)r,rcrrr�encoded_stringszFileBufferIO.encoded_stringcCs tr|js|S|�|��|j�S)N)rrZ�decoderfr[)r,rcrrr�decoded_string#s
zFileBufferIO.decoded_stringcCs>|jr
|S|jdkr"|�d|j�S|jdkr0|S|�d|j�S)N)N�-rW)�rW)r]rY�replacer\)r,�srrr�convert_newlines_for_writing(s

z)FileBufferIO.convert_newlines_for_writingcCs:|jdkr|�dd��dd�S|jdkr6|�|jd�S|S)Nz
rW�
rl)rYrnr\)r,rorrr�convert_newlines_after_reading1s


z+FileBufferIO.convert_newlines_after_reading���cCs&|j�|�}|jr|S|�|�|��S)N)r`�readr]rrrk)r,�sizercrrrrt8s
zFileBufferIO.readc
Csn|j��}|j�|�}|jr&|}d}n|�|�|��}d}d}|jdkrj|�|�}|dkrh|�|�d}n�|jdkr�|�|�}|dkr�||dt	d�kr�d}n&|dkr�||dt	d�kr�d	}nd}|�|�t
|�}nJ|jd
kr�dn|j}|�|�}|dk�r$t
|�}	|�|���|	}||	7}|dk�r>t
|�}t
|�}|j�||�|j�rb|d|�S|d|�S)N�
rWr�rm�
rqrz
rl)
r`�tellrtr]rrrkrY�_linelen_for_universal_newlines�find�ord�lenrrb)
r,ruZseek_pos�
byte_contentsZ
read_contentsZLF�end_pos�lengthreZnl_lenrrr�readline?sD







zFileBufferIO.readlinecCs~|jr|�d�dS|�d�}|�d�}|dkr<|dkr<dS|dkrZ||ksT|dkrZ|}n|}||krv|d|krv|}|dS)Nrvrwrxrsr)r]r{)r,r~Zpos_lfZpos_crrrrrrzis

z,FileBufferIO._linelen_for_universal_newlinescCsN|}g}x@|�|�}|s|S|�|�|dkr
|t|�8}|dkr
|Sq
WdS)Nr)r��appendr})r,ruZremaining_size�lines�linerrr�	readlinesxs

zFileBufferIO.readlinescCs|j�|�|��dS)N)r`�writeri)r,rorrrra�szFileBufferIO.putvaluecCs:ts|jt|�krtd��|�|�}t|�}|�|�|S)NzIncorrect type for writing)rr]r�	TypeErrorrpr}ra)r,rorcr�rrrr��s

zFileBufferIO.writecCsx|D]}|�|�qWdS)N)r�)r,r�r�rrr�
writelines�s
zFileBufferIO.writelinescCs|S)Nr)r,rrr�__iter__�szFileBufferIO.__iter__cCs|��}|st�|S)N)r��
StopIteration)r,r�rrr�__next__�szFileBufferIO.__next__cCs|��S)N)r�)r,rrr�next�szFileBufferIO.nextcCst|j|�S)N)�getattrr`)r,�namerrr�__getattr__�szFileBufferIO.__getattr__)NrWFNNrX)rs)rs)rs)rOrPrQrRr-rfrirkrprrrtr�rzr�rar�r�r�r�r�r�rrrrrVs&
	

*

rVc@seZdZdZdd�ZdS)�NullFileBufferIOz8Special stream for null device. Does nothing on writing.cCsdS)Nr)r,rorrrra�szNullFileBufferIO.putvalueN)rOrPrQrRrarrrrr��sr�)rRr^rg�platformrrrArrrrZpython_implementationZIS_PYPYZIS_WINrZ	text_typer	rr
rrr�objectrrVr�rrrr�<module>
s.

	I