AdBlock

Problematic

How can we efficiently decode AdBlock filter list?

Documentation

The tool to check the availability or syntax of domains, IPv4 or URL.

██████╗ ██╗   ██╗███████╗██╗   ██╗███╗   ██╗ ██████╗███████╗██████╗ ██╗     ███████╗
██╔══██╗╚██╗ ██╔╝██╔════╝██║   ██║████╗  ██║██╔════╝██╔════╝██╔══██╗██║     ██╔════╝
██████╔╝ ╚████╔╝ █████╗  ██║   ██║██╔██╗ ██║██║     █████╗  ██████╔╝██║     █████╗
██╔═══╝   ╚██╔╝  ██╔══╝  ██║   ██║██║╚██╗██║██║     ██╔══╝  ██╔══██╗██║     ██╔══╝
██║        ██║   ██║     ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗
╚═╝        ╚═╝   ╚═╝      ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝

This submodule will provide adblock decoding interface.

Author:
Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom
Special thanks:
https://pyfunceble.github.io/special-thanks.html
Contributors:
https://pyfunceble.github.io/contributors.html
Project link:
https://github.com/funilrys/PyFunceble
Project documentation:
https://pyfunceble.readthedocs.io/en/master/
Project homepage:
https://pyfunceble.github.io/

License:

MIT License

Copyright (c) 2017, 2018, 2019 Nissar Chababy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
class PyFunceble.adblock.AdBlock(list_from_file, aggressive=False)[source]

Provide the adblock decoding logic.

Parameters:
  • list_from_file (list) – The file in list format.
  • aggressive (bool) –

    Activate the extration of all domains present into the given adbloack filter list.

    Warning

    This is for now for testing purpose.

    It may be one day accessible to the public but please if you read this, think twice before using it.

_extract_base(element)[source]

Extract the base of the given element.

As an example:
given "hello.world/?is=beautiful" returns "hello.world"
Parameters:element (str|list) – The element we are working with.
_format_decoded(to_format, result=None)[source]

Format the exctracted adblock line before passing it to the system.

Parameters:
  • to_format (str) – The extracted line from the file.
  • result (list) – A list of the result of this method.
Returns:

The list of domains or IP to test.

Return type:

list

_handle_options(options)[source]

Handle the data from the options.

Parameters:options (list) – The list of options from the rule.
Returns:The list of domains to return globally.
Return type:list
classmethod _is_to_ignore(line)[source]

Check if we have to ignore the given line.

Parameters:line (str) – The line from the file.
Returns:The result of the check.
Return type:bool
_remove_ignored(list_from_file)[source]

Removed the ignored element from the given list.

Parameters:list_from_file (list) – The list which represent the file we are decoding.
Returns:The filtered list.
Return type:list
decode()[source]

Decode/extract the domains to test from the adblock formated file.

Returns:The list of domains to test.
Return type:list