flow.record 3.14.dev4__tar.gz → 3.15.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. {flow.record-3.14.dev4/flow.record.egg-info → flow.record-3.15.dev1}/PKG-INFO +1 -1
  2. flow.record-3.15.dev1/flow/record/adapter/line.py +81 -0
  3. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/base.py +1 -1
  4. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/fieldtypes/__init__.py +25 -17
  5. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/tools/rdump.py +13 -1
  6. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/version.py +2 -2
  7. {flow.record-3.14.dev4 → flow.record-3.15.dev1/flow.record.egg-info}/PKG-INFO +1 -1
  8. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_fieldtypes.py +26 -6
  9. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_rdump.py +45 -0
  10. flow.record-3.14.dev4/flow/record/adapter/line.py +0 -44
  11. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/COPYRIGHT +0 -0
  12. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/LICENSE +0 -0
  13. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/MANIFEST.in +0 -0
  14. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/README.md +0 -0
  15. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/examples/filesystem.py +0 -0
  16. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/examples/passivedns.py +0 -0
  17. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/examples/records.json +0 -0
  18. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/examples/tcpconn.py +0 -0
  19. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/__init__.py +0 -0
  20. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/__init__.py +0 -0
  21. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/archive.py +0 -0
  22. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/avro.py +0 -0
  23. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/broker.py +0 -0
  24. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/csvfile.py +0 -0
  25. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/elastic.py +0 -0
  26. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/jsonfile.py +0 -0
  27. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/mongo.py +0 -0
  28. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/split.py +0 -0
  29. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/splunk.py +0 -0
  30. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/sqlite.py +0 -0
  31. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/stream.py +0 -0
  32. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/text.py +0 -0
  33. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/adapter/xlsx.py +0 -0
  34. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/exceptions.py +0 -0
  35. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/fieldtypes/credential.py +0 -0
  36. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/fieldtypes/net/__init__.py +0 -0
  37. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/fieldtypes/net/ip.py +0 -0
  38. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/fieldtypes/net/ipv4.py +0 -0
  39. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/fieldtypes/net/tcp.py +0 -0
  40. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/fieldtypes/net/udp.py +0 -0
  41. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/jsonpacker.py +0 -0
  42. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/packer.py +0 -0
  43. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/selector.py +0 -0
  44. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/stream.py +0 -0
  45. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/tools/__init__.py +0 -0
  46. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/tools/geoip.py +0 -0
  47. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/utils.py +0 -0
  48. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow/record/whitelist.py +0 -0
  49. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow.record.egg-info/SOURCES.txt +0 -0
  50. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow.record.egg-info/dependency_links.txt +0 -0
  51. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow.record.egg-info/entry_points.txt +0 -0
  52. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow.record.egg-info/requires.txt +0 -0
  53. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/flow.record.egg-info/top_level.txt +0 -0
  54. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/pyproject.toml +0 -0
  55. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/setup.cfg +0 -0
  56. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/__init__.py +0 -0
  57. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/_utils.py +0 -0
  58. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/docs/Makefile +0 -0
  59. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/docs/conf.py +0 -0
  60. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/docs/index.rst +0 -0
  61. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/selector_explain_example.py +0 -0
  62. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/standalone_test.py +0 -0
  63. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_avro.py +0 -0
  64. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_avro_adapter.py +0 -0
  65. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_compiled_selector.py +0 -0
  66. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_csv_adapter.py +0 -0
  67. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_deprecations.py +0 -0
  68. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_fieldtype_ip.py +0 -0
  69. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_json_packer.py +0 -0
  70. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_json_record_adapter.py +0 -0
  71. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_multi_timestamp.py +0 -0
  72. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_packer.py +0 -0
  73. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_record.py +0 -0
  74. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_record_adapter.py +0 -0
  75. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_record_descriptor.py +0 -0
  76. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_regression.py +0 -0
  77. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_selector.py +0 -0
  78. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_splunk_adapter.py +0 -0
  79. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/test_sqlite_adapter.py +0 -0
  80. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tests/utils_inspect.py +0 -0
  81. {flow.record-3.14.dev4 → flow.record-3.15.dev1}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flow.record
