Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-ttp for openSUSE:Factory 
checked in at 2024-01-03 12:24:34
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-ttp (Old)
 and      /work/SRC/openSUSE:Factory/.python-ttp.new.28375 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-ttp"

Wed Jan  3 12:24:34 2024 rev:4 rq:1135639 version:0.9.5

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-ttp/python-ttp.changes    2023-05-03 
12:57:15.251824357 +0200
+++ /work/SRC/openSUSE:Factory/.python-ttp.new.28375/python-ttp.changes 
2024-01-03 12:24:41.938843652 +0100
@@ -1,0 +2,10 @@
+Wed Dec 27 15:56:30 UTC 2023 - Dirk Müller <[email protected]>
+
+- update to 0.9.5:
+  * 1. group `to_int` function improved handling of missing keys,
+  * 2. group `to_int` function added support to handle list of
+    integers conversion, #109
+  * 3. group `to_int` function improved best effort conversion
+    logic to not fail on any conversion error at all
+
+-------------------------------------------------------------------

Old:
----
  ttp-0.9.4.tar.gz

New:
----
  ttp-0.9.5.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-ttp.spec ++++++
--- /var/tmp/diff_new_pack.9vOiqH/_old  2024-01-03 12:24:42.886878291 +0100
+++ /var/tmp/diff_new_pack.9vOiqH/_new  2024-01-03 12:24:42.890878438 +0100
@@ -25,7 +25,7 @@
 %bcond_with test
 %endif
 Name:           python-ttp%{psuffix}
-Version:        0.9.4
+Version:        0.9.5
 Release:        0
 Summary:        Template Text Parser
 License:        MIT

++++++ ttp-0.9.4.tar.gz -> ttp-0.9.5.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ttp-0.9.4/pyproject.toml new/ttp-0.9.5/pyproject.toml
--- old/ttp-0.9.4/pyproject.toml        2023-04-23 15:35:34.000000000 +0200
+++ new/ttp-0.9.5/pyproject.toml        2023-06-25 02:27:08.000000000 +0200
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "ttp"
-version = "0.9.4"
+version = "0.9.5"
 description = "Template Text Parser"
 authors = ["Denis Mulyalin <[email protected]>"]
 maintainers = ["Denis Mulyalin <[email protected]>"]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ttp-0.9.4/test/pytest/test_group_functions.py 
new/ttp-0.9.5/test/pytest/test_group_functions.py
--- old/ttp-0.9.4/test/pytest/test_group_functions.py   2023-04-23 
15:35:34.000000000 +0200
+++ new/ttp-0.9.5/test/pytest/test_group_functions.py   2023-06-25 
02:27:08.000000000 +0200
@@ -864,4 +864,127 @@
                                  'switched-vlan': {'mode': 'access'},
                                  'vrf': 'XYZ'}]}}]]
                                                                 
