edq.util.common

Common files for utils.

Objects are often placed here to break circular dependencies.

 1"""
 2Common files for utils.
 3
 4Objects are often placed here to break circular dependencies.
 5"""
 6
 7import copy
 8import typing
 9
10class SerializationContext:
11    """
12    Context information (context and options) to aid the serialization process.
13    An instance of this class will be passed around the core serialization functions to provide context and extra options.
14    """
15
16    def __init__(self,
17            base_dir: typing.Union[str, None] = None,
18            source_path: typing.Union[str, None] = None,
19            key: typing.Union[str, None] = None,
20            json_options: typing.Union[typing.Dict[str, typing.Any], None] = None,
21            extra: typing.Union[typing.Dict[str, typing.Any], None] = None,
22            **kwargs: typing.Any) -> None:
23        if (base_dir is None):
24            base_dir = '.'
25
26        self.base_dir: str = base_dir
27        """
28        The base directory for any relative paths this object needs to resolve.
29        Defaults to '.'.
30        """
31
32        self.source_path: typing.Union[str, None] = source_path
33        """ If we are reading from a file, this attribute should be the absolute path to that file. """
34
35        self.key: typing.Union[str, None] = key
36        """
37        An key to use during (de)serialization.
38        For example, this may be an encryption key.
39        """
40
41        if (json_options is None):
42            json_options = {}
43
44        self.json_options: typing.Dict[str, typing.Any] = json_options
45        """ Options to pass to JSON functions. """
46
47        if (extra is None):
48            extra = {}
49        else:
50            extra = extra.copy()
51
52        extra.update(kwargs)
53
54        self.extra: typing.Dict[str, typing.Any] = extra
55        """
56        Additional data to pass along the serialization process.
57        This is where users can pass additional data.
58        """
59
60    def copy(self) -> 'SerializationContext':
61        """ Make a deep copy of this context. """
62
63        return copy.deepcopy(self)
class SerializationContext:
11class SerializationContext:
12    """
13    Context information (context and options) to aid the serialization process.
14    An instance of this class will be passed around the core serialization functions to provide context and extra options.
15    """
16
17    def __init__(self,
18            base_dir: typing.Union[str, None] = None,
19            source_path: typing.Union[str, None] = None,
20            key: typing.Union[str, None] = None,
21            json_options: typing.Union[typing.Dict[str, typing.Any], None] = None,
22            extra: typing.Union[typing.Dict[str, typing.Any], None] = None,
23            **kwargs: typing.Any) -> None:
24        if (base_dir is None):
25            base_dir = '.'
26
27        self.base_dir: str = base_dir
28        """
29        The base directory for any relative paths this object needs to resolve.
30        Defaults to '.'.
31        """
32
33        self.source_path: typing.Union[str, None] = source_path
34        """ If we are reading from a file, this attribute should be the absolute path to that file. """
35
36        self.key: typing.Union[str, None] = key
37        """
38        An key to use during (de)serialization.
39        For example, this may be an encryption key.
40        """
41
42        if (json_options is None):
43            json_options = {}
44
45        self.json_options: typing.Dict[str, typing.Any] = json_options
46        """ Options to pass to JSON functions. """
47
48        if (extra is None):
49            extra = {}
50        else:
51            extra = extra.copy()
52
53        extra.update(kwargs)
54
55        self.extra: typing.Dict[str, typing.Any] = extra
56        """
57        Additional data to pass along the serialization process.
58        This is where users can pass additional data.
59        """
60
61    def copy(self) -> 'SerializationContext':
62        """ Make a deep copy of this context. """
63
64        return copy.deepcopy(self)

Context information (context and options) to aid the serialization process. An instance of this class will be passed around the core serialization functions to provide context and extra options.

SerializationContext( base_dir: Optional[str] = None, source_path: Optional[str] = None, key: Optional[str] = None, json_options: Optional[Dict[str, Any]] = None, extra: Optional[Dict[str, Any]] = None, **kwargs: Any)
17    def __init__(self,
18            base_dir: typing.Union[str, None] = None,
19            source_path: typing.Union[str, None] = None,
20            key: typing.Union[str, None] = None,
21            json_options: typing.Union[typing.Dict[str, typing.Any], None] = None,
22            extra: typing.Union[typing.Dict[str, typing.Any], None] = None,
23            **kwargs: typing.Any) -> None:
24        if (base_dir is None):
25            base_dir = '.'
26
27        self.base_dir: str = base_dir
28        """
29        The base directory for any relative paths this object needs to resolve.
30        Defaults to '.'.
31        """
32
33        self.source_path: typing.Union[str, None] = source_path
34        """ If we are reading from a file, this attribute should be the absolute path to that file. """
35
36        self.key: typing.Union[str, None] = key
37        """
38        An key to use during (de)serialization.
39        For example, this may be an encryption key.
40        """
41
42        if (json_options is None):
43            json_options = {}
44
45        self.json_options: typing.Dict[str, typing.Any] = json_options
46        """ Options to pass to JSON functions. """
47
48        if (extra is None):
49            extra = {}
50        else:
51            extra = extra.copy()
52
53        extra.update(kwargs)
54
55        self.extra: typing.Dict[str, typing.Any] = extra
56        """
57        Additional data to pass along the serialization process.
58        This is where users can pass additional data.
59        """
base_dir: str

The base directory for any relative paths this object needs to resolve. Defaults to '.'.

source_path: Optional[str]

If we are reading from a file, this attribute should be the absolute path to that file.

key: Optional[str]

An key to use during (de)serialization. For example, this may be an encryption key.

json_options: Dict[str, Any]

Options to pass to JSON functions.

extra: Dict[str, Any]

Additional data to pass along the serialization process. This is where users can pass additional data.

def copy(self) -> SerializationContext:
61    def copy(self) -> 'SerializationContext':
62        """ Make a deep copy of this context. """
63
64        return copy.deepcopy(self)

Make a deep copy of this context.