3
- Version: 3.14.dev4
3
+ Version: 3.15.dev1
4
4
  Summary: A library for defining and creating structured data (called records) that can be streamed to disk or piped to other tools that use flow.record
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -0,0 +1,81 @@
1
+ from __future__ import annotations
2
+
3
+ from functools import lru_cache
4
+
5
+ from flow.record import Record, RecordDescriptor, open_path_or_stream
6
+ from flow.record.adapter import AbstractWriter
7
+ from flow.record.utils import is_stdout
8
+
9
+ __usage__ = """
10
+ Line output format adapter (writer only)
11
+ ---
12
+ Write usage: rdump -w line://[PATH]?verbose=[VERBOSE]
13
+ [PATH]: path to file. Leave empty or "-" to output to stdout
14
+
15
+ Optional arguments:
16
+ [VERBOSE]: Also show fieldtype in line output (default: False)
17
+ """
18
+
19
+
20
+ @lru_cache(maxsize=1024)
21
+ def field_types_for_record_descriptor(desc: RecordDescriptor) -> dict[str, str]:
22
+ """Return dictionary of fieldname -> fieldtype for given RecordDescriptor.
23
+
24
+ Args:
25
+ desc: RecordDescriptor to get fieldtypes for
26
+ Returns:
27
+ Dictionary of fieldname -> fieldtype
28
+ """
29
+ return {fname: fieldset.typename for fname, fieldset in desc.get_all_fields().items()}
30
+
31
+
32
+ class LineWriter(AbstractWriter):
33
+ """Prints all fields and values of the Record on a separate line."""
34
+
35
+ fp = None
36
+
37
+ def __init__(
38
+ self,
39
+ path: str,
40
+ *,
41
+ fields: list[str] | str | None = None,
42
+ exclude: list[str] | str | None = None,
43
+ verbose: bool = False,
44
+ **kwargs,
45
+ ):
46
+ self.fp = open_path_or_stream(path, "wb")
47
+ self.count = 0
48
+ self.fields = fields
49
+ self.exclude = exclude
50
+ self.verbose = verbose
51
+ if isinstance(self.fields, str):
52
+ self.fields = self.fields.split(",")
53
+ if isinstance(self.exclude, str):
54
+ self.exclude = self.exclude.split(",")
55
+
56
+ def write(self, rec: Record) -> None:
57
+ rdict = rec._asdict(fields=self.fields, exclude=self.exclude)
58
+ rdict_types = field_types_for_record_descriptor(rec._desc) if self.verbose else None
59
+
60
+ self.count += 1
61
+ self.fp.write(f"--[ RECORD {self.count} ]--\n".encode())
62
+ if rdict:
63
+ if rdict_types:
64
+ # also account for extra characters for fieldtype and whitespace + parenthesis
65
+ width = max(len(k + rdict_types[k]) for k in rdict) + 3
66
+ else:
67
+ width = max(len(k) for k in rdict)
68
+ fmt = "{{:>{width}}} = {{}}\n".format(width=width)
69
+ for key, value in rdict.items():
70
+ if rdict_types:
71
+ key = f"{key} ({rdict_types[key]})"
72
+ self.fp.write(fmt.format(key, value).encode())
73
+
74
+ def flush(self) -> None:
75
+ if self.fp:
76
+ self.fp.flush()
77
+
78
+ def close(self) -> None:
79
+ if self.fp and not is_stdout(self.fp):
80
+ self.fp.close()
81
+ self.fp = None
@@ -499,7 +499,7 @@ class RecordDescriptor:
499
499
  "_source": RecordField("_source", "string"),
500
500
  "_classification": RecordField("_classification", "datetime"),
501
501
  "_generated": RecordField("_generated", "datetime"),
