Karim shoair commited on
Commit
df159e9
·
1 Parent(s): 23b9523

refactor: optimize imports and docstrings correction

Browse files
scrapling/core/custom_types.py CHANGED
@@ -131,8 +131,8 @@ class TextHandler(str):
131
  extract_first = get
132
 
133
  def json(self) -> Dict:
134
- """Return json response if the response is jsonable otherwise throw error"""
135
- # Using str function as a workaround for orjson issue with subclasses of str
136
  # Check this out: https://github.com/ijl/orjson/issues/445
137
  return loads(str(self))
138
 
@@ -167,10 +167,10 @@ class TextHandler(str):
167
  """Apply the given regex to the current text and return a list of strings with the matches.
168
 
169
  :param regex: Can be either a compiled regular expression or a string.
170
- :param replace_entities: if enabled character entity references are replaced by their corresponding character
171
- :param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
172
- :param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
173
- :param check_match: used to quickly check if this regex matches or not without any operations on the results
174
 
175
  """
176
  if isinstance(regex, str):
@@ -213,9 +213,9 @@ class TextHandler(str):
213
 
214
  :param regex: Can be either a compiled regular expression or a string.
215
  :param default: The default value to be returned if there is no match
216
- :param replace_entities: if enabled character entity references are replaced by their corresponding character
217
- :param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
218
- :param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
219
 
220
  """
221
  result = self.re(
@@ -262,9 +262,9 @@ class TextHandlers(List[TextHandler]):
262
  their results flattened as TextHandlers.
263
 
264
  :param regex: Can be either a compiled regular expression or a string.
265
- :param replace_entities: if enabled character entity references are replaced by their corresponding character
266
  :param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
267
- :param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
268
  """
269
  results = [
270
  n.re(regex, replace_entities, clean_match, case_sensitive) for n in self
@@ -284,9 +284,9 @@ class TextHandlers(List[TextHandler]):
284
 
285
  :param regex: Can be either a compiled regular expression or a string.
286
  :param default: The default value to be returned if there is no match
287
- :param replace_entities: if enabled character entity references are replaced by their corresponding character
288
- :param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
289
- :param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
290
  """
291
  for n in self:
292
  for result in n.re(regex, replace_entities, clean_match, case_sensitive):
@@ -308,8 +308,8 @@ class TextHandlers(List[TextHandler]):
308
 
309
 
310
  class AttributesHandler(Mapping[str, _TextHandlerType]):
311
- """A read-only mapping to use instead of the standard dictionary for the speed boost but at the same time I use it to add more functionalities.
312
- If standard dictionary is needed, just convert this class to dictionary with `dict` function
313
  """
314
 
315
  __slots__ = ("_data",)
@@ -338,12 +338,12 @@ class AttributesHandler(Mapping[str, _TextHandlerType]):
338
  def get(
339
  self, key: str, default: Optional[str] = None
340
  ) -> Union[_TextHandlerType, None]:
341
- """Acts like standard dictionary `.get()` method"""
342
  return self._data.get(key, default)
343
 
344
  def search_values(self, keyword, partial=False):
345
- """Search current attributes by values and return dictionary of each matching item
346
- :param keyword: The keyword to search for in the attributes values
347
  :param partial: If True, the function will search if keyword in each value instead of perfect match
348
  """
349
  for key, value in self._data.items():
 
131
  extract_first = get
132
 
133
  def json(self) -> Dict:
134
+ """Return JSON response if the response is jsonable otherwise throw error"""
135
+ # Using str function as a workaround for orjson issue with subclasses of str.
136
  # Check this out: https://github.com/ijl/orjson/issues/445
137
  return loads(str(self))
138
 
 
167
  """Apply the given regex to the current text and return a list of strings with the matches.
168
 
169
  :param regex: Can be either a compiled regular expression or a string.
170
+ :param replace_entities: If enabled character entity references are replaced by their corresponding character
171
+ :param clean_match: If enabled, this will ignore all whitespaces and consecutive spaces while matching
172
+ :param case_sensitive: If disabled, function will set the regex to ignore the letters-case while compiling it
173
+ :param check_match: Used to quickly check if this regex matches or not without any operations on the results
174
 
175
  """
176
  if isinstance(regex, str):
 
213
 
214
  :param regex: Can be either a compiled regular expression or a string.
215
  :param default: The default value to be returned if there is no match
216
+ :param replace_entities: If enabled character entity references are replaced by their corresponding character
217
+ :param clean_match: If enabled, this will ignore all whitespaces and consecutive spaces while matching
218
+ :param case_sensitive: If disabled, function will set the regex to ignore the letters-case while compiling it
219
 
220
  """
221
  result = self.re(
 
262
  their results flattened as TextHandlers.
263
 
264
  :param regex: Can be either a compiled regular expression or a string.
265
+ :param replace_entities: If enabled character entity references are replaced by their corresponding character
266
  :param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
267
+ :param case_sensitive: if disabled, the function will set the regex to ignore the letters-case while compiling it
268
  """
269
  results = [
270
  n.re(regex, replace_entities, clean_match, case_sensitive) for n in self
 
284
 
285
  :param regex: Can be either a compiled regular expression or a string.
286
  :param default: The default value to be returned if there is no match
287
+ :param replace_entities: If enabled character entity references are replaced by their corresponding character
288
+ :param clean_match: If enabled, this will ignore all whitespaces and consecutive spaces while matching
289
+ :param case_sensitive: If disabled, function will set the regex to ignore the letters-case while compiling it
290
  """
291
  for n in self:
292
  for result in n.re(regex, replace_entities, clean_match, case_sensitive):
 
308
 
309
 
310
  class AttributesHandler(Mapping[str, _TextHandlerType]):
311
+ """A read-only mapping to use instead of the standard dictionary for the speed boost, but at the same time I use it to add more functionalities.
312
+ If the standard dictionary is needed, convert this class to a dictionary with the `dict` function
313
  """
314
 
315
  __slots__ = ("_data",)
 
338
  def get(
339
  self, key: str, default: Optional[str] = None
340
  ) -> Union[_TextHandlerType, None]:
341
+ """Acts like the standard dictionary `.get()` method"""
342
  return self._data.get(key, default)
343
 
344
  def search_values(self, keyword, partial=False):
345
+ """Search current attributes by values and return a dictionary of each matching item
346
+ :param keyword: The keyword to search for in the attribute values
347
  :param partial: If True, the function will search if keyword in each value instead of perfect match
348
  """
349
  for key, value in self._data.items():
scrapling/engines/_browsers/_validators.py CHANGED
@@ -9,7 +9,6 @@ from scrapling.core._types import (
9
  Callable,
10
  Literal,
11
  List,
12
- Iterable,
13
  SelectorWaitStates,
14
  )
15
  from scrapling.engines.toolbelt import construct_proxy_dict
 
9
  Callable,
10
  Literal,
11
  List,
 
12
  SelectorWaitStates,
13
  )
14
  from scrapling.engines.toolbelt import construct_proxy_dict