Skip to content

Commit

Permalink
Upgrade to PyFunceble-dev 4.0.0 (alpha).
Browse files Browse the repository at this point in the history
  • Loading branch information
funilrys committed Mar 18, 2021
1 parent a3e5404 commit f764bf3
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 27 deletions.
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
recursive-include adblock_decoder *.py
graft adblock_decoder
global-exclude __pycache__
global-exclude *.py[co]
include LICENSE
include requirements.txt
include README.rst
36 changes: 32 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
adblock-decoder
===============
AdBlock Filter List Decoder
===========================

A set of tools for the decoding and conversion of AdBlock and filter lists.
The decoder itself is part of the PyFunceble project.
Expand All @@ -11,6 +11,34 @@ Installation

$ pip install --user adblock-decoder

Python API
----------

If you want to use the decoder in your own Python modules or infrastructure,
you may use the PyFunceble project to access the decoder.


::

from PyFunceble.converter.adblock_input_line2subject import AdblockInputLine2Subject

to_decode = ["||example.com^", "||example.net^"]

decoder = AdblockInputLine2Subject()
decoder.aggressive = False

decoded = set()

for line in to_decode:
# One shot method.
decoded.update(decoder.set_data_to_convert(to_decode).get_converted())

# Step by step method
decoder.set_data_to_convert(to_decode)
decoded.update(decoder.get_converted())

print("Decoded:", decoded)

Tools
-----

Expand Down Expand Up @@ -74,8 +102,8 @@ License

MIT License

Copyright (c) 2020 PyFunceble
Copyright (c) 2020 Nissar Chababy
Copyright (c) 2020, 2021 PyFunceble
Copyright (c) 2020, 2021 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
Expand Down
2 changes: 1 addition & 1 deletion adblock_decoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
SOFTWARE.
"""

VERSION = "1.0.2"
VERSION = "1.1.0"
55 changes: 35 additions & 20 deletions adblock_decoder/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,47 +61,62 @@
SOFTWARE.
"""

from tempfile import TemporaryDirectory
from typing import Optional

import PyFunceble
from PyFunceble.converter.adblock_input_line2subject import AdblockInputLine2Subject


class BaseCore:
"""
Provides the base of all cores.
"""

def __init__(self):
temp_config_dir = TemporaryDirectory()
PyFunceble.helpers.EnvironmentVariable("PYFUNCEBLE_CONFIG_DIR").set_value(
temp_config_dir.name
)
PyFunceble.load_config()
_aggressive: bool = False

decoder: Optional[AdblockInputLine2Subject] = None

def __init__(self, aggressive: Optional[bool] = None):
if aggressive is not None:
self.aggressive = aggressive

self.decoder = AdblockInputLine2Subject()

@property
def aggressive(self) -> bool:
"""
Provides the current state of the aggressive attribute.
"""

self.aggresive = False
return self.decoder.aggressive

def set_aggressive(self, value):
@aggressive.setter
def aggressive(self, value: bool) -> None:
"""
Sets the value of the aggressive variable.
Overwrites the current state of the aggressive attribute.
:param value:
The value to set.
"""

self.aggresive = value
self.decoder.aggressive = value

def get_aggressive(self):
def set_aggressive(self, value: bool) -> "BaseCore":
"""
Provides the value of the aggressive variable.
Overwrites the current state of the aggressive attribute.
:param value:
The value to set.
"""

return self.aggresive
self.aggressive = value

return self

def decode_line(self, line):
def decode_line(self, line: str):
"""
Decodes a single line.
"""

return (
x
for x in PyFunceble.converter.AdBlock(
line.strip(), aggressive=self.aggresive
).get_converted()
x for x in self.decoder.set_data_to_convert(line.strip()).get_converted()
)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PyFunceble-dev
PyFunceble-dev>=4.0.0b1
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def get_long_description():
platforms=["any"],
packages=find_packages(),
long_description=get_long_description(),
project_urls={
"Funding": "https://github.com/sponsors/funilrys",
"Source": "https://github.com/PyFunceble/adblock-decoder",
"Tracker": "https://github.com/funilrys/PyFunceble/issues",
},
keywords=["PyFunceble", "AdBlock", "Filter", "list", "decoder"],
classifiers=[
"Environment :: Console",
Expand Down

0 comments on commit f764bf3

Please sign in to comment.