-# test_expand_issue_65()
\ No newline at end of file
+# test_expand_issue_65()
+
+def test_group_to_int_for_non_integer():
+    template = """
+<input load="text">
+interface GigabitEthernet1/1
+   mtu ABC
+!
+interface GigabitEthernet1/2
+   mtu 8000
+!    
+interface GigabitEthernet1/2
+   mtu 9200.0
+!    
+</input>
+
+<group to_int="">
+interface {{ name }}
+   mtu {{ mtu }}
+</group>
+    """
+    parser = ttp(template=template)
+    parser.parse()
+    res = parser.result()
+    pprint.pprint(res) 
+    assert res == [[[{'mtu': 'ABC', 'name': 'GigabitEthernet1/1'},
+                     {'mtu': 8000, 'name': 'GigabitEthernet1/2'},
+                     {'mtu': 9200.0, 'name': 'GigabitEthernet1/2'}]]]
+   
+# test_group_to_int_for_non_integer()
+    
+def test_group_to_int_missing_key_issue_109():
+    template = """
+<input load="text">
+interface GigabitEthernet1/1
+   mtu ABC
+!
+interface GigabitEthernet1/2
+   mtu 8000
+!    
+interface GigabitEthernet1/2
+   mtu 9200.0
+!    
+</input>
+
+<group to_int="mtu, foo, bar">
+interface {{ name }}
+   mtu {{ mtu }}
+</group>
+    """
+    parser = ttp(template=template)
+    parser.parse()
+    res = parser.result()
+    pprint.pprint(res) 
+    assert res == [[[{'mtu': 'ABC', 'name': 'GigabitEthernet1/1'},
+                     {'mtu': 8000, 'name': 'GigabitEthernet1/2'},
+                     {'mtu': 9200.0, 'name': 'GigabitEthernet1/2'}]]]
+
+# test_group_to_int_missing_key_issue_109()
+    
+def test_group_to_int_with_intlist_true_issue_109():
+    template = """
+<input load="text">
+interface GigabitEthernet1/1
+   switchport trunk allowed vlan 1,2,3,4
+!
+interface GigabitEthernet1/2
+   switchport trunk allowed vlan 123
+!    
+interface GigabitEthernet1/3
+   switchport trunk allowed vlan foo,bar
+!    
+interface GigabitEthernet1/4
+! 
+</input>
+
+<group to_int="trunk_vlan, intlist=True">
+interface {{ name }}
+   switchport trunk allowed vlan {{ trunk_vlan | split(',') }}
+</group>
+    """
+    parser = ttp(template=template)
+    parser.parse()
+    res = parser.result()
+    pprint.pprint(res)   
+    assert res == [[[{'name': 'GigabitEthernet1/1', 'trunk_vlan': [1, 2, 3, 
4]},
+                     {'name': 'GigabitEthernet1/2', 'trunk_vlan': [123]},
+                     {'name': 'GigabitEthernet1/3', 'trunk_vlan': ['foo', 
'bar']},
+                     {'name': 'GigabitEthernet1/4'}]]]
+    
+# test_group_to_int_with_intlist_issue_109()
+
+
+def test_group_to_int_with_intlist_false_issue_109():
+    template = """
+<input load="text">
+interface GigabitEthernet1/1
+   switchport trunk allowed vlan 1,2,3,4
+!
+interface GigabitEthernet1/2
+   switchport trunk allowed vlan 123
+!    
+interface GigabitEthernet1/3
+   switchport trunk allowed vlan foo,bar
+!    
+interface GigabitEthernet1/4
+! 
+</input>
+
+<group to_int="trunk_vlan">
+interface {{ name }}
+   switchport trunk allowed vlan {{ trunk_vlan | split(',') }}
+</group>
+    """
+    parser = ttp(template=template)
+    parser.parse()
+    res = parser.result()
+    pprint.pprint(res)   
+    assert res == [[[{'name': 'GigabitEthernet1/1', 'trunk_vlan': ['1', '2', 
'3', '4']},
+                     {'name': 'GigabitEthernet1/2', 'trunk_vlan': ['123']},
+                     {'name': 'GigabitEthernet1/3', 'trunk_vlan': ['foo', 
'bar']},
+                     {'name': 'GigabitEthernet1/4'}]]]
+                     
+# test_group_to_int_with_intlist_false_issue_109()
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ttp-0.9.4/ttp/__init__.py 
new/ttp-0.9.5/ttp/__init__.py
--- old/ttp-0.9.4/ttp/__init__.py       2023-04-23 15:35:34.000000000 +0200
+++ new/ttp-0.9.5/ttp/__init__.py       2023-06-25 02:27:08.000000000 +0200
@@ -2,7 +2,7 @@
 
 __all__ = ["ttp"]
 __author__ = "Denis Mulyalin <[email protected]>"
-__version__ = "0.9.4"
+__version__ = "0.9.5"
 from sys import version_info
 
 # get python version:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ttp-0.9.4/ttp/group/sformat.py 
