3
 [ð]ö  ã               @   sP   d Z ddlZG dd„ deƒZG dd„ deƒZddlmZ eedd	gid
ƒ [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dxZdDZejdEƒZ	dFdG„ Z
dHdI„ ZdJS )yÚUserAgentParserz5A simple user agent parser.  Used by the `UserAgent`.ÚcrosÚchromeosú
iphone|iosÚiphoneÚipadúdarwin|mac|os\s*xÚmacosÚwinÚwindowsÚandroidÚnetbsdÚopenbsdÚfreebsdÚ	dragonflyÚdragonflybsdú(sun|i86)osÚsolarisúx11|lin(\b|ux)?Úlinuxúnintendo\s+wiiÚwiiÚirixúhp-?uxÚhpuxÚaixúsco|unix_svÚscoÚbsdÚamigaúblackberry|playbookÚ
blackberryÚsymbianÚ	googlebotÚgoogleÚmsnbotÚmsnÚyahooú
ask jeevesÚaskúaol|america\s+online\s+browserÚaolÚoperaÚedgeúchrome|criosÚchromeÚ	seamonkeyú"firefox|firebird|phoenix|iceweaselÚfirefoxÚgaleonúsafari|versionÚsafariÚwebkitÚcaminoÚ	konquerorúk-meleonÚkmeleonÚnetscapeú4msie|microsoft\s+internet\s+explorer|trident/.+? rv:ÚmsieÚlynxÚlinksÚBaiduspiderÚbaiduÚbingbotÚbingÚmozillaz(?:%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 j|t jƒf‘qS © )ÚreÚcompileÚI)Ú.0ÚaÚbrE   rE   ú7/tmp/pip-build-w1as9q70/Werkzeug/werkzeug/useragents.pyú
<listcomp>L   s    z,UserAgentParser.__init__.<locals>.<listcomp>c                s(   g | ] \}}|t jˆ j| t jƒf‘qS rE   )rF   rG   Ú_browser_version_rerH   )rI   rJ   rK   )ÚselfrE   rL   rM   N   s   )Ú	platformsÚbrowsers)rO   rE   )rO   rL   Ú__init__K   s    
zUserAgentParser.__init__c             C   s    x*| j D ]\}}|j|ƒ}|d k	rP qW d }x8| jD ]&\}}|j|ƒ}|d k	r4|jdƒ}P q4W d  }}| jj|ƒ}|d k	r�|jdƒpŒ|jdƒ}nd }||||fS )Né   é   )rP   ÚsearchrQ   ÚgroupÚ_language_re)rO   Ú
user_agentÚplatformÚregexÚmatchÚbrowserÚversionÚlanguagerE   rE   rL   Ú__call__R   s     


zUserAgentParser.__call__N©r   r   ©r   r   ©r   r   ©r   r	   ©r
   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r   r   ©r    r!   ©r"   r"   )r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ©r#   r$   ©r%   r&   ©r'   r'   ©r(   r)   ©r*   r+   ©r,   r,   ©r-   r-   ©r.   r/   ©r0   r0   ©r1   r2   ©r3   r3   ©r4   r5   ©r6   r6   ©r7   r7   ©r8   r8   ©r9   r:   ©r;   r;   ©r<   r=   ©r>   r>   ©r?   r?   ©r@   rA   ©rB   rC   ©rD   rD   )ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rP   rQ   rN   rF   rG   rW   rR   r_   rE   rE   rE   rL   r      sd                                             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 )Ú	UserAgentaA  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.  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.  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

    .. attribute:: language

        the language of the browser
    c             C   s:   t |tƒr|jddƒ}|| _| j|ƒ\| _| _| _| _d S )NZHTTP_USER_AGENTÚ )	Ú
isinstanceÚdictÚgetÚstringÚ_parserrY   r\   r]   r^   )rO   Zenviron_or_stringrE   rE   rL   rR   ¶   s
    
zUserAgent.__init__c             C   s   | j S )N)r•   )rO   rE   rE   rL   Ú	to_header¾   s    zUserAgent.to_headerc             C   s   | j S )N)r•   )rO   rE   rE   rL   Ú__str__Á   s    zUserAgent.__str__c             C   s
   t | jƒS )N)Úboolr\   )rO   rE   rE   rL   Ú__nonzero__Ä   s    zUserAgent.__nonzero__c             C   s   d| j j| j| jf S )Nz
<%s %r/%s>)Ú	__class__rŒ   r\   r]   )rO   rE   rE   rL   Ú__repr__É   s    zUserAgent.__repr__N)rŒ   r�   rŽ   r�   r   r–   rR   r—   r˜   rš   Ú__bool__rœ   rE   rE   rE   rL   r�   h   s   Jr�   )Ú_DeprecatedImportModulez.wrappers.user_agentZUserAgentMixinzWerkzeug 1.0)r�   rF   Úobjectr   r�   Zwerkzeugrž   rŒ   rE   rE   rE   rL   Ú<module>   s   We