U
    AÞ«^»  ã                   @   s0   d Z ddlZG dd„ deƒZG dd„ deƒZdS )a  
    werkzeug.useragents
    ~~~~~~~~~~~~~~~~~~~

    This module provides a helper to inspect user agent strings.  This module
    is far from complete but should work for most of the currently available
    browsers.


    :copyright: 2007 Pallets
    :license: BSD-3-Clause
é    Nc                   @   s6   e Zd ZdZdZdZdZe d¡Z	dd„ Z
dd	„ Zd
S )ÚUserAgentParserz5A simple user agent parser.  Used by the `UserAgent`.))z cros Zchromeos)z
iphone|iosZiphone)Úipadr   )zdarwin|mac|os\s*xZmacos)ÚwinZwindows)Úandroidr   )Únetbsdr   )Úopenbsdr   )Úfreebsdr   )Z	dragonflyZdragonflybsd)z(sun|i86)osÚsolaris)zx11|lin(\b|ux)?Úlinux)znintendo\s+wiiZwii)Úirixr   )zhp-?uxZhpux)Úaixr   )zsco|unix_svZsco)Úbsdr   )Úamigar   )zblackberry|playbookZ
blackberry)Úsymbianr   ))Z	googlebotZgoogle)ZmsnbotZmsn)Úyahoor   )z
ask jeevesÚask)zaol|america\s+online\s+browserZaol)z	opera|oprZopera)Úedger   )zchrome|criosZchrome)Ú	seamonkeyr   )z"firefox|firebird|phoenix|iceweaselZfirefox)Úgaleonr   )zsafari|versionZsafari)Úwebkitr   )Úcaminor   )Ú	konquerorr   )zk-meleonZkmeleon)Únetscaper   )z4msie|microsoft\s+internet\s+explorer|trident/.+? rv:Zmsie)Úlynxr   )Úlinksr   )ZBaiduspiderZbaidu)ZbingbotZbing)Úmozillar   z(?:%s)[/\sa-z(]*(\d+[.\da-z]+)?za(?:;\s*|\s+)(\b\w{2}\b(?:-\b\w{2}\b)?)\s*;|(?:\(|\[|;)\s*(\b\w{2}\b(?:-\b\w{2}\b)?)\s*(?:\]|\)|;)c                    s,   dd„ ˆ j D ƒˆ _ ‡ fdd„ˆ jD ƒˆ _d S )Nc                 S   s"   g | ]\}}|t  |t j¡f‘qS © )ÚreÚcompileÚI©Ú.0ÚaÚbr   r   ú7/tmp/pip-unpacked-wheel-74fb410_/werkzeug/useragents.pyÚ
<listcomp>L   s     z,UserAgentParser.__init__.<locals>.<listcomp>c                    s(   g | ] \}}|t  ˆ j| t j¡f‘qS r   )r   r   Ú_browser_version_rer   r    ©Úselfr   r$   r%   M   s   ÿ)Ú	platformsÚbrowsersr'   r   r'   r$   Ú__init__K   s    
þzUserAgentParser.__init__c                 C   sœ   | j D ]\}}| |¡}|d k	r q*qd }| jD ](\}}| |¡}|d k	r0| d¡} qbq0d  }}| j |¡}|d k	rŒ| d¡pˆ| d¡}nd }||||fS )Né   é   )r)   Úsearchr*   ÚgroupÚ_language_re)r(   Ú
user_agentÚplatformÚregexÚmatchÚbrowserÚversionÚlanguager   r   r$   Ú__call__R   s     


zUserAgentParser.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r*   r&   r   r   r0   r+   r8   r   r   r   r$   r      s   ÿr   c                   @   sB   e Zd ZdZeƒ Zdd„ Zdd„ Zdd„ Zdd	„ Z	e	Z
d
d„ ZdS )Ú	UserAgenta±  Represents a user agent.  Pass it a WSGI environment or a user agent
    string and you can inspect some of the details from the user agent
    string via the attributes.  The following attributes exist:

    .. attribute:: string

       the raw user agent string

    .. attribute:: platform

       the browser platform. ``None`` if not recognized.
       The following platforms are currently recognized:

       -   `aix`
       -   `amiga`
       -   `android`
       -   `blackberry`
       -   `bsd`
       -   `chromeos`
       -   `dragonflybsd`
       -   `freebsd`
       -   `hpux`
       -   `ipad`
       -   `iphone`
       -   `irix`
       -   `linux`
       -   `macos`
       -   `netbsd`
       -   `openbsd`
       -   `sco`
       -   `solaris`
       -   `symbian`
       -   `wii`
       -   `windows`

    .. attribute:: browser

        the name of the browser. ``None`` if not recognized.
        The following browsers are currently recognized:

        -   `aol` *
        -   `ask` *
        -   `baidu` *
        -   `bing` *
        -   `camino`
        -   `chrome`
        -   `edge`
        -   `firefox`
        -   `galeon`
        -   `google` *
        -   `kmeleon`
        -   `konqueror`
        -   `links`
        -   `lynx`
        -   `mozilla`
        -   `msie`
        -   `msn`
        -   `netscape`
        -   `opera`
        -   `safari`
        -   `seamonkey`
        -   `webkit`
        -   `yahoo` *

        (Browsers marked with a star (``*``) are crawlers.)

    .. attribute:: version

        the version of the browser. ``None`` if not recognized.

    .. attribute:: language

        the language of the browser. ``None`` if not recognized.
    c                 C   s:   t |tƒr| dd¡}|| _|  |¡\| _| _| _| _d S )NZHTTP_USER_AGENTÚ )	Ú
isinstanceÚdictÚgetÚstringÚ_parserr2   r5   r6   r7   )r(   Zenviron_or_stringr   r   r$   r+   ¶   s    
ÿzUserAgent.__init__c                 C   s   | j S ©N©rB   r'   r   r   r$   Ú	to_header¾   s    zUserAgent.to_headerc                 C   s   | j S rD   rE   r'   r   r   r$   Ú__str__Á   s    zUserAgent.__str__c                 C   s
   t | jƒS rD   )Úboolr5   r'   r   r   r$   Ú__nonzero__Ä   s    zUserAgent.__nonzero__c                 C   s   d| j j| j| jf S )Nz
<%s %r/%s>)Ú	__class__r9   r5   r6   r'   r   r   r$   Ú__repr__É   s    zUserAgent.__repr__N)r9   r:   r;   r<   r   rC   r+   rF   rG   rI   Ú__bool__rK   r   r   r   r$   r=   h   s   Kr=   )r<   r   Úobjectr   r=   r   r   r   r$   Ú<module>   s   W