new/ttp-0.9.5/ttp/group/sformat.py
--- old/ttp-0.9.4/ttp/group/sformat.py  2023-04-23 15:35:34.000000000 +0200
+++ new/ttp-0.9.5/ttp/group/sformat.py  2023-06-25 02:27:08.000000000 +0200
@@ -9,7 +9,9 @@
     """
     try:
         data[add_field] = string.format(**data)
-    except KeyError:  # KeyError happens when not enough keys in **data 
supplied to format method
+    except (
+        KeyError
+    ):  # KeyError happens when not enough keys in **data supplied to format 
method
         kwargs = _ttp_["global_vars"].copy()
         kwargs.update(_ttp_["vars"])
         kwargs.update(data)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ttp-0.9.4/ttp/group/to_converters.py 
new/ttp-0.9.5/ttp/group/to_converters.py
--- old/ttp-0.9.4/ttp/group/to_converters.py    2023-04-23 15:35:34.000000000 
+0200
+++ new/ttp-0.9.5/ttp/group/to_converters.py    2023-06-25 02:27:08.000000000 
+0200
@@ -12,16 +12,37 @@
     return data, None
 
 
-def to_int(data, *keys):
+def to_int(data, *keys, intlist=False):
     if not keys:
         keys = list(data.keys())
     for k in keys:
-        v = data[k]
+        # check if given key exists
+        try:
+            v = data[k]
+        except KeyError:
+            continue
+
+        # do best effort string to int conversion
         try:
             data[k] = int(v)
-        except ValueError:
+        except:
             try:
                 data[k] = float(v)
             except:
-                continue
+                pass
+
+        # convert list of integer strings to list of integers
+        if intlist is True and isinstance(data[k], list):
+            converted_list = []
+            for i in data[k]:
+                try:
+                    converted_list.append(int(i))
+                except:
+                    try:
+                        converted_list.append(float(i))
+                    except:
+                        converted_list.append(i)
+
+            data[k] = converted_list
+
     return data, None
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ttp-0.9.4/ttp/output/validate_yangson.py 
new/ttp-0.9.5/ttp/output/validate_yangson.py
--- old/ttp-0.9.4/ttp/output/validate_yangson.py        2023-04-23 
15:35:34.000000000 +0200
+++ new/ttp-0.9.5/ttp/output/validate_yangson.py        2023-06-25 
02:27:08.000000000 +0200
@@ -106,14 +106,14 @@
         ) as yf:
             _module_entry(yf)
     marr = []
-    for (yam, mrev) in modmap:
+    for yam, mrev in modmap:
         men = {"name": yam, "revision": mrev}
         sarr = []
         mrec = modmap[(yam, mrev)]
         men["namespace"] = mrec["namespace"]
         fts = mrec["features"]
         imp_only = mrec["import-only"]
-        for (subm, srev) in mrec["includes"]:
+        for subm, srev in mrec["includes"]:
             sen = {"name": subm}
             try:
                 srec = submodmap[subm]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/ttp-0.9.4/ttp/ttp.py new/ttp-0.9.5/ttp/ttp.py
--- old/ttp-0.9.4/ttp/ttp.py    2023-04-23 15:35:34.000000000 +0200
+++ new/ttp-0.9.5/ttp/ttp.py    2023-06-25 02:27:08.000000000 +0200
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-__version__ = "0.9.4"
+__version__ = "0.9.5"
 
 import re
 import os
@@ -2333,7 +2333,7 @@
         from pprint import pformat
 
         attributes = dict(vars(self))
-        _ = attributes.pop("_ttp_") # remove _ttp_ dictionary to not clutter 
the output
+        _ = attributes.pop("_ttp_")  # remove _ttp_ dictionary to not clutter 
the output
         text = "Variable object {}, Variable name '{}' content:\n{}".format(
             self, self.var_name, pformat(attributes, indent=4)
         )
@@ -3045,7 +3045,7 @@
             copied = E.copy()
         copied.update(result_data)
         return copied
-    
+
     def start(self, result, PATH, DEFAULTS=None, FUNCTIONS=None, REDICT=""):
         DEFAULTS = DEFAULTS or {}
         FUNCTIONS = FUNCTIONS or []
@@ -3200,9 +3200,9 @@
     def form_path(self, path):
         """
         Method to form dynamic path transforming it into a list of tuples,
-        where each tuple first element is a path item value and second 
-        element is a number of asterisks, need to keep asterisks count 
-        separatefrom path item value becasue match result value can end 
+        where each tuple first element is a path item value and second
+        element is a number of asterisks, need to keep asterisks count
+        separatefrom path item value becasue match result value can end
         with asterisk - issue #97
         """
         for index, path_item in enumerate(path):
@@ -3228,7 +3228,10 @@
                         path_item = re.sub(pattern, str(self.variables[m]), 
path_item)
                     else:
                         return False
-            path[index] = (path_item, asterisk_count * "*",)
+            path[index] = (
+                path_item,
+                asterisk_count * "*",
+            )
         return path
 
     def processgrp(self):
@@ -3236,12 +3239,14 @@
         # add default values to group results
         for k, v in self.record["DEFAULTS"].items():
             self.record["result"].setdefault(k, v)
-        # if merge_with_last - tail match, attempt to reconstruct group result 
-        # this only will work if self.record["result"] contains enough info to 
form PATH        
+        # if merge_with_last - tail match, attempt to reconstruct group result
+        # this only will work if self.record["result"] contains enough info to 
form PATH
         if self.record.get("merge_with_last") is True:
             processed_path = self.form_path(list(self.record["PATH"]))
             if processed_path:
-                self.record["result"] = 
self.reconstruct_last_element(self.record["result"], processed_path)
+                self.record["result"] = self.reconstruct_last_element(
+                    self.record["result"], processed_path
+                )
         # process group functions
         for item in self.record["FUNCTIONS"]:
             func_name = item["name"]
@@ -3271,7 +3276,6 @@
     """Class to serve run output functions, returners and formatters"""
 
     def __init__(self, element=None, template_obj=None, _ttp_=None, **kwargs):
-
         # set attributes default values
         self._ttp_ = _ttp_
         self.attributes = {"returner": "self", "format": "raw", "load": 
"python"}

Reply via email to