502
- "_version": RecordField("_version", "vaeint"),
502
+ "_version": RecordField("_version", "varint"),
503
503
  }
504
504
 
505
505
  Returns:
@@ -32,6 +32,7 @@ NATIVE_UNICODE = isinstance("", str)
32
32
  UTC = timezone.utc
33
33
 
34
34
  PY_311 = sys.version_info >= (3, 11, 0)
35
+ PY_312 = sys.version_info >= (3, 12, 0)
35
36
 
36
37
  PATH_POSIX = 0
37
38
  PATH_WINDOWS = 1
@@ -645,28 +646,31 @@ class path(pathlib.PurePath, FieldType):
645
646
  for path_part in args:
646
647
  if isinstance(path_part, pathlib.PureWindowsPath):
647
648
  cls = windows_path
648
- # The (string) representation of a pathlib.PureWindowsPath is not round trip equivalent if a
649
- # path starts with a \ or / followed by a drive letter, e.g.: \C:\...
650
- # Meaning:
651
- #
652
- # str(PureWindowsPath(r"\C:\WINDOWS/Temp")) !=
653
- # str(PureWindowsPath(PureWindowsPath(r"\C:\WINDOWS/Temp"))),
654
- #
655
- # repr(PureWindowsPath(r"\C:\WINDOWS/Temp")) !=
656
- # repr(PureWindowsPath(PureWindowsPath(r"\C:\WINDOWS/Temp"))),
657
- #
658
- # This would be the case though when using PurePosixPath instead.
659
- #
660
- # This construction works around that by converting all path parts
661
- # to strings first.
662
- args = (str(arg) for arg in args)
649
+ if not PY_312:
650
+ # For Python < 3.12, the (string) representation of a
651
+ # pathlib.PureWindowsPath is not round trip equivalent if a path
652
+ # starts with a \ or / followed by a drive letter, e.g.: \C:\...
653
+ # Meaning:
654
+ #
655
+ # str(PureWindowsPath(r"\C:\WINDOWS/Temp")) !=
656
+ # str(PureWindowsPath(PureWindowsPath(r"\C:\WINDOWS/Temp"))),
657
+ #
658
+ # repr(PureWindowsPath(r"\C:\WINDOWS/Temp")) !=
659
+ # repr(PureWindowsPath(PureWindowsPath(r"\C:\WINDOWS/Temp"))),
660
+ #
661
+ # This would be the case though when using PurePosixPath instead.
662
+ #
663
+ # This construction works around that by converting all path parts
664
+ # to strings first.
665
+ args = (str(arg) for arg in args)
663
666
  elif isinstance(path_part, pathlib.PurePosixPath):
664
667
  cls = posix_path
665
668
  elif _is_windowslike_path(path_part):
666
669
  # This handles any custom PurePath based implementations that have a windows
667
670
  # like path separator (\).
668
671
  cls = windows_path
669
- args = (str(arg) for arg in args)
672
+ if not PY_312:
673
+ args = (str(arg) for arg in args)
670
674
  elif _is_posixlike_path(path_part):
671
675
  # This handles any custom PurePath based implementations that don't have a
672
676
  # windows like path separator (\).
@@ -675,7 +679,11 @@ class path(pathlib.PurePath, FieldType):
675
679
  continue
676
680
  break
677
681
 
678
- return cls._from_parts(args)
682
+ if PY_312:
683
+ obj = super().__new__(cls)
684
+ else:
685
+ obj = cls._from_parts(args)
686
+ return obj
679
687
 
680
688
  def __eq__(self, other: Any) -> bool:
681
689
  if isinstance(other, str):
@@ -98,7 +98,9 @@ def main(argv=None):
98
98
  output.add_argument("-c", "--count", type=int, help="Exit after COUNT records")
99
99
  output.add_argument("--skip", metavar="COUNT", type=int, default=0, help="Skip the first COUNT records")
100
100
  output.add_argument("-w", "--writer", metavar="OUTPUT", default=None, help="Write records to output")
