Skip to content

Commit 1b5d5cf

Browse files
authored
Merge branch 'main' into fix/flatten-command-type
2 parents 18977b3 + 25d783a commit 1b5d5cf

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

flow/record/adapter/elastic.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def __init__(
8282
self.metadata_fields[arg_key[6:]] = arg_val
8383

8484
def excepthook(self, exc: threading.ExceptHookArgs, *args, **kwargs) -> None:
85-
log.error("Exception in thread: %s", exc.exc_value.message)
86-
self.exception = exc.exc_value
85+
log.error("Exception in thread: %s", exc)
86+
self.exception = getattr(exc, "exc_value", exc)
8787
self.event.set()
8888
self.close()
8989

@@ -127,6 +127,8 @@ def document_stream(self) -> Iterator[dict]:
127127
record = self.queue.get()
128128
if record is StopIteration:
129129
break
130+
if not record:
131+
continue
130132
yield self.record_to_document(record, index=self.index)
131133

132134
def streaming_bulk_thread(self) -> None:

flow/record/fieldtypes/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
PY_311_OR_HIGHER = sys.version_info >= (3, 11, 0)
3535
PY_312_OR_HIGHER = sys.version_info >= (3, 12, 0)
36+
PY_313_OR_HIGHER = sys.version_info >= (3, 13, 0)
3637

3738
TYPE_POSIX = 0
3839
TYPE_WINDOWS = 1
@@ -600,12 +601,18 @@ def _unpack(cls, data):
600601
return data
601602

602603

603-
def _is_posixlike_path(path: Any):
604-
return isinstance(path, pathlib.PurePath) and "\\" not in (path._flavour.sep, path._flavour.altsep)
604+
def _is_posixlike_path(path: Any) -> bool:
605+
if isinstance(path, pathlib.PurePath):
606+
obj = getattr(path, "parser", None) or path._flavour
607+
return "\\" not in (obj.sep, obj.altsep)
608+
return False
605609

606610

607-
def _is_windowslike_path(path: Any):
608-
return isinstance(path, pathlib.PurePath) and "\\" in (path._flavour.sep, path._flavour.altsep)
611+
def _is_windowslike_path(path: Any) -> bool:
612+
if isinstance(path, pathlib.PurePath):
613+
obj = getattr(path, "parser", None) or path._flavour
614+
return "\\" in (obj.sep, obj.altsep)
615+
return False
609616

610617

611618
class path(pathlib.PurePath, FieldType):
@@ -684,17 +691,17 @@ def __repr__(self) -> str:
684691
return repr(str(self))
685692

686693
@property
687-
def parent(self):
694+
def parent(self) -> path:
688695
if self._empty_path:
689696
return self
690697
return super().parent
691698

692-
def _pack(self):
699+
def _pack(self) -> tuple[str, int]:
693700
path_type = TYPE_WINDOWS if isinstance(self, windows_path) else TYPE_POSIX
694701
return (str(self), path_type)
695702

696703
@classmethod
697-
def _unpack(cls, data: tuple[str, str]):
704+
def _unpack(cls, data: tuple[str, str]) -> posix_path | windows_path:
698705
path_, path_type = data
699706
if path_type == TYPE_POSIX:
700707
return posix_path(path_)
@@ -705,12 +712,12 @@ def _unpack(cls, data: tuple[str, str]):
705712
return posix_path(path_)
706713

707714
@classmethod
708-
def from_posix(cls, path_: str):
715+
def from_posix(cls, path_: str) -> posix_path:
709716
"""Initialize a path instance from a posix path string using / as a separator."""
710717
return posix_path(path_)
711718

712719
@classmethod
713-
def from_windows(cls, path_: str):
720+
def from_windows(cls, path_: str) -> windows_path:
714721
"""Initialize a path instance from a windows path string using \\ or / as a separator."""
715722
return windows_path(path_)
716723

tests/test_fieldtypes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from flow.record import RecordDescriptor, RecordReader, RecordWriter, fieldtypes
1616
from flow.record.fieldtypes import (
1717
PY_312_OR_HIGHER,
18+
PY_313_OR_HIGHER,
1819
TYPE_POSIX,
1920
TYPE_WINDOWS,
2021
_is_posixlike_path,
@@ -557,8 +558,15 @@ def __new__(cls):
557558
instance.altsep = altsep
558559
return instance
559560

560-
class PureCustomPath(pathlib.PurePath):
561-
_flavour = CustomFlavour()
561+
if PY_313_OR_HIGHER:
562+
563+
class PureCustomPath(pathlib.PurePath):
564+
parser = CustomFlavour()
565+
566+
else:
567+
568+
class PureCustomPath(pathlib.PurePath):
569+
_flavour = CustomFlavour()
562570

563571
return PureCustomPath
564572

0 commit comments

Comments
 (0)