






"""simple docstring"""
import subprocess
import sys

from transformers import BertConfig, BertModel, BertTokenizer, pipeline
from transformers.testing_utils import TestCasePlus, require_torch



class      SCREAMING_SNAKE_CASE  (				_SCREAMING_SNAKE_CASE						):





	"""simple docstring"""




	@require_torch
	def    lowerCamelCase(self							):
		# this test is a bit tricky since TRANSFORMERS_OFFLINE can only be changed before
		# `transformers` is loaded, and it's too late for inside pytest - so we are changing it
		# while running an external program

		# python one-liner segments

		# this must be loaded before socket.socket is monkey-patched
		A_		:						Tuple	    =   """
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        """

		A_		:						Any	    =   """
mname = \"hf-internal-testing/tiny-random-bert\"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
BertTokenizer.from_pretrained(mname)
pipe = pipeline(task=\"fill-mask\", model=mname)
print(\"success\")
        """

		A_		:						Optional[Any]	    =   """
import socket
def offline_socket(*args, **kwargs): raise RuntimeError(\"Offline mode is enabled, we shouldn't access internet\")
socket.socket = offline_socket
        """

		# Force fetching the files so that we can use the cache
		A_		:						Union[str, Any]	    =   """hf-internal-testing/tiny-random-bert"""
		BertConfig.from_pretrained(lowerCAmelCase_							)
		BertModel.from_pretrained(lowerCAmelCase_							)
		BertTokenizer.from_pretrained(lowerCAmelCase_							)
		pipeline(task="""fill-mask"""     ,     model=lowerCAmelCase_							)

		# baseline - just load from_pretrained with normal network
		A_		:						Tuple	    =   [sys.executable, """-c""", """\n""".join([load, run, mock]							)]

		# should succeed
		A_		:						Optional[int]	    =   self.get_env()
		# should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
		A_		:						Union[str, Any]	    =   """1"""
		A_		:						Union[str, Any]	    =   subprocess.run(lowerCAmelCase_     ,     env=lowerCAmelCase_     ,     check=lowerCAmelCase_     ,     capture_output=lowerCAmelCase_							)
		self.assertEqual(result.returncode     ,     0     ,     result.stderr							)
		self.assertIn("""success"""     ,     result.stdout.decode()							)





	@require_torch
	def    lowerCamelCase(self							):
		# python one-liner segments
		# this must be loaded before socket.socket is monkey-patched
		A_		:						Union[str, Any]	    =   """
from transformers import BertConfig, BertModel, BertTokenizer, pipeline
        """

		A_		:						Optional[Any]	    =   """
mname = \"hf-internal-testing/tiny-random-bert\"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
BertTokenizer.from_pretrained(mname)
pipe = pipeline(task=\"fill-mask\", model=mname)
print(\"success\")
        """

		A_		:						List[str]	    =   """
import socket
def offline_socket(*args, **kwargs): raise socket.error(\"Faking flaky internet\")
socket.socket = offline_socket
        """

		# Force fetching the files so that we can use the cache
		A_		:						List[Any]	    =   """hf-internal-testing/tiny-random-bert"""
		BertConfig.from_pretrained(lowerCAmelCase_							)
		BertModel.from_pretrained(lowerCAmelCase_							)
		BertTokenizer.from_pretrained(lowerCAmelCase_							)
		pipeline(task="""fill-mask"""     ,     model=lowerCAmelCase_							)

		# baseline - just load from_pretrained with normal network
		A_		:						List[Any]	    =   [sys.executable, """-c""", """\n""".join([load, run, mock]							)]

		# should succeed
		A_		:						List[str]	    =   self.get_env()
		A_		:						Optional[int]	    =   subprocess.run(lowerCAmelCase_     ,     env=lowerCAmelCase_     ,     check=lowerCAmelCase_     ,     capture_output=lowerCAmelCase_							)
		self.assertEqual(result.returncode     ,     0     ,     result.stderr							)
		self.assertIn("""success"""     ,     result.stdout.decode()							)





	@require_torch
	def    lowerCamelCase(self							):
		# this test is a bit tricky since TRANSFORMERS_OFFLINE can only be changed before
		# `transformers` is loaded, and it's too late for inside pytest - so we are changing it
		# while running an external program

		# python one-liner segments

		# this must be loaded before socket.socket is monkey-patched
		A_		:						Union[str, Any]	    =   """
from transformers import BertConfig, BertModel, BertTokenizer
        """

		A_		:						Union[str, Any]	    =   """
mname = \"hf-internal-testing/tiny-random-bert-sharded\"
BertConfig.from_pretrained(mname)
BertModel.from_pretrained(mname)
print(\"success\")
        """

		A_		:						str	    =   """
import socket
def offline_socket(*args, **kwargs): raise ValueError(\"Offline mode is enabled\")
socket.socket = offline_socket
        """

		# baseline - just load from_pretrained with normal network
		A_		:						Union[str, Any]	    =   [sys.executable, """-c""", """\n""".join([load, run]							)]

		# should succeed
		A_		:						Optional[Any]	    =   self.get_env()
		A_		:						Optional[int]	    =   subprocess.run(lowerCAmelCase_     ,     env=lowerCAmelCase_     ,     check=lowerCAmelCase_     ,     capture_output=lowerCAmelCase_							)
		self.assertEqual(result.returncode     ,     0     ,     result.stderr							)
		self.assertIn("""success"""     ,     result.stdout.decode()							)

		# next emulate no network
		A_		:						Tuple	    =   [sys.executable, """-c""", """\n""".join([load, mock, run]							)]

		# Doesn't fail anymore since the model is in the cache due to other tests, so commenting this.
		# env["TRANSFORMERS_OFFLINE"] = "0"
		# result = subprocess.run(cmd, env=env, check=False, capture_output=True)
		# self.assertEqual(result.returncode, 1, result.stderr)

		# should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
		A_		:						Optional[Any]	    =   """1"""
		A_		:						Optional[int]	    =   subprocess.run(lowerCAmelCase_     ,     env=lowerCAmelCase_     ,     check=lowerCAmelCase_     ,     capture_output=lowerCAmelCase_							)
		self.assertEqual(result.returncode     ,     0     ,     result.stderr							)
		self.assertIn("""success"""     ,     result.stdout.decode()							)





	@require_torch
	def    lowerCamelCase(self							):
		A_		:						Any	    =   """
from transformers import pipeline
        """
		A_		:						List[Any]	    =   """
mname = \"hf-internal-testing/tiny-random-bert\"
pipe = pipeline(model=mname)
        """

		A_		:						int	    =   """
import socket
def offline_socket(*args, **kwargs): raise socket.error(\"Offline mode is enabled\")
socket.socket = offline_socket
        """
		A_		:						str	    =   self.get_env()
		A_		:						int	    =   """1"""
		A_		:						int	    =   [sys.executable, """-c""", """\n""".join([load, mock, run]							)]
		A_		:						Dict	    =   subprocess.run(lowerCAmelCase_     ,     env=lowerCAmelCase_     ,     check=lowerCAmelCase_     ,     capture_output=lowerCAmelCase_							)
		self.assertEqual(result.returncode     ,     1     ,     result.stderr							)
		self.assertIn(
		    """You cannot infer task automatically within `pipeline` when using offline mode"""     ,     result.stderr.decode().replace("""\n"""     ,     """"""							)     ,     )





	@require_torch
	def    lowerCamelCase(self							):
		A_		:						Tuple	    =   """
from transformers import AutoModel
        """
		A_		:						Dict	    =   """
mname = \"hf-internal-testing/test_dynamic_model\"
AutoModel.from_pretrained(mname, trust_remote_code=True)
print(\"success\")
        """

		# baseline - just load from_pretrained with normal network
		A_		:						Dict	    =   [sys.executable, """-c""", """\n""".join([load, run]							)]

		# should succeed
		A_		:						Optional[int]	    =   self.get_env()
		A_		:						Optional[Any]	    =   subprocess.run(lowerCAmelCase_     ,     env=lowerCAmelCase_     ,     check=lowerCAmelCase_     ,     capture_output=lowerCAmelCase_							)
		self.assertEqual(result.returncode     ,     0     ,     result.stderr							)
		self.assertIn("""success"""     ,     result.stdout.decode()							)

		# should succeed as TRANSFORMERS_OFFLINE=1 tells it to use local files
		A_		:						List[Any]	    =   """1"""
		A_		:						str	    =   subprocess.run(lowerCAmelCase_     ,     env=lowerCAmelCase_     ,     check=lowerCAmelCase_     ,     capture_output=lowerCAmelCase_							)
		self.assertEqual(result.returncode     ,     0     ,     result.stderr							)
		self.assertIn("""success"""     ,     result.stdout.decode()							)









"""simple docstring"""
import sys
import webbrowser

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

if __name__ == "__main__":
							print("Googling.....")
							_lowerCAmelCase         =							"https://www.google.com/search?q=" + " ".join(sys.argv[1:])
							_lowerCAmelCase         =							requests.get(url, headers={"UserAgent": UserAgent().random})
							# res.raise_for_status()
							with open("project1a.html", "wb") as out_file:  # only for knowing the class
														for data in res.iter_content(10_000):
																					out_file.write(data)
							_lowerCAmelCase         =							BeautifulSoup(res.text, "html.parser")
							_lowerCAmelCase         =							list(soup.select(".eZt8xd"))[:5]

							print(len(links))
							for link in links:
														if link.text == "Maps":
																					webbrowser.open(link.get("href"))
														else:
																					webbrowser.open(F'https://google.com{link.get("href")}')