101
- output.add_argument("-m", "--mode", default=None, choices=("csv", "json", "jsonlines", "line"), help="Output mode")
101
+ output.add_argument(
102
+ "-m", "--mode", default=None, choices=("csv", "json", "jsonlines", "line", "line-verbose"), help="Output mode"
103
+ )
102
104
  output.add_argument(
103
105
  "--split", metavar="COUNT", default=None, type=int, help="Write record files smaller than COUNT records"
104
106
  )
@@ -155,6 +157,15 @@ def main(argv=None):
155
157
  default=argparse.SUPPRESS,
156
158
  help="Short for --mode=line",
157
159
  )
160
+ aliases.add_argument(
161
+ "-Lv",
162
+ "--line-verbose",
163
+ action="store_const",
164
+ const="line-verbose",
165
+ dest="mode",
166
+ default=argparse.SUPPRESS,
167
+ help="Short for --mode=line-verbose",
168
+ )
158
169
 
159
170
  args = parser.parse_args(argv)
160
171
 
@@ -176,6 +187,7 @@ def main(argv=None):
176
187
  "json": "jsonfile://?indent=2&descriptors=false",
177
188
  "jsonlines": "jsonfile://?descriptors=false",
178
189
  "line": "line://",
190
+ "line-verbose": "line://?verbose=true",
179
191
  }
180
192
  uri = mode_to_uri.get(args.mode, uri)
