
_                 @   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netscape4msie|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