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.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��PyPy�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!srcCstst|d�St|ttf�S)zLReturn True if `val` is a bytes-like object, False for a unicode
    string.�encode)�IS_PY2�hasattrr�
memoryview�str)rrrr
�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)rrrr
�is_unicode_string1s
rcCstjdkrt�|�}|S)N)r�)�sys�version_info�os�fspath)�dir_namerrr
�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)�user_id�group_id�initial_timerrr
�__init__KszFakeStatResult.__init__cCs|jdkr|��S|jS)N)r!�stat_float_times)r.rrr
�	use_float\s
zFakeStatResult.use_floatcCs
||_dS)N)r!)r.rrrr
r4bscCs�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.�otherrrr
�__eq__fs
zFakeStatResult.__eq__cCs
||kS)Nr)r.r6rrr
�__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.
        )rr4)r.�stat_resultrrr
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'r5r(rrr*�st_atimer+�st_mtimer,�st_ctimer-�st_atime_ns�st_mtime_ns�st_ctime_ns)r.r9rrr
�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)�cls�newvaluerrr
r3�s
zFakeStatResult.stat_float_timescCs|jd}|jr|St|�S)z$Return the creation time in seconds.ge��A)r-r4r)r.�ctimerrr
r<�s
zFakeStatResult.st_ctimecCs|jd}|jr|St|�S)z"Return the access time in seconds.ge��A)r+r4r)r.�atimerrr
r:�s
zFakeStatResult.st_atimecCs|jd}|jr|St|�S)z(Return the modification time in seconds.ge��A)r,r4r)r.�mtimerrr
r;�s
zFakeStatResult.st_mtimecCs|�|d�|_dS)z!Set the creation time in seconds.ge��AN)r*r-)r.rrrr
r<�scCs|�|d�|_dS)zSet the access time in seconds.ge��AN)r*r+)r.rrrr
r:�scCs|�|d�|_dS)z%Set the modification time in seconds.ge��AN)r*r,)r.rrrr
r;�scCs|jt@tkr|jrdS|jS)Nr)r"rr)r()r.rrr
r5�szFakeStatResult.st_sizecCs
||_dS)N)r()r.rrrr
r5�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_SIZEr5�ST_ATIMErr:�ST_MTIMEr;�ST_CTIMEr<�
ValueError)r.�itemrHrrr
�__getitem__�s,












zFakeStatResult.__getitem__)rrcCs|jS)z&Return the access time in nanoseconds.)r+)r.rrr
r=�szFakeStatResult.st_atime_nscCs|jS)z,Return the modification time in nanoseconds.)r,)r.rrr
r>�szFakeStatResult.st_mtime_nscCs|jS)z(Return the creation time in nanoseconds.)r-)r.rrr
r?�szFakeStatResult.st_ctime_nscCs
||_dS)z#Set the access time in nanoseconds.N)r+)r.rrrr
r=�scCs
||_dS)z:Set the modification time of the fake file in nanoseconds.N)r,)r.rrrr
r>�scCs
||_dS)z6Set the creation time of the fake file in nanoseconds.N)r-)r.rrrr
r?s)N)N)�__name__�
__module__�__qualname__�__doc__r	r*r
rrrrBr2�propertyr4�setterr7r8rr@�classmethodr3r<r:r;r5rUr=r>r?rrrr
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�lineseprd�newline�encodingrbrrr
r2s

zFileBufferIO.__init__cCs|jpt�d�S)NF)ra�locale�getpreferredencoding)r.rrr
rmszFileBufferIO.encodingcCst|�r|S|�|��|j�S)N)rrrmrb)r.rjrrr
�encoded_stringszFileBufferIO.encoded_stringcCs tr|js|S|�|��|j�S)N)rra�decodermrb)r.rjrrr
�decoded_string#s
zFileBufferIO.decoded_stringcCs>|jr
|S|jdkr"|�d|j�S|jdkr0|S|�d|j�S)N)N�-r^)�r^)rdr`�replacerc)r.�srrr
�convert_newlines_for_writing(s

z)FileBufferIO.convert_newlines_for_writingcCs:|jdkr|�dd��dd�S|jdkr6|�|jd�S|S)Nz
r^�
rs)r`rurc)r.rvrrr
�convert_newlines_after_reading1s


z+FileBufferIO.convert_newlines_after_reading���cCs&|j�|�}|jr|S|�|�|��S)N)rg�readrdryrr)r.�sizerjrrr
r{8s
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�
r^r�rt�
rxrz
rs)
rg�tellr{rdryrrr`�_linelen_for_universal_newlines�find�ord�lenrri)
r.r|�seek_pos�
byte_contents�
read_contents�LF�end_pos�lengthrl�nl_lenrrr
�readline?sD







zFileBufferIO.readlinecCs~|jr|�d�dS|�d�}|�d�}|dkr<|dkr<dS|dkrZ||ksT|dkrZ|}n|}||krv|d|krv|}|dS)Nr}r~rrzr)rdr�)r.r��pos_lf�pos_crr�rrr
r�is

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

zFileBufferIO.readlinescCs|j�|�|��dS)N)rg�writerp)r.rvrrr
rh�szFileBufferIO.putvaluecCs:ts|jt|�krtd��|�|�}t|�}|�|�|S)NzIncorrect type for writing)rrdr�	TypeErrorrwr�rh)r.rvrjr�rrr
r��s

zFileBufferIO.writecCsx|D]}|�|�qWdS)N)r�)r.r�r�rrr
�
writelines�s
zFileBufferIO.writelinescCs|S)Nr)r.rrr
�__iter__�szFileBufferIO.__iter__cCs|��}|st�|S)N)r��
StopIteration)r.r�rrr
�__next__�szFileBufferIO.__next__cCs|��S)N)r�)r.rrr
�next�szFileBufferIO.nextcCst|j|�S)N)�getattrrg)r.�namerrr
�__getattr__�szFileBufferIO.__getattr__)Nr^FNNr_)rz)rz)rz)rVrWrXrYr2rmrprrrwryr{r�r�r�rhr�r�r�r�r�r�rrrr
r]s&
	

*

r]c@seZdZdZdd�ZdS)�NullFileBufferIOz8Special stream for null device. Does nothing on writing.cCsdS)Nr)r.rvrrr
rh�szNullFileBufferIO.putvalueN)rVrWrXrYrhrrrr
r��sr�)rYrern�platformrrrHrrrr�python_implementation�IS_PYPY�IS_WINr�	text_typer
rrrrr�objectrr]r�rrrr
�<module>
s.

	I