_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q270300
Production._does_require_deprecation
test
def _does_require_deprecation(self): """ Check if we have to put the previous version into the deprecated list. """ for index, version_number in enumerate(self.current_version[0][:2]): # We loop through the 2 last elements of the version. if version_number > sel...
python
{ "resource": "" }
q270301
AutoContinue.backup
test
def backup(self): """ Backup the current execution state. """ if PyFunceble.CONFIGURATION["auto_continue"]: # The auto_continue subsystem is activated. # We initiate the location where we are going to save the data to backup. data_to_backup = {} ...
python
{ "resource": "" }
q270302
AutoContinue.restore
test
def restore(self): """ Restore data from the given path. """ if PyFunceble.CONFIGURATION["auto_continue"] and self.backup_content: # The auto_continue subsystem is activated and the backup_content # is not empty. # We get the file we have to restore....
python
{ "resource": "" }
q270303
AdBlock._is_to_ignore
test
def _is_to_ignore(cls, line): """ Check if we have to ignore the given line. :param line: The line from the file. :type line: str """ # We set the list of regex to match to be # considered as ignored. to_ignore = [r"(^!|^@@|^\/|^\[|^\.|^-|^_|^\?|^&)"] #...
python
{ "resource": "" }
q270304
AdBlock._handle_options
test
def _handle_options(self, options): """ Handle the data from the options. :param options: The list of options from the rule. :type options: list :return: The list of domains to return globally. :rtype: list """ # We initiate a variable which will save o...
python
{ "resource": "" }
q270305
AdBlock._extract_base
test
def _extract_base(self, element): """ Extract the base of the given element. .. example: given "hello/world?world=beautiful" return "hello" :param element: The element we are working with. :type element: str|list """ if isinstance(element, list): ...
python
{ "resource": "" }
q270306
AdBlock._format_decoded
test
def _format_decoded(self, to_format, result=None): # pragma: no cover """ Format the exctracted adblock line before passing it to the system. :param to_format: The extracted line from the file. :type to_format: str :param result: A list of the result of this method. :t...
python
{ "resource": "" }
q270307
HTTPCode._access
test
def _access(self): # pragma: no cover """ Get the HTTP code status. :return: The matched HTTP status code. :rtype: int|None """ try: # We try to get the HTTP status code. if PyFunceble.INTERN["to_test_type"] == "url": # We are g...
python
{ "resource": "" }
q270308
HTTPCode.get
test
def get(self): """ Return the HTTP code status. :return: The matched and formatted status code. :rtype: str|int|None """ if PyFunceble.HTTP_CODE["active"]: # The http status code extraction is activated. # We get the http status code. ...
python
{ "resource": "" }
q270309
syntax_check
test
def syntax_check(domain): # pragma: no cover """ Check the syntax of the given domain. :param domain: The domain to check the syntax for. :type domain: str :return: The syntax validity. :rtype: bool .. warning:: If an empty or a non-string :code:`domain` is given, we return :code...
python
{ "resource": "" }
q270310
is_subdomain
test
def is_subdomain(domain): # pragma: no cover """ Check if the given domain is a subdomain. :param domain: The domain we are checking. :type domain: str :return: The subdomain state. :rtype: bool .. warning:: If an empty or a non-string :code:`domain` is given, we return :code:`No...
python
{ "resource": "" }
q270311
ipv4_syntax_check
test
def ipv4_syntax_check(ip): # pragma: no cover """ Check the syntax of the given IPv4. :param ip: The IPv4 to check the syntax for. :type ip: str :return: The syntax validity. :rtype: bool .. warning:: If an empty or a non-string :code:`ip` is given, we return :code:`None`. ""...
python
{ "resource": "" }
q270312
is_ipv4_range
test
def is_ipv4_range(ip): # pragma: no cover """ Check if the given IP is an IP range. :param ip: The IP we are checking. :type ip: str :return: The IPv4 range state. :rtype: bool .. warning:: If an empty or a non-string :code:`ip` is given, we return :code:`None`. """ if i...
python
{ "resource": "" }
q270313
url_syntax_check
test
def url_syntax_check(url): # pragma: no cover """ Check the syntax of the given URL. :param url: The URL to check the syntax for. :type url: str :return: The syntax validity. :rtype: bool .. warning:: If an empty or a non-string :code:`url` is given, we return :code:`None`. "...
python
{ "resource": "" }
q270314
load_config
test
def load_config(under_test=False, custom=None): # pragma: no cover """ Load the configuration. :param under_test: Tell us if we only have to load the configuration file (True) or load the configuration file and initate the output directory if it does not exist (False). :type un...
python
{ "resource": "" }
q270315
stay_safe
test
def stay_safe(): # pragma: no cover """ Print a friendly message. """ random = int(choice(str(int(time())))) if not CONFIGURATION["quiet"] and random % 3 == 0: print("\n" + Fore.GREEN + Style.BRIGHT + "Thanks for using PyFunceble!") print( Fore.YELLOW + Sty...
python
{ "resource": "" }
q270316
Core._entry_management_url_download
test
def _entry_management_url_download(self, passed): """ Check if the given information is a URL. If it is the case, it download and update the location of file to test. :param passed: The url passed to the system. :type passed: str :return: The state of the check. ...
python
{ "resource": "" }
q270317
Core._entry_management_url
test
def _entry_management_url(self): """ Manage the loading of the url system. """ if ( self.url_file # pylint: disable=no-member and not self._entry_management_url_download( self.url_file # pylint: disable=no-member ) ): # pyli...
python
{ "resource": "" }
q270318
Core._print_header
test
def _print_header(cls): """ Decide if we print or not the header. """ if ( not PyFunceble.CONFIGURATION["quiet"] and not PyFunceble.CONFIGURATION["header_printed"] ): # * The quiet mode is not activated. # and # * The h...
python
{ "resource": "" }
q270319
Core._file_decision
test
def _file_decision(self, current, last, status=None): """ Manage the database, autosave and autocontinue systems for the case that we are reading a file. :param current: The currently tested element. :type current: str :param last: The last element of the list. ...
python
{ "resource": "" }
q270320
Core.domain
test
def domain(self, domain=None, last_domain=None): """ Manage the case that we want to test only a domain. :param domain: The domain or IP to test. :type domain: str :param last_domain: The last domain to test if we are testing a file. :type last_domain: str ...
python
{ "resource": "" }
q270321
Core.url
test
def url(self, url_to_test=None, last_url=None): """ Manage the case that we want to test only a given url. :param url_to_test: The url to test. :type url_to_test: str :param last_url: The last url of the file we are testing (if exist) :type last_...
python
{ "resource": "" }
q270322
Core.colorify_logo
test
def colorify_logo(cls, home=False): """ Print the colored logo based on global results. :param home: Tell us if we have to print the initial coloration. :type home: bool """ if not PyFunceble.CONFIGURATION["quiet"]: # The quiet mode is not activated. ...
python
{ "resource": "" }
q270323
Core._format_domain
test
def _format_domain(cls, extracted_domain): """ Format the extracted domain before passing it to the system. :param extracted_domain: The extracted domain. :type extracted_domain: str :return: The formatted domain or IP to test. :rtype: str .. note: ...
python
{ "resource": "" }
q270324
Core._extract_domain_from_file
test
def _extract_domain_from_file(cls): """ Extract all non commented lines from the file we are testing. :return: The elements to test. :rtype: list """ # We initiate the variable which will save what we are going to return. result = [] if PyFunceble.path....
python
{ "resource": "" }
q270325
Core.file
test
def file(self): """ Manage the case that need to test each domain of a given file path. .. note:: 1 domain per line. """ # We get, format, filter, clean the list to test. list_to_test = self._file_list_to_test_filtering() if PyFunceble.CONFIGURATION...
python
{ "resource": "" }
q270326
Core.file_url
test
def file_url(self): """ Manage the case that we have to test a file .. note:: 1 URL per line. """ # We get, format, clean the list of URL to test. list_to_test = self._file_list_to_test_filtering() # We initiate a local variable which will save the ...
python
{ "resource": "" }
q270327
Core.switch
test
def switch( cls, variable, custom=False ): # pylint: disable=inconsistent-return-statements """ Switch PyFunceble.CONFIGURATION variables to their opposite. :param variable: The variable name to switch. The variable should be an index our configuration syste...
python
{ "resource": "" }
q270328
Status.get
test
def get(cls): """ Get the status while testing for an IP or domain. .. note:: We consider that the domain or IP we are currently testing is into :code:`PyFunceble.INTERN["to_test"]`. """ if "to_test" in PyFunceble.INTERN and PyFunceble.INTERN["to_test"]:...
python
{ "resource": "" }
q270329
URLStatus.handle
test
def handle(self): """ Handle the backend of the given status. """ # We initiate the source we are going to parse to the Generate class. source = "URL" if self.catched.lower() not in PyFunceble.STATUS["list"]["invalid"]: # The parsed status is not in the list...
python
{ "resource": "" }
q270330
DirectoryStructure._get_structure
test
def _get_structure(self): """ Get the structure we are going to work with. :return: The structure we have to work with. :rtype: dict """ # We initiate an empty variable which is going to save the location of # file we are going to download. structure_fil...
python
{ "resource": "" }
q270331
DirectoryStructure._create_directory
test
def _create_directory(cls, directory, loop=False): """ Creates the given directory if it does not exists. :param directory: The directory to create. :type directory: str :param loop: Tell us if we are in the creation loop or not. :type loop: bool """ if...
python
{ "resource": "" }
q270332
DirectoryStructure.delete_uneeded
test
def delete_uneeded(self): """ Delete the directory which are not registered into our structure. """ # We get the structure we have to apply. structure = self._get_structure() # We get the list of key which is implicitly the list of directory we do not bave to delete. ...
python
{ "resource": "" }
q270333
Load._set_path_to_configs
test
def _set_path_to_configs(cls, path_to_config): """ Set the paths to the configuration files. :param path_to_config: The possible path to the config to load. :type path_to_config: str :return: The path to the config to read (0), the path to the default co...
python
{ "resource": "" }
q270334
Load._load_config_file
test
def _load_config_file(self): """ Load .PyFunceble.yaml into the system. """ try: # We try to load the configuration file. PyFunceble.CONFIGURATION.update( Dict.from_yaml(File(self.path_to_config).read()) ) # We install th...
python
{ "resource": "" }
q270335
Load._install_production_config
test
def _install_production_config(self): """ Download the production configuration and install it in the current directory. """ # We initiate the link to the production configuration. # It is not hard coded because this method is called only if we # are sure that th...
python
{ "resource": "" }
q270336
Load._install_iana_config
test
def _install_iana_config(cls): """ Download `iana-domains-db.json` if not present. """ # We initiate the link to the iana configuration. # It is not hard coded because this method is called only if we # are sure that the configuration file exist. iana_link = PyFu...
python
{ "resource": "" }
q270337
Load._install_psl_config
test
def _install_psl_config(cls): """ Download `public-suffix.json` if not present. """ # We initiate the link to the public suffix configuration. # It is not hard coded because this method is called only if we # are sure that the configuration file exist. psl_link =...
python
{ "resource": "" }
q270338
Load._install_directory_structure_file
test
def _install_directory_structure_file(cls): """ Download the latest version of `dir_structure_production.json`. """ # We initiate the link to the public suffix configuration. # It is not hard coded because this method is called only if we # are sure that the configuratio...
python
{ "resource": "" }
q270339
Merge._merge_values
test
def _merge_values(self): """ Simply merge the older into the new one. """ to_remove = [] self.new_config = Dict( Dict(self.upstream_config).merge(PyFunceble.CONFIGURATION) ).remove_key(to_remove)
python
{ "resource": "" }
q270340
Merge._load
test
def _load(self): """ Execute the logic behind the merging. """ if "PYFUNCEBLE_AUTO_CONFIGURATION" not in PyFunceble.environ: # The auto configuration environment variable is not set. while True: # We infinitly loop until we get a reponse which is...
python
{ "resource": "" }
q270341
Version.split_versions
test
def split_versions(cls, version, return_non_digits=False): """ Convert the versions to a shorter one. :param version: The version to split. :type version: str :param return_non_digits: Activate the return of the non-digits parts of the splitted version. ...
python
{ "resource": "" }
q270342
Version.check_versions
test
def check_versions(cls, local, upstream): """ Compare the given versions. :param local: The local version converted by split_versions(). :type local: list :param upstream: The upstream version converted by split_versions(). :type upstream: list :return: ...
python
{ "resource": "" }
q270343
Version.is_cloned
test
def is_cloned(cls): """ Let us know if we are currently in the cloned version of PyFunceble which implicitly mean that we are in developement mode. """ if not PyFunceble.path.isdir(".git"): # The git directory does not exist. # We return False, the curre...
python
{ "resource": "" }
q270344
Generate._handle_non_existant_index
test
def _handle_non_existant_index(cls): """ Handle and check that some configuration index exists. """ try: # We try to call the http code. PyFunceble.INTERN["http_code"] except KeyError: # If it is not found. # We initiate an empty ...
python
{ "resource": "" }
q270345
Generate._analytic_host_file_directory
test
def _analytic_host_file_directory(self): """ Return the analytic directory to write depending of the matched status. """ # We construct the path to the analytic directory. output_dir = ( self.output_parent_dir + PyFunceble.OUTPUTS["analytic"]["dir...
python
{ "resource": "" }
q270346
Generate.unified_file
test
def unified_file(self): """ Generate unified file. Understand by that that we use an unified table instead of a separate table for each status which could result into a misunderstanding. """ if ( "file_to_test" in PyFunceble.INTERN and PyFunceble....
python
{ "resource": "" }
q270347
Generate.status_file
test
def status_file(self): # pylint: disable=inconsistent-return-statements """ Generate a file according to the domain status. """ if "file_to_test" in PyFunceble.INTERN: # We are not testing as an imported module. # We generate the hosts file. Generat...
python
{ "resource": "" }
q270348
Generate._do_not_produce_file
test
def _do_not_produce_file(self): """ Check if we are allowed to produce a file based from the given information. :return: The state of the production. True: We do not produce file. False: We do produce file. :rtype: bool """ if...
python
{ "resource": "" }
q270349
PublicSuffix._extensions
test
def _extensions(self, line): """ Extract the extension from the given line. :param line: The line from the official public suffix repository. :type line: str """ # We strip the parsed line. line = line.strip() if not line.startswith("//") and "." in lin...
python
{ "resource": "" }
q270350
PublicSuffix.load
test
def load(self): """ Load the public suffix database into the system. """ if not PyFunceble.INTERN["psl_db"]: # The public database was not already loaded. # * We read, convert to dict and return the file content. # and # * We fill/create ...
python
{ "resource": "" }
q270351
Sort.standard
test
def standard(cls, element): """ Implement the standard and alphabetical sorting. :param element: The element we are currently reading. :type element: str :return: The formatted element. :rtype: str """ # We remove all special characters and return the f...
python
{ "resource": "" }
q270352
Sort.hierarchical
test
def hierarchical(cls, element): """ The idea behind this method is to sort a list of domain hierarchicaly. :param element: The element we are currently reading. :type element: str :return: The formatted element. :rtype: str .. note:: For a domain li...
python
{ "resource": "" }
q270353
IANA.load
test
def load(self): """ Initiate the IANA database if it is not the case. """ if "iana_db" not in PyFunceble.INTERN or not PyFunceble.INTERN["iana_db"]: # The global database is empty, None or does not exist. # We update it with the database content. PyF...
python
{ "resource": "" }
q270354
IANA._referer
test
def _referer(self, extension): """ Return the referer for the given extension. :param extension: A valid domain extension. :type extension: str :return: The whois server to use to get the WHOIS record. :rtype: str """ # We get the a copy of the page. ...
python
{ "resource": "" }
q270355
IANA._extensions
test
def _extensions(self): """ Extract the extention from the given block. Plus get its referer. """ upstream_lines = ( Download(self.iana_url, return_data=True) .text() .split('<span class="domain tld">') ) # We extract the diffe...
python
{ "resource": "" }
q270356
IANA.update
test
def update(self): """ Update the content of the `iana-domains-db` file. """ if not PyFunceble.CONFIGURATION["quiet"]: # * The quiet mode is not activated. # We print on screen what we are doing. print("Update of iana-domains-db", end=" ") # ...
python
{ "resource": "" }
q270357
Mining.mine
test
def mine(self): # pragma: no cover """ Search for domain or URL related to the original URL or domain. :return: The mined domains or URL. :rtype: dict """ if PyFunceble.CONFIGURATION["mining"]: # The mining is activated. try: # ...
python
{ "resource": "" }
q270358
Mining._retrieve
test
def _retrieve(self): """ Retrieve the mining informations. """ if PyFunceble.CONFIGURATION["mining"]: # The mining is activated. if "mined" not in PyFunceble.INTERN: PyFunceble.INTERN["mined"] = {} if PyFunceble.path.isfile(self.file...
python
{ "resource": "" }
q270359
Mining._backup
test
def _backup(self): """ Backup the mined informations. """ if PyFunceble.CONFIGURATION["mining"]: # The mining is activated. # We backup our mined informations. Dict(PyFunceble.INTERN["mined"]).to_json(self.file)
python
{ "resource": "" }
q270360
Mining._add
test
def _add(self, to_add): """ Add the currently mined information to the mined "database". :param to_add: The element to add. :type to_add: dict """ if PyFunceble.CONFIGURATION["mining"]: # The mining is activated. if PyFunceble.INTERN["fi...
python
{ "resource": "" }
q270361
Mining.remove
test
def remove(self): """ Remove the currently tested element from the mining data. """ if PyFunceble.CONFIGURATION["mining"]: # The mining is activated. if PyFunceble.INTERN["file_to_test"] in PyFunceble.INTERN["mined"]: # The currently test...
python
{ "resource": "" }
q270362
Mining.list_of_mined
test
def list_of_mined(cls): """ Provide the list of mined so they can be added to the list queue. :return: The list of mined domains or URL. :rtype: list """ # We initiate a variable which will return the result. result = [] if PyFunceble.CONFIGURAT...
python
{ "resource": "" }
q270363
Mining.process
test
def process(self): # pragma: no cover """ Process the logic and structuration of the mining database. """ if PyFunceble.CONFIGURATION["mining"]: # The mining is activated. # We load the mining logic. mined = self.mine() if mined: ...
python
{ "resource": "" }
q270364
Logs._get_content
test
def _get_content(cls, file): """ Get and return the content of the given log file. :param file: The file we have to get the content from. :type file: str :return The content of the given file. :rtype: dict """ if PyFunceble.path.isfile(file): ...
python
{ "resource": "" }
q270365
Logs._write_content
test
def _write_content(cls, content, file): """ Write the content into the given file. :param content: The dict to write. :type content: dict :param file: The file to write. :type file: str """ if not PyFunceble.CONFIGURATION["no_files"]: if not...
python
{ "resource": "" }
q270366
Logs.whois
test
def whois(self, record): """ Logs the WHOIS record if needed. :param record: The record to log. :type record: str """ if PyFunceble.CONFIGURATION["debug"] and PyFunceble.CONFIGURATION["logs"]: # The debug and the logs subsystem are activated. if...
python
{ "resource": "" }
q270367
Logs.expiration_date
test
def expiration_date(self, extracted): """ Logs the extracted expiration date. :param extracted: The extracted expiration date (from WHOIS record). :type extracted: str """ if PyFunceble.CONFIGURATION["logs"]: # The logs subsystem is activated. i...
python
{ "resource": "" }
q270368
Logs.referer_not_found
test
def referer_not_found(self, extension): """ Logs the case that the referer was not found. :param extension: The extension of the domain we are testing. :type extension: str """ if PyFunceble.CONFIGURATION["logs"]: # The logs subsystem is activated. ...
python
{ "resource": "" }
q270369
Prints._before_header
test
def _before_header(self): """ Print informations about PyFunceble and the date of generation of a file into a given path, if doesn't exist. """ if ( not PyFunceble.CONFIGURATION["no_files"] and self.output and not PyFunceble.path.isfile(self.o...
python
{ "resource": "" }
q270370
Prints._header_constructor
test
def _header_constructor( cls, data_to_print, header_separator="-", column_separator=" " ): """ Construct header of the table according to template. :param data_to_print: The list of data to print into the header of the table. :type data_to_print: list :p...
python
{ "resource": "" }
q270371
Prints.header
test
def header( self, do_not_print=False ): # pragma: no cover pylint: disable=too-many-branches """ Management and creation of templates of header. Please consider as "header" the title of each columns. :param do_not_print: Tell us if we have to print the header or...
python
{ "resource": "" }
q270372
Prints._data_constructor
test
def _data_constructor(self, size): """ Construct the table of data according to given size. :param size: The maximal length of each string in the table. :type size: list :return: A dict with all information about the data and how to which what maximal si...
python
{ "resource": "" }
q270373
Prints._size_from_header
test
def _size_from_header(cls, header): """ Get the size of each columns from the header. :param header: The header template we have to get the size from. :type header: dict :return: The maximal size of the each data to print. :rtype: list """ #...
python
{ "resource": "" }
q270374
Prints._colorify
test
def _colorify(self, data): """ Retun colored string. :param data: The string to colorify. :type data: str :return: A colored string. :rtype: str """ if self.template in ["Generic", "Less"]: # The template is in the list of template that need...
python
{ "resource": "" }
q270375
Prints._json_print
test
def _json_print(self): # pragma: no cover """ Management of the json template. """ if self.output: # The given output is not empty. if PyFunceble.path.isfile(self.output): # The given output already exist. # We get the content o...
python
{ "resource": "" }
q270376
Prints.data
test
def data(self): # pragma: no cover pylint: disable=inconsistent-return-statements """ Management and input of data to the table. :raises: :code:`Exception` When self.data_to_print is not a list. """ if isinstance(self.data_to_print, list): ...
python
{ "resource": "" }
q270377
ExecutionTime._save
test
def _save(self, last=False): # pragma: no cover """ Save the current time to the file. :param last: Tell us if we are at the very end of the file testing. :type last: bool """ if ( self._authorization() and PyFunceble.CONFIGURATION["...
python
{ "resource": "" }
q270378
ExecutionTime._calculate
test
def _calculate(cls, start=None, end=None): """ calculate the difference between starting and ending time. :param start: A starting time. :type start: int|str :param stop: A ending time. :type stop: int|str :return: A dict with following as index. ...
python
{ "resource": "" }
q270379
ExecutionTime.format_execution_time
test
def format_execution_time(self, start=None, end=None): """ Format the calculated time into a human readable format. :param start: A starting time. :type start: int|str :param stop: A ending time. :type stop: int|str :return: A human readable date. :rtyp...
python
{ "resource": "" }
q270380
Clean.file_to_delete
test
def file_to_delete(cls): """ Return the list of file to delete. """ # We initiate the directory we have to look for. directory = PyFunceble.OUTPUT_DIRECTORY + PyFunceble.OUTPUTS["parent_directory"] if not directory.endswith(PyFunceble.directory_separator): # pragma: no...
python
{ "resource": "" }
q270381
Clean.databases_to_delete
test
def databases_to_delete(cls): # pragma: no cover """ Set the databases files to delete. """ # We initiate the directory we have to look for. directory = PyFunceble.CURRENT_DIRECTORY # We initate the result variable. result = [] # We append the dir_stru...
python
{ "resource": "" }
q270382
Clean.almost_everything
test
def almost_everything(self, clean_all=False): """ Delete almost all discovered files. :param clean_all: Tell the subsystem if we have to clean everything instesd of almost everything. :type clean_all: bool """ # We get the list of file to delete....
python
{ "resource": "" }
q270383
Hash._hash_file
test
def _hash_file(self, algo): """Get the hash of the given file :param algo: The algorithm to use. :type algo: str :return: The hexdigest of the data. :rtype: str """ # We het the algorithm function. hash_data = getattr(hashlib, algo)() with open...
python
{ "resource": "" }
q270384
Hash._hash_data
test
def _hash_data(self, algo): """ Get hash of the given data. :param algo: The algorithm to use. :type algo: str """ # We het the algorithm function. hash_data = getattr(hashlib, algo)() # We set the data into our hashlib. hash_data.update(self.da...
python
{ "resource": "" }
q270385
Hash.get
test
def get(self): """ Return the hash of the given file """ # We initiate a variable which will save the result we are going # to return. result = {} if self.algorithm in self.valid_algorithms: # * The parsed path exist. # and # ...
python
{ "resource": "" }
q270386
Command.execute
test
def execute(self): """ Execute the given command. :return: The output of the command. :rtype: str """ # We initiate a process and parse the command to it. process = Popen(self.command, stdout=PIPE, stderr=PIPE, shell=True) # We communicate the command a...
python
{ "resource": "" }
q270387
Dict.remove_key
test
def remove_key(self, key_to_remove): """ Remove a given key from a given dictionary. :param key_to_remove: The key(s) to delete. :type key_to_remove: list|str :return: The dict without the given key(s). :rtype: dict|None """ if isinstance(self.main_dict...
python
{ "resource": "" }
q270388
Dict.rename_key
test
def rename_key(self, key_to_rename, strict=True): """ Rename the given keys from the given dictionary. :param key_to_rename: The key(s) to rename. Expected format: :code:`{old:new}` :type key_to_rename: dict :param strict: Tell us if we have ...
python
{ "resource": "" }
q270389
Dict.merge
test
def merge(self, to_merge, strict=True): """ Merge the content of to_merge into the given main dictionnary. :param to_merge: The dictionnary to merge. :type to_merge: dict :param strict: Tell us if we have to strictly merge lists. :code:`True`: We follow...
python
{ "resource": "" }
q270390
Dict.to_json
test
def to_json(self, destination): """ Save a dictionnary into a JSON file. :param destination: A path to a file where we're going to write the converted dict into a JSON format. :type destination: str """ try: with open(destination, "w"...
python
{ "resource": "" }
q270391
Dict.to_yaml
test
def to_yaml(self, destination, flow_style=False): """ Save a dictionnary into a YAML file. :param destination: A path to a file where we're going to write the converted dict into a JSON format. :type destination: str """ with open(destination, "w...
python
{ "resource": "" }
q270392
Directory.fix_path
test
def fix_path(self, splited_path=None): """ Fix the path of the given path. :param splited_path: A list to convert to the right path. :type splited_path: list :return: The fixed path. :rtype: str """ if not splited_path: # A splited path is p...
python
{ "resource": "" }
q270393
File.write
test
def write(self, data_to_write, overwrite=False): """ Write or append data into the given file path. :param data_to_write: The data to write. :type data_to_write: str :param overwrite: Tell us if we have to overwrite the content of the file we are working...
python
{ "resource": "" }
q270394
File.read
test
def read(self): """ Read a given file path and return its content. :return: The content of the given file path. :rtype: str """ try: with open(self.file, "r", encoding="utf-8") as file: # We open and read a file. # We get the...
python
{ "resource": "" }
q270395
List.format
test
def format(self): """ Return a well formatted list. Basicaly, it's sort a list and remove duplicate. :return: A sorted, without duplicate, list. :rtype: list """ try: return sorted(list(set(self.main_list)), key=str.lower) except TypeError: # pragm...
python
{ "resource": "" }
q270396
List.merge
test
def merge(self, to_merge, strict=True): """ Merge to_merge into the given main list. :param to_merge: The list to merge. :type to_merge: list :param strict: Tell us if we have to respect index (True) or not (False). :type strict: bool :r...
python
{ "resource": "" }
q270397
Regex.not_matching_list
test
def not_matching_list(self): """ Return a list of string which don't match the given regex. """ pre_result = comp(self.regex) return [x for x in self.data if not pre_result.search(str(x))]
python
{ "resource": "" }
q270398
Regex.match
test
def match(self): """ Used to get exploitable result of re.search :return: The data of the match status. :rtype: mixed """ # We initate this variable which gonna contain the returned data result = [] # We compile the regex string to_match = comp(...
python
{ "resource": "" }
q270399
Regex.replace
test
def replace(self): """ Used to replace a matched string with another. :return: The data after replacement. :rtype: str """ if self.replace_with: # pylint: disable=no-member return substrings( self.regex, self.replace_with, #...
python
{ "resource": "" }