





from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
    import tensorflow as tf

    from transformers.models.distilbert.modeling_tf_distilbert import (
        TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFDistilBertForMaskedLM,
        TFDistilBertForMultipleChoice,
        TFDistilBertForQuestionAnswering,
        TFDistilBertForSequenceClassification,
        TFDistilBertForTokenClassification,
        TFDistilBertModel,
    )

class 		SCREAMING_SNAKE_CASE__    :


      def __init__(self	:				str    ,      a__	:				Union[str, Any]    ,      ):





         """simple docstring"""



         __snake_case								=       parent
         __snake_case								=       13
         __snake_case								=       7
         __snake_case								=       True
         __snake_case								=       True
         __snake_case								=       False
         __snake_case								=       True
         __snake_case								=       99
         __snake_case								=       32
         __snake_case								=       2
         __snake_case								=       4
         __snake_case								=       37
         __snake_case								=       '''gelu'''
         __snake_case								=       0.1
         __snake_case								=       0.1
         __snake_case								=       512
         __snake_case								=       16
         __snake_case								=       2
         __snake_case								=       0.0_2
         __snake_case								=       3
         __snake_case								=       4
         __snake_case								=       None


      def        a			(self	:				str				):





         """simple docstring"""



         __snake_case								=       ids_tensor([self.batch_size, self.seq_length]    ,      self.vocab_size				)

         __snake_case								=       None
         if self.use_input_mask:
            __snake_case								=       random_attention_mask([self.batch_size, self.seq_length]				)

         __snake_case								=       None
         __snake_case								=       None
         __snake_case								=       None
         if self.use_labels:
            __snake_case								=       ids_tensor([self.batch_size]    ,      self.type_sequence_label_size				)
            __snake_case								=       ids_tensor([self.batch_size, self.seq_length]    ,      self.num_labels				)
            __snake_case								=       ids_tensor([self.batch_size]    ,      self.num_choices				)

         __snake_case								=       DistilBertConfig(
             vocab_size=self.vocab_size    ,      dim=self.hidden_size    ,      n_layers=self.num_hidden_layers    ,      n_heads=self.num_attention_heads    ,      hidden_dim=self.intermediate_size    ,      hidden_act=self.hidden_act    ,      dropout=self.hidden_dropout_prob    ,      attention_dropout=self.attention_probs_dropout_prob    ,      max_position_embeddings=self.max_position_embeddings    ,      initializer_range=self.initializer_range    ,      )

         return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels


      def        a			(self	:				List[str]    ,      a__	:				str    ,      a__	:				List[str]    ,      a__	:				str    ,      a__	:				Optional[Any]    ,      a__	:				Optional[int]    ,      a__	:				int				):





         """simple docstring"""



         __snake_case								=       TFDistilBertModel(config=__a				)
         __snake_case								=       {'''input_ids''': input_ids, '''attention_mask''': input_mask}

         __snake_case								=       model(__a				)

         __snake_case								=       [input_ids, input_mask]

         __snake_case								=       model(__a				)

         self.parent.assertEqual(result.last_hidden_state.shape    ,      (self.batch_size, self.seq_length, self.hidden_size)				)


      def        a			(self	:				Union[str, Any]    ,      a__	:				Any    ,      a__	:				Optional[int]    ,      a__	:				str    ,      a__	:				Optional[int]    ,      a__	:				Union[str, Any]    ,      a__	:				Optional[int]				):





         """simple docstring"""



         __snake_case								=       TFDistilBertForMaskedLM(config=__a				)
         __snake_case								=       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
         __snake_case								=       model(__a				)
         self.parent.assertEqual(result.logits.shape    ,      (self.batch_size, self.seq_length, self.vocab_size)				)


      def        a			(self	:				List[str]    ,      a__	:				int    ,      a__	:				str    ,      a__	:				List[str]    ,      a__	:				Optional[Any]    ,      a__	:				Dict    ,      a__	:				List[Any]				):





         """simple docstring"""



         __snake_case								=       TFDistilBertForQuestionAnswering(config=__a				)
         __snake_case								=       {
             '''input_ids''': input_ids,
             '''attention_mask''': input_mask,
         }
         __snake_case								=       model(__a				)
         self.parent.assertEqual(result.start_logits.shape    ,      (self.batch_size, self.seq_length)				)
         self.parent.assertEqual(result.end_logits.shape    ,      (self.batch_size, self.seq_length)				)


      def        a			(self	:				List[Any]    ,      a__	:				Dict    ,      a__	:				List[Any]    ,      a__	:				Optional[Any]    ,      a__	:				Optional[int]    ,      a__	:				int    ,      a__	:				Any				):





         """simple docstring"""



         __snake_case								=       self.num_labels
         __snake_case								=       TFDistilBertForSequenceClassification(__a				)
         __snake_case								=       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
         __snake_case								=       model(__a				)
         self.parent.assertEqual(result.logits.shape    ,      (self.batch_size, self.num_labels)				)


      def        a			(self	:				List[str]    ,      a__	:				Union[str, Any]    ,      a__	:				List[Any]    ,      a__	:				int    ,      a__	:				str    ,      a__	:				Optional[Any]    ,      a__	:				List[Any]				):





         """simple docstring"""



         __snake_case								=       self.num_choices
         __snake_case								=       TFDistilBertForMultipleChoice(__a				)
         __snake_case								=       tf.tile(tf.expand_dims(__a    ,      1				)    ,      (1, self.num_choices, 1)				)
         __snake_case								=       tf.tile(tf.expand_dims(__a    ,      1				)    ,      (1, self.num_choices, 1)				)
         __snake_case								=       {
             '''input_ids''': multiple_choice_inputs_ids,
             '''attention_mask''': multiple_choice_input_mask,
         }
         __snake_case								=       model(__a				)
         self.parent.assertEqual(result.logits.shape    ,      (self.batch_size, self.num_choices)				)


      def        a			(self	:				List[Any]    ,      a__	:				Optional[int]    ,      a__	:				str    ,      a__	:				Union[str, Any]    ,      a__	:				Optional[int]    ,      a__	:				Dict    ,      a__	:				Tuple				):





         """simple docstring"""



         __snake_case								=       self.num_labels
         __snake_case								=       TFDistilBertForTokenClassification(__a				)
         __snake_case								=       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
         __snake_case								=       model(__a				)
         self.parent.assertEqual(result.logits.shape    ,      (self.batch_size, self.seq_length, self.num_labels)				)


      def        a			(self	:				Optional[int]				):





         """simple docstring"""



         __snake_case								=       self.prepare_config_and_inputs()
         ((__snake_case)	,     (__snake_case)	,     (__snake_case)	,     (__snake_case)	,     (__snake_case)	,     (__snake_case))								=       config_and_inputs
         __snake_case								=       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
         return config, inputs_dict






