U
    n5{i$  ã                   @   s|   d ddddgZ ddlZddlZddlZddlmZ ddlmZ ed	œd
d„Z	ddddddœZ
G dd„ dƒZeƒ Ze ¡ ZdS )ÚsecondsÚshortPythonVersionÚPlatformÚplatformÚplatformTypeé    N)Útime)ÚOptional©Úreturnc                   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   ú:/tmp/pip-unpacked-wheel-mnhg7r0q/twisted/python/runtime.pyr      s    Úwin32ÚposixÚjava)ÚntZcer   r   zorg.python.modules.osc                   @   sö   e Zd ZU dZe ej¡Ze	e
 ed< eeƒZejZd e	e
 e	e
 ddœdd„Zedœdd	„Ze	e
 dœd
d„Zedœdd„Zedœdd„Zedœdd„Zedœdd„Zedœdd„Zd!e
edœdd„Zedœdd„Zedœdd„Zedœdd„ZdS )"r   zC
    Gives us information about the platform we're running on.
    ÚtypeN)Únamer   r
   c                 C   s&   |d k	rt  |¡| _|d k	r"|| _d S )N)ÚknownPlatformsÚgetr   Ú	_platform)Úselfr   r   r   r   r   Ú__init__,   s    zPlatform.__init__r	   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.
        N©r   ©r   r   r   r   ÚisKnown4   s    zPlatform.isKnownc                 C   s   | j S )zX
        Get platform type.

        @return: Either 'posix', 'win32' or 'java'
        r   r   r   r   r   ÚgetType<   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.
        Údarwin)r   r   r   r   r   ÚisMacOSXD   s    zPlatform.isMacOSXc                 C   s   t jdtdd� |  ¡ S )a   
        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.
        zgtwisted.python.runtime.Platform.isWinNT was deprecated in Twisted 13.0. Use Platform.isWindows instead.é   )Ú
stacklevel)ÚwarningsÚwarnÚDeprecationWarningÚ	isWindowsr   r   r   r   ÚisWinNTL   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.
        r   )r   r   r   r   r   r&   ^   s    zPlatform.isWindowsc                 C   s   t jdkot  ¡ jdk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
        r   é   )r   r   ÚgetwindowsversionÚmajorr   r   r   r   ÚisVistag   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.
        Úlinux)r   Ú
startswithr   r   r   r   ÚisLinuxo   s    zPlatform.isLinuxú/proc/1/cgroup)Ú_initCGroupLocationr
   c                 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.
        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.filepathr1   ÚexistsZ
getContentr3   Úlenr-   )r   r0   r1   ZinitCGroupsZcontrolGroupsÚgroupr   r   r   ÚisDockerw   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}.
        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 )zy
        Can threads be created?

        @return: C{True} if the threads are supported on the current platform.
        r   NF)Ú	threadingÚImportError)r   r@   r   r   r   ÚsupportsThreads¬   s
    
zPlatform.supportsThreadsc                 C   sX   zddl m}m} W n tk
r*   Y dS X zt |ƒ ¡ W n |k
rR   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._inotifyrC   rD   rA   r<   Úclose)r   rC   rD   r   r   r   ÚsupportsINotify¹   s    zPlatform.supportsINotify)NN)r/   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r<   r   r   r   ÚstrÚ__annotations__Ústaticmethodr   r   r   r   r   Úboolr   r   r    r'   r&   r+   r.   r;   r?   rB   rF   r   r   r   r   r   #   s,   
   ÿ þ	)Ú__all__r<   r   r#   r   r   Útypingr   rK   r   r   r   r   r   r   r   r   r   r   Ú<module>   s*   ûû	 )