Skip to content

Commit

Permalink
replaced references to parser_object with vars in _ttp_ dictionaru fo…
Browse files Browse the repository at this point in the history
…r consistency
  • Loading branch information
dmulyalin committed Dec 3, 2022
1 parent 8a41bc2 commit 9d0f1f3
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 23 deletions.
7 changes: 6 additions & 1 deletion docs/source/Installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ Using pip::

pip install ttp

Or clone from GitHub, unzip, navigate to folder and run::
Or download code from GitHub, unzip, navigate to folder and run::

python setup.py install or python -m pip install .
Or install GIT and run installation of latest source code from GitHub master brunch::

python -m pip install git+https://github.com/dmulyalin/ttp

Install all optional dependencies::

pip install ttp[full]

Additional dependencies
-----------------------
Expand Down
2 changes: 1 addition & 1 deletion ttp/group/exclude_val.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def exclude_val(data, key, value):
check if certain key has certain value, return False if so and True otherwise
"""
# try to get value variable from parser specific variables
value = _ttp_["parser_object"].vars.get(value, value)
value = _ttp_["vars"].get(value, value)
try:
if data[key] == value:
return data, False
Expand Down
2 changes: 1 addition & 1 deletion ttp/group/validate_cerberus.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def validate(data, schema, result="valid", info="", errors="", allow_unknown=Tru
if not HAS_LIBS:
return data, None
# get validation schema
schema_data = _ttp_["parser_object"].vars.get(schema, None)
schema_data = _ttp_["vars"].get(schema, None)
if not schema_data:
log.error("ttp.validate, schema '{}' not found".format(schema))
return data, None
Expand Down
4 changes: 2 additions & 2 deletions ttp/match/count.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
def count(data, var=None, globvar=None):
if var:
try:
_ttp_["parser_object"].vars[var] += 1
_ttp_["vars"][var] += 1
except KeyError:
_ttp_["parser_object"].vars[var] = 1
_ttp_["vars"][var] = 1

if globvar:
try:
Expand Down
2 changes: 1 addition & 1 deletion ttp/match/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def ip_info(data, *args):

def cidr_match(data, prefix):
# try to get value from TTP vars variables
prefix = _ttp_["parser_object"].vars.get(prefix, prefix)
prefix = _ttp_["vars"].get(prefix, prefix)
# convert data to ipaddress object:
if isinstance(data, str):
try:
Expand Down
2 changes: 1 addition & 1 deletion ttp/match/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def gpvlookup(data, name, add_field=False, record=False, multimatch=False):
found_value += [key for pattern in patterns if fnmatch(data, pattern)]
# record found_value if told to do so:
if record is not False:
_ttp_["parser_object"].vars.update({record: found_value})
_ttp_["vars"].update({record: found_value})
_ttp_["global_vars"].update({record: found_value})
# decide to replace match result or add new field:
if not found_value:
Expand Down
4 changes: 2 additions & 2 deletions ttp/match/re_.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def exclude_re(data, pattern):


def resub(data, old, new, count=1):
vars = _ttp_["parser_object"].vars
vars = _ttp_["vars"]
if old in vars:
return re.sub(re.escape(vars[old]), new, data, count=count), None
return re.sub(old, new, data, count=count), None


def resuball(data, *args):
vars = _ttp_["parser_object"].vars
vars = _ttp_["vars"]
args = list(args)
new = ""
if len(args) > 1:
Expand Down
2 changes: 1 addition & 1 deletion ttp/match/record.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def record(data, record):
_ttp_["parser_object"].vars.update({record: data})
_ttp_["vars"].update({record: data})
_ttp_["global_vars"].update({record: data})
return data, None
2 changes: 1 addition & 1 deletion ttp/match/set_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def set_func(data, value, match_line):
vars = _ttp_["parser_object"].vars
vars = _ttp_["vars"]
if data.rstrip() == match_line:
if isinstance(value, str):
if value in vars:
Expand Down
18 changes: 6 additions & 12 deletions ttp/match/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ def exclude(data, pattern):


def equal(data, value):
if data == value:
return data, True
return data, False
return data, data == value


def notequal(data, value):
if data != value:
return data, True
return data, False
return data, data != value


def contains(data, *patterns):
Expand All @@ -32,9 +28,7 @@ def sformat(data, string):


def isdigit(data):
if data.strip().isdigit():
return data, True
return data, False
return data, data.strip().isdigit()


def notdigit(data):
Expand Down Expand Up @@ -68,7 +62,7 @@ def append(data, char):
# try to get char from global variables
char_value = _ttp_["global_vars"].get(char, char)
# try to get from input specific variables
char_value = _ttp_["parser_object"].vars.get(char, char)
char_value = _ttp_["vars"].get(char, char)
if isinstance(data, str):
return (data + char_value), None
elif isinstance(data, list):
Expand All @@ -82,7 +76,7 @@ def prepend(data, char):
# try to get char from global variables
char_value = _ttp_["global_vars"].get(char, char)
# try to get from input specific variables
char_value = _ttp_["parser_object"].vars.get(char, char)
char_value = _ttp_["vars"].get(char, char)
if isinstance(data, str):
return (char_value + data), None
elif isinstance(data, list):
Expand All @@ -98,7 +92,7 @@ def sprint(data):


def replaceall(data, *args):
vars = _ttp_["parser_object"].vars
vars = _ttp_["vars"]
args = list(args)
new = ""
if len(args) > 1:
Expand Down

0 comments on commit 9d0f1f3

Please sign in to comment.