@require_tf
class 		SCREAMING_SNAKE_CASE__    (	UpperCamelCase__						,				UpperCamelCase__						,				unittest.TestCase  ):
      A_						:    Any							=   (
          (
              TFDistilBertModel,
              TFDistilBertForMaskedLM,
              TFDistilBertForQuestionAnswering,
              TFDistilBertForSequenceClassification,
              TFDistilBertForTokenClassification,
              TFDistilBertForMultipleChoice,
          )
          if is_tf_available()
          else None
      )
      A_						:    int							=   (
          {
              """feature-extraction""": TFDistilBertModel,
              """fill-mask""": TFDistilBertForMaskedLM,
              """question-answering""": TFDistilBertForQuestionAnswering,
              """text-classification""": TFDistilBertForSequenceClassification,
              """token-classification""": TFDistilBertForTokenClassification,
              """zero-shot""": TFDistilBertForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      A_						:    int							=   False
      A_						:    Dict							=   False


      def        a			(self	:				Optional[int]				):





         """simple docstring"""



         __snake_case								=       TFDistilBertModelTester(self				)
         __snake_case								=       ConfigTester(self    ,      config_class=__a    ,      dim=37				)


      def        a			(self	:				Union[str, Any]				):





         """simple docstring"""



         self.config_tester.run_common_tests()


      def        a			(self	:				Dict				):





         """simple docstring"""



         __snake_case								=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_model(*__a				)


      def        a			(self	:				List[Any]				):





         """simple docstring"""



         __snake_case								=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_masked_lm(*__a				)


      def        a			(self	:				Union[str, Any]				):





         """simple docstring"""



         __snake_case								=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_question_answering(*__a				)


      def        a			(self	:				Tuple				):





         """simple docstring"""



         __snake_case								=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_sequence_classification(*__a				)


      def        a			(self	:				Optional[int]				):





         """simple docstring"""



         __snake_case								=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_multiple_choice(*__a				)


      def        a			(self	:				List[Any]				):





         """simple docstring"""



         __snake_case								=       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_token_classification(*__a				)


      @slow
      def        a			(self	:				Any				):





         """simple docstring"""



         for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]				):
            __snake_case								=       TFDistilBertModel.from_pretrained(__a				)
            self.assertIsNotNone(__a				)






