adds the NULL string terminator
(val)
| 39 | |
| 40 | |
| 41 | def make_field(val) -> str: |
| 42 | """adds the NULL string terminator""" |
| 43 | if val is None: |
| 44 | raise ValueError("Cannot send None to TWS") |
| 45 | |
| 46 | # if string is not empty and contains invalid symbols |
| 47 | if val is not None and type(val) == str and val and not isAsciiPrintable(val): |
| 48 | raise ClientException( |
| 49 | INVALID_SYMBOL.code(), |
| 50 | INVALID_SYMBOL.msg(), |
| 51 | val.encode(sys.stdout.encoding, errors="ignore").decode( |
| 52 | sys.stdout.encoding |
| 53 | ), |
| 54 | ) |
| 55 | |
| 56 | # bool type is encoded as int |
| 57 | if val is not None and type(val) == bool: |
| 58 | val = int(val) |
| 59 | |
| 60 | field = str(val) + "\0" |
| 61 | return field |
| 62 | |
| 63 | |
| 64 | def make_field_handle_empty(val) -> str: |
no test coverage detected