Issues (43)

starstruct/elementnone.py (1 issue)

1
"""
2
Element None
3
4
A non-packable, non-unpackable item that can help facilitate with additional information about an object,
5
pass extra references to a variable and potentially more
6
7
.. code-block:: python
8
9
    ExampleMessage = Message('VarTest', [('x', 'B'), ('y', 'B')])
10
11
    CRCedMessage = Message('CRCedMessage', [
12
       ('data', ExampleMessage),                  # A data field that has the example message in it
13
       ('extra_param', None),                     # The None Element
14
       ('crc', 'I', my_crc32, ['data', 'extra_param']),          # Crc the data, and give an error if we have something unexpected
15
   ])
16
17
"""
18
19 1
from typing import Optional
0 ignored issues
show
The import typing could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
20
21 1
from starstruct.element import register, Element
22 1
from starstruct.modes import Mode
23
24
25 1
@register
26 1
class ElementNone(Element):
27
    """
28
    Initialize a StarStruct element object.
29
30
    :param field: The fields passed into the constructor of the element
31
    :param mode: The mode in which to pack the bytes
32
    :param alignment: Number of bytes to align to
33
    """
34 1
    def __init__(self, field: list, mode: Optional[Mode]=Mode.Native, alignment: Optional[int]=1):
35 1
        self.name = field[0]
36
37 1
        self.update(mode=mode, alignment=alignment)
38
39 1
    @staticmethod
40 1
    def valid(field: tuple) -> bool:
41 1
        return len(field) == 2 \
42
            and isinstance(field[0], str) \
43
            and field[1] is None
44
45 1
    def validate(self, msg):
46 1
        return True
47
48 1
    def update(self, mode=None, alignment=None):
49 1
        if mode:
50 1
            self._mode = mode
51
52 1
        if alignment:
53 1
            self._alignment = alignment
54 1
        return
55
56 1
    def pack(self, msg):
57 1
        return b''
58
59 1
    def unpack(self, msg, buf):
60 1
        return (None, buf)
61
62 1
    def make(self, msg):
63
        return msg[self.name]
64