181
193
  qparams = {
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '3.14.dev4'
16
- __version_tuple__ = version_tuple = (3, 14, 'dev4')
15
+ __version__ = version = '3.15.dev1'
16
+ __version_tuple__ = version_tuple = (3, 15, 'dev1')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flow.record
3
- Version: 3.14.dev4
3
+ Version: 3.15.dev1
4
4
  Summary: A library for defining and creating structured data (called records) that can be streamed to disk or piped to other tools that use flow.record
5
5
  Author-email: Dissect Team <dissect@fox-it.com>
6
6
  License: Affero General Public License v3
@@ -3,6 +3,8 @@
3
3
  import hashlib
4
4
  import os
5
5
  import pathlib
6
+ import posixpath
7
+ import types
6
8
  from datetime import datetime, timedelta, timezone
7
9
 
8
10
  import pytest
@@ -12,6 +14,7 @@ from flow.record import RecordDescriptor, RecordReader, RecordWriter
12
14
  from flow.record.fieldtypes import (
13
15
  PATH_POSIX,
14
16
  PATH_WINDOWS,
17
+ PY_312,
15
18
  _is_posixlike_path,
16
19
  _is_windowslike_path,
17
20
  )
@@ -527,12 +530,29 @@ def test_digest():
527
530
 
528
531
 
529
532
  def custom_pure_path(sep, altsep):
530
- class CustomFlavour(pathlib._PosixFlavour):
531
- def __new__(cls):
532
- instance = pathlib._PosixFlavour.__new__(cls)
533
- instance.sep = sep
534
- instance.altsep = altsep
535
- return instance
533
+ # Starting from Python 3.12, pathlib._Flavours are removed as you can
534
+ # now properly subclass pathlib.Path
535
+ # The flavour property of Path's is replaced by a link to e.g.
536
+ # posixpath or ntpath.
537
+ # See also: https://github.com/python/cpython/issues/88302
538
+ if PY_312:
539
+
540
+ class CustomFlavour:
541
+ def __new__(cls, *args, **kwargs):
542
+ flavour = types.ModuleType("mockpath")
543
+ flavour.__dict__.update(posixpath.__dict__)
544
+ flavour.sep = sep
545
+ flavour.altsep = altsep
546
+ return flavour
547
+
548
+ else:
549
+
550
+ class CustomFlavour(pathlib._PosixFlavour):
551
+ def __new__(cls):
552
+ instance = super().__new__(cls)
553
+ instance.sep = sep
554
+ instance.altsep = altsep
555
+ return instance
536
556
 
537
557
  class PureCustomPath(pathlib.PurePath):
538
558
  _flavour = CustomFlavour()
@@ -624,3 +624,48 @@ def test_flow_record_invalid_tz(tmp_path, capsys):
624
624
 
625
625
  # restore DISPLAY_TZINFO just in case
626
626
  flow.record.fieldtypes.DISPLAY_TZINFO = flow_record_tz(default_tz="UTC")
627
+
628
+
629
+ @pytest.mark.parametrize(
630
+ "rdump_params",
631
+ [
632
+ ["--mode=line-verbose"],
633
+ ["--line-verbose"],
634
+ ["-Lv"],
635
+ ["-w", "line://?verbose=true"],
636
+ ["-w", "line://?verbose=1"],
637
+ ["-w", "line://?verbose=True"],
638
+ ],
639
+ )
640
+ def test_rdump_line_verbose(tmp_path, capsys, rdump_params):
641
+ TestRecord = RecordDescriptor(
642
+ "test/rdump/line_verbose",
643
+ [
644
+ ("datetime", "stamp"),
645
+ ("bytes", "data"),
646
+ ("uint32", "counter"),
647
+ ("string", "foo"),
648
+ ],
649
+ )
650
+ record_path = tmp_path / "test.records"
651
+
652
+ with RecordWriter(record_path) as writer:
653
+ writer.write(TestRecord(counter=1))
654
+ writer.write(TestRecord(counter=2))
655
+ writer.write(TestRecord(counter=3))
656
+
657
+ from flow.record.adapter.line import field_types_for_record_descriptor
658
+
659
+ field_types_for_record_descriptor.cache_clear()
660
+ assert field_types_for_record_descriptor.cache_info().currsize == 0
661
+ rdump.main([str(record_path)] + rdump_params)
662
+ assert field_types_for_record_descriptor.cache_info().misses == 1
663
+ assert field_types_for_record_descriptor.cache_info().hits == 2
664
+ assert field_types_for_record_descriptor.cache_info().currsize == 1
665
+
666
+ captured = capsys.readouterr()
667
+ assert captured.err == ""
668
+ assert "stamp (datetime) =" in captured.out
669
+ assert "data (bytes) =" in captured.out
670
+ assert "counter (uint32) =" in captured.out
671
+ assert "foo (string) =" in captured.out
@@ -1,44 +0,0 @@
1
- from flow.record import open_path_or_stream
2
- from flow.record.adapter import AbstractWriter
3
- from flow.record.utils import is_stdout
4
-
5
- __usage__ = """
6
- Line output format adapter (writer only)
7
- ---
8
- Write usage: rdump -w line://[PATH]
9
- [PATH]: path to file. Leave empty or "-" to output to stdout
10
- """
11
-
12
-
13
- class LineWriter(AbstractWriter):
14
- """Prints all fields and values of the Record on a separate line."""
15
-
16
- fp = None
17
-
18
- def __init__(self, path, fields=None, exclude=None, **kwargs):
19
- self.fp = open_path_or_stream(path, "wb")
20
- self.count = 0
21
- self.fields = fields
22
- self.exclude = exclude
23
- if isinstance(self.fields, str):
24
- self.fields = self.fields.split(",")
25
- if isinstance(self.exclude, str):
26
- self.exclude = self.exclude.split(",")
27
-
28
- def write(self, rec):
29
- rdict = rec._asdict(fields=self.fields, exclude=self.exclude)
30
- self.count += 1
31
- self.fp.write("--[ RECORD {} ]--\n".format(self.count).encode())
32
- if rdict:
33
- fmt = "{{:>{width}}} = {{}}\n".format(width=max(len(k) for k in rdict))
34
- for key, value in rdict.items():
35
- self.fp.write(fmt.format(key, value).encode())
36
-
37
- def flush(self):
38
- if self.fp:
39
- self.fp.flush()
40
-
41
- def close(self):
42
- if self.fp and not is_stdout(self.fp):
43
- self.fp.close()
44
- self.fp = None
File without changes
File without changes