@require_tf
class 		SCREAMING_SNAKE_CASE__    (	unittest.TestCase  ):


      @slow
      def        a			(self	:				Union[str, Any]				):





         """simple docstring"""



         __snake_case								=       TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''				)
         __snake_case								=       tf.constant([[0, 1, 2, 3, 4, 5]]				)
         __snake_case								=       model(__a				)[0]

         __snake_case								=       [1, 6, 768]
         self.assertEqual(output.shape    ,      __a				)

         __snake_case								=       tf.constant(
             [
                 [
                     [0.1_9_2_6_1_8_8_5, -0.1_3_7_3_2_9_5_5, 0.4_1_1_9_7_9_9],
                     [0.2_2_1_5_0_1_5_6, -0.0_7_4_2_2_6_6_1, 0.3_9_0_3_7_2_0_4],
                     [0.2_2_7_5_6_0_1_8, -0.0_8_9_6_4_1_4, 0.3_7_0_1_4_6_7],
                 ]
             ]				)
         tf.debugging.assert_near(output[:, :3, :3]    ,      __a    ,      atol=1E-4				)








from __future__ import annotations

snake_case_           =      'Muhammad Umer Farooq'
snake_case_           =      'MIT'
snake_case_           =      '1.0.0'
snake_case_           =      'Muhammad Umer Farooq'
snake_case_           =      'contact@muhammadumerfarooq.me'
snake_case_           =      'Alpha'

import re
from html.parser import HTMLParser
from urllib import parse

import requests

class 		SCREAMING_SNAKE_CASE__    (	_UpperCAmelCase  ):


      def __init__(self	:				Dict    ,      a__	:				str				):





         """simple docstring"""



         super().__init__()
         __snake_case								=       []
         __snake_case								=       domain


      def        a			(self	:				Tuple    ,      a__	:				str    ,      a__	:				list[tuple[str, str | None]]				):





         """simple docstring"""



         if tag == "a":
            # Check the list of defined attributes.
            for name, value in attrs:
               # If href is defined, and not empty nor # print it.
               if name == "href" and value != "#" and value != "":
                  # If not already in urls.
                  if value not in self.urls:
                     __snake_case								=       parse.urljoin(self.domain    ,      a__				)
                     self.urls.append(a__				)






def lowerCamelCase__   (							snake_case_     :  str	)				->    str:
   return ".".join(get_sub_domain_name(snake_case_	).split('''.'''	)[-2:]	)






def lowerCamelCase__   (							snake_case_     :  str	)				->    str:
   return parse.urlparse(snake_case_	).netloc






def lowerCamelCase__   (							snake_case_     :  str = "https://github.com"	)				->    list[str]:
   __snake_case								=       get_domain_name(snake_case_	)

   # Initialize the parser
   __snake_case								=       Parser(snake_case_	)

   try:
      # Open URL
      __snake_case								=       requests.get(snake_case_	)

      # pass the raw HTML to the parser to get links
      parser.feed(r.text	)

      # Get links and loop through
      __snake_case								=       set()
      for link in parser.urls:
         # open URL.
         # read = requests.get(link)
         try:
            __snake_case								=       requests.get(snake_case_	)
            # Get the valid email.
            __snake_case								=       re.findall('''[a-zA-Z0-9]+@''' + domain	,				read.text	)
            # If not in list then append it.
            for email in emails:
               valid_emails.add(snake_case_	)
         except ValueError:
            pass
   except ValueError:
      raise SystemExit(1	)

   # Finally return a sorted list of email addresses with no duplicates.
   return sorted(snake_case_	)


if __name__ == "__main__":
    snake_case_           =      emails_from_url('https://github.com')
    print(F'{len(emails)} emails found:')
    print('\n'.join(sorted(emails)))

