
À«‘_»  ã               @   sB   d  Z  d d l Z Gd d „  d e ƒ Z Gd 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               @   sO   e  Z d  Z d Z da Z dy Z dE Z e j dF ƒ Z	 dG dH „  Z
 dI dJ „  Z dK S)zÚ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|oprÚ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   s1   g  |  ]' \ } } | t  j | t  j ƒ f ‘ q S© )ÚreÚcompileÚI)Ú.0ÚaÚbrF   rF   ú7/tmp/pip-build-5gj8f0j9/Werkzeug/werkzeug/useragents.pyú
<listcomp>L   s   	 z,UserAgentParser.__init__.<locals>.<listcomp>c                s8   g  |  ]. \ } } | t  j ˆ  j | t  j ƒ f ‘ q SrF   )rG   rH   Ú_browser_version_rerI   )rJ   rK   rL   )ÚselfrF   rM   rN   N   s   	)Ú	platformsÚbrowsers)rP   rF   )rP   rM   Ú__init__K   s    zUserAgentParser.__init__c             C   sà   x9 |  j  D]( \ } } | j | ƒ } | d  k	 r
 Pq
 Wd  } xL |  j D]7 \ } } | j | ƒ } | d  k	 rF | j d ƒ } PqF Wd  } } |  j j | ƒ } | d  k	 rÊ | j d ƒ pÄ | j d ƒ } n d  } | | | | f S)Né   é   )rQ   ÚsearchrR   ÚgroupÚ_language_re)rP   Ú
user_agentÚplatformÚregexÚmatchÚbrowserÚversionÚlanguagerF   rF   rM   Ú__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"   )ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   ©r#   r$   ©r%   r&   ©r'   r'   ©r(   r)   ©r*   r+   ©r,   r-   ©r.   r.   ©r/   r0   ©r1   r1   ©r2   r3   ©r4   r4   ©r5   r6   ©r7   r7   ©r8   r8   ©r9   r9   ©r:   r;   ©r<   r<   ©r=   r>   ©r?   r?   ©r@   r@   ©rA   rB   ©rC   rD   ©rE   rE   )rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rQ   rR   rO   rG   rH   rX   rS   r`   rF   rF   rF   rM   r      sd                                             	r   c               @   sa   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   sU   t  | t ƒ r! | j d d ƒ } | |  _ |  j | ƒ \ |  _ |  _ |  _ |  _ d  S)NZHTTP_USER_AGENTÚ )	Ú
isinstanceÚdictÚgetÚstringÚ_parserrZ   r]   r^   r_   )rP   Zenviron_or_stringrF   rF   rM   rS   ¶   s
    	zUserAgent.__init__c             C   s   |  j  S)N)r–   )rP   rF   rF   rM   Ú	to_header¾   s    zUserAgent.to_headerc             C   s   |  j  S)N)r–   )rP   rF   rF   rM   Ú__str__Á   s    zUserAgent.__str__c             C   s   t  |  j ƒ S)N)Úboolr]   )rP   rF   rF   rM   Ú__nonzero__Ä   s    zUserAgent.__nonzero__c             C   s   d |  j  j |  j |  j f S)Nz
<%s %r/%s>)Ú	__class__r�   r]   r^   )rP   rF   rF   rM   Ú__repr__É   s    zUserAgent.__repr__N)r�   rŽ   r�   r�   r   r—   rS   r˜   r™   r›   Ú__bool__r�   rF   rF   rF   rM   r‘   h   s   J	r‘   )r�   rG   Úobjectr   r‘   rF   rF   rF   rM   Ú<module>   s   W