
    ,h9                         d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZ dee   deee      d	ee   fd
Zded	efdZded	efdZ G d d      ZeZy)zFake User Agent retriever.    N)Iterable)AnyOptionalUnion)logger)BrowserUserAgentDataloaddefaultkwargreturnc           	      ^   t        |      dk7  rt        dt        |       d      t        t        |j	                                     \  }}|t        |       S t        |t              r|gS 	 t        |      S # t        $ r+}t        d| dt        |      j                   d      |d}~ww xY w)a  Ensure the given value is an Iterable and convert it to a list.

    Args:
        default (Iterable[str]): Default iterable to use if value is `None`.
        **kwarg (Optional[Iterable[str]]): A single keyword argument containing the value to check
            and convert.

    Raises:
        ValueError: If more than one keyword argument is provided.
        TypeError: If the value is not None, not a str, and not iterable.

    Returns:
        list[str]: A list containing the items from the iterable.
       z=ensure_iterable expects exactly one keyword argument but got .N'z<' must be an iterable of str, a single str, or None but got )len
ValueErrornextiteritemslist
isinstancestr	TypeErrortype__name__)r
   r   
param_namevaluetes        U/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/fake_useragent/fake.py_ensure_iterabler       s    " 5zQKCPUJ<WXY
 	
 T%++-01J}G}%wE{ 
|WE{##$A'
 	s   -
A8 8	B,&B''B,r   c                 `    	 t        |       S # t        $ r}d|  d}t        |      |d}~ww xY w)zEnsure the given value is a float.

    Args:
        value (Any): The value to check and convert.

    Raises:
        ValueError: If the value is not a float.

    Returns:
        float: The float value.
    z+Value must be convertible to float but got r   N)floatr   )r   vemsgs      r   _ensure_floatr%   1   s;    &U| &;E7!Do2%&s   
 	-(-attribute_namec                     dt        d      z  dz   }t        |       |k\  xr6 | j                         xr$ | j                  d      xr | j                  d      S )zJudge whether the given attribute name is the name of a magic method(e.g. __iter__).

    Args:
        attribute_name (str): The attribute name to check.

    Returns:
        bool: Whether the given attribute name is magic.
       __r   )r   isascii
startswithendswith)r&   magic_min_lengths     r   _is_magic_namer.   D   sc     3t9}q(N// 	*""$	*%%d+	* ##D)	    c                   t    e Zd ZdZ	 	 	 	 	 	 	 d!deee      deee      dededeee      dedeee      fd	Zde	ee
e   f   d
efdZ	 d"dee	ee
e   f      d
e
e   fdZded
e	eef   fdZde	ee
e   f   d
e	eef   f fdZed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Zed
efd       Z ed
efd        Z! xZ"S )#FakeUserAgenta&  Fake User Agent retriever.

    Args:
        browsers (Optional[Iterable[str]], optional): If given, will only ever return user agents
            from these browsers. If None, set to:
            `["Google", "Chrome", "Firefox", "Edge", "Opera"," Safari", "Android", "Yandex Browser", "Samsung Internet", "Opera Mobile",
              "Mobile Safari", "Firefox Mobile", "Firefox iOS", "Chrome Mobile", "Chrome Mobile iOS", "Mobile Safari UI/WKWebView",
              "Edge Mobile", "DuckDuckGo Mobile", "MiuiBrowser", "Whale", "Twitter", "Facebook", "Amazon Silk"]`.
            Defaults to None.
        os (Optional[Iterable[str]], optional): If given, will only ever return user agents from
            these operating systems. If None, set to `["Windows", "Linux", "Ubuntu", "Chrome OS", "Mac OS X", "Android","iOS"]`. Defaults to
            None.
        min_version (float, optional): Will only ever return user agents with versions greater than
            this one. Defaults to 0.0.
        min_percentage (float, optional): Filter user agents based on usage.
            Defaults to 0.0.
        platforms (Optional[Iterable[str]], optional): If given, will only return the user-agents with
            the provided platform type. If None, set to `["desktop", "mobile", "tablet"]`. Defaults to None.
        fallback (str, optional): User agent to use if there are any issues retrieving a user agent.
            Defaults to `"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
            Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"`.
        safe_attrs (Optional[Iterable[str]], optional): `FakeUserAgent` uses a custom `__getattr__`
            to facilitate retrieval of user agents by browser. If you need to prevent some
            attributes from being treated as browsers, pass them here. If None, all attributes will
            be treated as browsers. Defaults to ["shape"] to prevent unintended calls in IDEs like PyCharm.

    Raises:
        TypeError: If `fallback` isn't a `str` or `safe_attrs` contains non-`str` values.
    browsersosmin_versionmin_percentage	platformsfallback
safe_attrsc                 l   t        |g d      | _        t        |g d      | _        t        |      | _        t        |      | _        t        |g d      | _        t        |t              s$dt        |      j                   d}t        |      || _        |d	g}t        |t               
      }|D 	cg c]  }	t        |	t               }
}	t        |
      s1t        |
      D cg c]
  \  }}|r	| }}}d| d}t        |      t        |      | _        t#               | _        y c c}	w c c}}w )N)GoogleChromeFirefoxEdgeOperaSafariAndroidzYandex BrowserzSamsung InternetOpera MobileMobile SafariFirefox MobileFirefox iOSChrome MobileChrome Mobile iOSzMobile Safari UI/WKWebViewEdge MobilezDuckDuckGo MobileMiuiBrowserWhaleTwitterFacebookzAmazon Silk)r2   r
   )WindowsLinuxUbuntuz	Chrome OSzMac OS Xr@   iOS)r3   r
   )desktopmobiletablet)r6   r
   zfallback must be a str but got r   shape)r8   r
   z2safe_attrs must be an iterable of str but indices z	 are not.)r    r2   r3   r%   r5   r4   r6   r   r   r   r   r   r7   setall	enumerater8   r	   data_browsers)selfr2   r3   r4   r5   r6   r7   r8   r$   attrstr_safe_attrsidxis_strbad_indicess                 r   __init__zFakeUserAgent.__init__u   s2    )
