diff --git a/CHANGELOG.md b/CHANGELOG.md index 87d9df8..c67f673 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## 1.4.5 * drop Python3.9 support * fix: Setting field type by `--type` suppresses the auto-detection. +* fix: split by CIDR +* fix: single value regex preview wizzard ## 1.4.4 (2023-05-26) * fix: OTRS sending with no attachment forwarded diff --git a/README.md b/README.md index fe9ffcc..7a32482 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Any input is accepted: 6) **Aggregate** (count grouped by a column, sum...) 7) **Merge** (join other file) -Python3.7+ required (older releases support 3.6). +Python3.10+ required (older releases support up to 3.6). # Table of contents * [Usage](#usage) @@ -673,10 +673,11 @@ heLLo Specify source ```bash -# start adding a new reg column wizzard that will take plaintext "aGVsbG8=" as input +# start adding a new reg column wizzard that will take plaintext from auto-detected base64 "aGVsbG8=" as input $ convey aGVsbG8= -f reg,plaintext -# specifying plaintext as a source type will prevent implicit convertion from base64 -$ convey aGVsbG8= -f reg_s,plaintext,"[A-Z]","!" -H # substitute uppercase letters with '!' +# specifying plaintext as a source type (and not as a column) will prevent implicit conversion from base64 +# Note the 1 that specifies the (first and only) column. +$ convey aGVsbG8= -f reg_s,1,plaintext,"[A-Z]","!" -H # substitute uppercase letters with '!' a!!sb!8= ``` diff --git a/convey/controller.py b/convey/controller.py index 2678a5a..1ea117e 100644 --- a/convey/controller.py +++ b/convey/controller.py @@ -403,7 +403,7 @@ def change_dialect(s, s2): exit() return ac - def run_menu(self, ac): + def run_menu(self, ac: ActionController): # main menu start_debugger = False session = None diff --git a/convey/parser.py b/convey/parser.py index fc0959d..32f4c9a 100644 --- a/convey/parser.py +++ b/convey/parser.py @@ -148,6 +148,7 @@ def prepare(self): print("Empty contents.") exit() self.prepare_target_file() + self.sample_parsed = [x for x in csv.reader(self.sample)] # check if we are parsing a single cell if self.stdin: @@ -209,7 +210,6 @@ def join_quo(s): return self # we are parsing a CSV file - self.sample_parsed = [x for x in csv.reader(self.sample)] self.informer.sout_info() try: # Dialog to obtain basic information about CSV - delimiter, header @@ -277,7 +277,7 @@ def get_fields_autodetection(self, append_values=True): :type append_values: bool Append sample values to the informative result string. """ fields = [] - for col, field in enumerate(self.fields): + for _, field in enumerate(self.fields): s = "" if field.is_new: s = f"computed from: {field.source_type}" diff --git a/convey/processor.py b/convey/processor.py index 7a36172..59fe8b6 100644 --- a/convey/processor.py +++ b/convey/processor.py @@ -358,9 +358,10 @@ def process_line(self, parser: Parser, line: List, settings: Settings, fields: U chosen_fields = fields # determine location - if type(settings["split"]) == int: - # split ('/' is a forbidden char in linux file names) - location = fields[settings["split"]].replace("/", "-") + if type(settings["split"]) == int: # split location: + # * '/' is a forbidden char in linux file names) + # * we cast to str as the field could contain an object (like IPRange for the 'cidr' type) + location = str(fields[settings["split"]]).replace("/", "-") if not location: parser.unknown_lines_count += 1 location = Config.UNKNOWN_NAME @@ -429,10 +430,8 @@ def process_line(self, parser: Parser, line: List, settings: Settings, fields: U if self.descriptors_count >= self.descriptors_max: # too many descriptors open, we have to close the least used key = min(self.descriptorsStatsOpen, key=self.descriptorsStatsOpen.get) self.descriptors[key][0].close() - # print("Closing", key, self.descriptorsStatsOpen[key]) del self.descriptorsStatsOpen[key] self.descriptors_count -= 1 - # print("Opening", location) if location == 2: # this is a sign that we store raw data to stdout (not through a CSVWriter) t = w = parser.external_stdout # custom object simulate CSVWriter - it adopts .writerow and .close methods diff --git a/convey/wizzard.py b/convey/wizzard.py index 6b82a6e..f7ffbbf 100644 --- a/convey/wizzard.py +++ b/convey/wizzard.py @@ -17,8 +17,9 @@ from pygments.token import Token from tabulate import tabulate -from convey import PickInput from .config import Config, console_handler +from .decorators import PickInput +from .field import Field from .dialogue import Cancelled from .types import Type, Types @@ -181,7 +182,7 @@ def validate(self, document): class Preview: - def __init__(self, source_field, source_type: "Type", target_type: "Type" = None): + def __init__(self, source_field: Field, source_type: Type, target_type: Type = None): self.source_field = source_field self.source_type = source_type self.target_type = target_type