U
    
W[~                     @   s   d dl mZmZ d dlZd dlZd dlZd dlZd dlmZ dd Z	dddddd	Z
dejiZeG d
d dZe Ze ZejZdS )    )divisionabsolute_importN)	_oldStylec                   C   s   dt jdd  S )z?
    Returns the Python version as a dot-separated string.
    z%s.%s.%sN   )sysversion_info r   r   8/usr/lib/python3/dist-packages/twisted/python/runtime.pyshortPythonVersion   s    r
   win32posixjava)ntZcer   r   zorg.python.modules.osc                   @   s   e Zd ZdZeejZe	e
eejZejZdddZdd Zdd Zd	d
 Zdd Zdd Zdd Zdd ZdddZdd Zdd Zdd ZdS )PlatformzC
    Gives us information about the platform we're running on.
    Nc                 C   s8   |d k	r&t || _t| jtj| _|d k	r4|| _d S )N)knownPlatformsgettype_timeFunctionstimeseconds	_platform)selfnameplatformr   r   r	   __init__3   s
    zPlatform.__init__c                 C   s
   | j dkS )z
        Do we know about this platform?

        @return: Boolean indicating whether this is a known platform or not.
        @rtype: C{bool}
        Nr   r   r   r   r	   isKnown;   s    zPlatform.isKnownc                 C   s   | j S )zo
        Get platform type.

        @return: Either 'posix', 'win32' or 'java'
        @rtype: C{str}
        r   r   r   r   r	   getTypeE   s    zPlatform.getTypec                 C   s
   | j dkS )z
        Check if current platform is macOS.

        @return: C{True} if the current platform has been detected as macOS.
        @rtype: C{bool}
        darwin)r   r   r   r   r	   isMacOSXO   s    zPlatform.isMacOSXc                 C   s   t jdtdd |  S )a8  
        Are we running in Windows NT?

        This is deprecated and always returns C{True} on win32 because
        Twisted only supports Windows NT-derived platforms at this point.

        @return: C{True} if the current platform has been detected as
            Windows NT.
        @rtype: C{bool}
        zgtwisted.python.runtime.Platform.isWinNT was deprecated in Twisted 13.0. Use Platform.isWindows instead.   )
stacklevel)warningswarnDeprecationWarning	isWindowsr   r   r   r	   isWinNTY   s     zPlatform.isWinNTc                 C   s   |   dkS )z
        Are we running in Windows?

        @return: C{True} if the current platform has been detected as
            Windows.
        @rtype: C{bool}
        r   )r   r   r   r   r	   r&   k   s    zPlatform.isWindowsc                 C   s(   t tdddk	r t d dkS dS dS )z
        Check if current platform is Windows Vista or Windows Server 2008.

        @return: C{True} if the current platform has been detected as Vista
        @rtype: C{bool}
        getwindowsversionNr      F)getattrr   r(   r   r   r   r	   isVistav   s    zPlatform.isVistac                 C   s   | j dS )z
        Check if current platform is Linux.

        @return: C{True} if the current platform has been detected as Linux.
        @rtype: C{bool}
        Zlinux)r   
startswithr   r   r   r	   isLinux   s    zPlatform.isLinux/proc/1/cgroupc                 C   sn   |   sdS ddlm} ||}| rjdd | dD }|D ]$}t|dkrD|d d	rD d
S qDdS )z
        Check if the current platform is Linux in a Docker container.

        @return: C{True} if the current platform has been detected as Linux
            inside a Docker container.
        @rtype: C{bool}
        Fr   )FilePathc                 S   s   g | ]}| d qS )   :)split).0xr   r   r	   
<listcomp>   s   z%Platform.isDocker.<locals>.<listcomp>   
r   r!   s   /docker/T)r-   Ztwisted.python.filepathr/   existsZ
getContentr1   lenr,   )r   Z_initCGroupLocationr/   ZinitCGroupsZcontrolGroupsgroupr   r   r	   isDocker   s    zPlatform.isDockerc                 C   s6   |   rdS z
tj W n tk
r,   Y dS X dS dS )z
        Check for symlink support usable for Twisted's purposes.

        @return: C{True} if symlinks are supported on the current platform,
                 otherwise C{False}.
        @rtype: L{bool}
        FTN)r&   ossymlinkAttributeErrorr   r   r   r	   _supportsSymlinks   s    
zPlatform._supportsSymlinksc                 C   s.   zddl }|dk	W S  tk
r(   Y dS X dS )z
        Can threads be created?

        @return: C{True} if the threads are supported on the current platform.
        @rtype: C{bool}
        r   NF)	threadingImportError)r   r>   r   r   r	   supportsThreads   s
    
zPlatform.supportsThreadsc                 C   sd   zddl m}m} W n tk
r*   Y dS X |  r8dS zt|  W n |k
r^   Y dS X dS )zf
        Return C{True} if we can use the inotify API on this platform.

        @since: 10.1
        r   )INotifyErrorinitFT)Ztwisted.python._inotifyrA   rB   r?   r9   r:   close)r   rA   rB   r   r   r	   supportsINotify   s    zPlatform.supportsINotify)NN)r.   )__name__
__module____qualname____doc__r   r   r:   r   r   staticmethodr   r   r   r   r   r   r   r   r   r    r'   r&   r+   r-   r9   r=   r@   rD   r   r   r   r	   r   )   s    





r   )Z
__future__r   r   r:   r   r   r#   Ztwisted.python._oldstyler   r
   r   r   r   r   r   ZplatformTyper   r   r   r   r	   <module>   s*   	  ?