: #
 ,N;(5))H
 (C(3DN4K4K3LANCC.  !J%SUK
<FGD*T3/GG>"'0'@#VK  G{mS\]CC. j/ "V Hs   6D+(
D03D0r   c                    	 |dk(  r| j                         }n| j                  |      }t        j                  |      S # t        t        f$ r3 t        j                  d| d       | j                  ddddd	d
dddd
cY S w xY w)a  Get a browser user agent based on the filters.

        Args:
            browsers (str): The browser name(s) to get. Special keyword "random" will return a random user-agent string.

        Returns:
            BrowserUserAgentData: The user agent with additional data.
        random)browsers_to_filterz*Error occurred during getting browser(s): z#, but was suppressed with fallback.g      Y@rP   Nr=   z	122.0.0.0g     ^@win3210Win32)
	useragentpercentr   device_brandbrowserbrowser_versionbrowser_version_major_minorr3   
os_versionplatform)_filter_useragentsr`   choiceKeyError
IndexErrorr   warningr7   )rX   r2   filtered_browserss      r   
getBrowserzFakeUserAgent.getBrowser   s    "	8#
 %)$;$;$=! %)$;$;x$;$X! ==!233*% 	NN<XJ G4 4 "]] ! $!#./4"# 	s   <? ?B Bra   c                      t        t         fd j                              }r+t        t              rgt        t        fd|            }|S )a  Filter the user agents based on filters set in the instance, and an optional browser name.

        User agents from the data file are filtered based on the attributes passed upon
        instantiation.

        Args:
            browsers_to_filter (Union[str, None], optional): A specific browser name you want results for in
                this particular call. If None, don't apply extra filters. Defaults to None.

        Returns:
            list[BrowserUserAgentData]: A filtered list of user agents.
        c                     | d   j                   v xrL | d   j                  v xr9 | d   j                  v xr& | d   j                  k\  xr | d   j                  k\  S )Nrh   r3   r   rj   rf   )r2   r3   r6   r4   r5   )xrX   s    r   <lambda>z2FakeUserAgent._filter_useragents.<locals>.<lambda>  sx    !I,$--7 8dGtww&8fI>>"8 348H8HH	8
 iLD$7$77 r/   c                     | d   v S )Nrh    )rv   ra   s    r   rw   z2FakeUserAgent._filter_useragents.<locals>.<lambda>  s    a	l.@@ r/   )r   filterrW   r   r   )rX   ra   filtered_useragentss   `` r   rm   z FakeUserAgent._filter_useragents   sb    " #8 ""

 ,c2&8%9""&@BU# #"r/   rY   c                 $    | j                  |      S )a&  Get a user agent by key lookup, as if it were a dictionary (i.e., `ua['random']`).

        Args:
            attr (str): Browser name to get.

        Returns:
            Union[str, Any]: The user agent string if not a `self.safe_attr`, otherwise the
                attribute value.
        __getattr__)rX   rY   s     r   __getitem__zFakeUserAgent.__getitem__  s     %%r/   c                    t        |t              r,t        |      s|| j                  v rMt        t
        |   |      S t        |t              r*|D ]%  }|| j                  v st        t
        |   |      c S  | j                  |      d   S )a  Get a user agent string by attribute lookup.

        Args:
            attr (str): Browser name to get. Special keyword "random" will return a user agent from
                any browser allowed by the instance's `self.browsers` filter.

        Returns:
            Union[str, Any]: The user agent string if not a `self.safe_attr`, otherwise the
                attribute value.
        re   )	r   r   r.   r8   super	UserAgent__getattribute__r   rs   )rX   rY   a	__class__s      r   r~   zFakeUserAgent.__getattr__+  s     dC d#tt'>Y>tDDd# F' DB1EEF t$[11r/   c                 (    | j                  g d      S )Get a random Chrome user agent.r;   rE   rF   r}   rX   s    r   chromezFakeUserAgent.chrome@  s      PQQr/   c                     | j                   S )r   )r   r   s    r   googlechromezFakeUserAgent.googlechromeE  s     {{r/   c                     | j                   S ) Get a random Firefox user agent.)firefoxr   s    r   ffzFakeUserAgent.ffJ  s     ||r/   c                 (    | j                  g d      S )r   )r<   rC   rD   r}   r   s    r   r   zFakeUserAgent.firefoxO  s      LMMr/   c                 (    | j                  ddg      S )zGet a random Safari user agent.r?   rB   r}   r   s    r   safarizFakeUserAgent.safariT  s     ? ;<<r/   c                 (    | j                  ddg      S )zGet a random Opera user agent.r>   rA   r}   r   s    r   operazFakeUserAgent.operaY  s     . 9::r/   c                 &    | j                  dg      S )zGet a random Google user agent.r:   r}   r   s    r   googlezFakeUserAgent.google^  s     
++r/   c                 (    | j                  ddg      S )zGet a random Edge user agent.r=   rG   r}   r   s    r   edgezFakeUserAgent.edgec  s      788r/   c                 $    | j                  d      S )zGet a random user agent.r`   r}   r   s    r   r`   zFakeUserAgent.randomh  s     ))r/   c                 (    | j                  g d      S )z5Get a random Chrome user agent, with additional data.r   rs   r   s    r   	getChromezFakeUserAgent.getChromem  s     OPPr/   c                 $    | j                  d      S )z6Get a random Firefox user agent, with additional data.r<   r   r   s    r   
getFirefoxzFakeUserAgent.getFirefoxr  s     y))r/   c                 (    | j                  ddg      S )5Get a random Safari user agent, with additional data.r?   rB   r   r   s    r   	getSafarizFakeUserAgent.getSafariw  s     /:;;r/   c                 (    | j                  ddg      S )r   r>   rA   r   r   s    r   getOperazFakeUserAgent.getOpera|  s     899r/   c                 &    | j                  dg      S )z5Get a random Google user agent, with additional data.r:   r   r   s    r   	getGooglezFakeUserAgent.getGoogle  s     z**r/   c                 (    | j                  ddg      S )z3Get a random Edge user agent, with additional data.r=   rG   r   r   s    r   getEdgezFakeUserAgent.getEdge  s     677r/   c                 $    | j                  d      S )z.Get a random user agent, with additional data.r`   r   r   s    r   	getRandomzFakeUserAgent.getRandom  s     x((r/   )NN        r   Nz}Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0N)N)#r   
__module____qualname____doc__r   r   r   r"   r^   r   r   r   rs   rm   r   r   r~   propertyr   r   r   r   r   r   r   r   r`   r   r   r   r   r   r   r   __classcell__)r   s   @r   r1   r1   V   s   @ -1&*  #-1; /3P$8C=)P$ Xc]#P$ 	P$
 P$ HSM*P$ P$ Xc]+P$d+5d3i#8 +=Q +\ EI)#"*5d3i+@"A)#	"	#)#V
& 
&c3h 
&2c49n 5 2%S/ 2* R R R c   C   N N N = = = ;s ; ; , , , 9c 9 9 * * * Q/ Q Q *0 * * </ < < :. : : +/ + + 8- 8 8 )/ ) )r/   r1   )r   r`   collections.abcr   typingr   r   r   fake_useragent.logr   fake_useragent.utilsr   r	   r   r   r    r"   r%   boolr.   r1   r   ry   r/   r   <module>r      s       $ ' ' % ;##(0#(?#	#Y#L& & &&3 4 $x) x)x	 	r/   