B
    UGZ                 @   s<   d Z ddlZG dd deZG dd deZddlm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: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
    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crosZ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)osZsolaris)zx11|lin(\b|ux)?Z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 jeevesZask)zaol|america\s+online\s+browserZaol)operar   )edger   )chromer   )	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   2lib/python3.7/site-packages/werkzeug/useragents.py
<listcomp>M   s    z,UserAgentParser.__init__.<locals>.<listcomp>c                s(   g | ] \}}|t  j| t jfqS r   )r   r   _browser_version_rer   )r   r    r!   )selfr   r"   r#   N   s   )	platformsbrowsers)r%   r   )r%   r"   __init__L   s    
zUserAgentParser.__init__c             C   s   x*| j D ]\}}||}|d k	rP qW d }x8| jD ]&\}}||}|d k	r4|d}P q4W d  }}| j|}|d k	r|dp|d}nd }||||fS )N      )r&   searchr'   group_language_re)r%   Z
user_agentplatformZregexmatchbrowserversionlanguager   r   r"   __call__Q   s     


zUserAgentParser.__call__N)__name__
__module____qualname____doc__r&   r'   r$   r   r   r-   r(   r3   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.  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`
        -   `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|dd}|| _| |\| _| _| _| _d S )NZHTTP_USER_AGENT )	
isinstancedictgetstring_parserr.   r0   r1   r2   )r%   Zenviron_or_stringr   r   r"   r(      s    
zUserAgent.__init__c             C   s   | j S )N)r=   )r%   r   r   r"   	to_header   s    zUserAgent.to_headerc             C   s   | j S )N)r=   )r%   r   r   r"   __str__   s    zUserAgent.__str__c             C   s
   t | jS )N)boolr0   )r%   r   r   r"   __nonzero__   s    zUserAgent.__nonzero__c             C   s   d| j j| j| jf S )Nz
<%s %r/%s>)	__class__r4   r0   r1   )r%   r   r   r"   __repr__   s    zUserAgent.__repr__N)r4   r5   r6   r7   r   r>   r(   r?   r@   rB   __bool__rD   r   r   r   r"   r8   g   s   Jr8   )UserAgentMixin)r7   r   objectr   r8   Zwerkzeug.wrappersrF   r   r   r   r"   <module>   s   Vm