Skip to content

Commit

Permalink
fixes: split by CIDR, regex wizzard
Browse files Browse the repository at this point in the history
  • Loading branch information
e3rd committed Nov 20, 2023
1 parent 86539d3 commit e7ac193
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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=
```
Expand Down
2 changes: 1 addition & 1 deletion convey/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions convey/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions convey/wizzard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e7ac193

Please sign in to comment.