Add support for newer keys to GraphicsCommand serializer

This commit is contained in:
Kovid Goyal 2021-01-29 14:16:19 +05:30
parent b21850dd15
commit ad4665e638
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 3 deletions

View File

@ -131,6 +131,7 @@ SentImageKey = Tuple[int, int, int]
class GraphicsCommand:
a: GRT_a = 't' # action
q: int = 0 # suppress responses
f: GRT_f = 32 # image data format
t: GRT_t = 'd' # transmission medium
s: int = 0 # sent image width
@ -138,6 +139,7 @@ class GraphicsCommand:
S: int = 0 # size of data to read from file
O: int = 0 # offset of data to read from file
i: int = 0 # image id
I: int = 0 # image number
p: int = 0 # placement id
o: Optional[GRT_o] = None # type of compression
m: GRT_m = 0 # 0 or 1 whether there is more chunked data
@ -152,7 +154,7 @@ class GraphicsCommand:
z: int = 0 # z-index
d: GRT_d = 'a' # what to delete
def serialize(self, payload: bytes = b'') -> bytes:
def serialize(self, payload: Union[bytes, str] = b'') -> bytes:
items = []
for k in GraphicsCommand.__annotations__:
val: Union[str, None, int] = getattr(self, k)
@ -166,6 +168,8 @@ class GraphicsCommand:
w(','.join(items).encode('ascii'))
if payload:
w(b';')
if isinstance(payload, str):
payload = standard_b64encode(payload.encode('utf-8'))
w(payload)
w(b'\033\\')
return b''.join(ans)

View File

@ -41,12 +41,12 @@ from .window import Window as WindowType
EdgeLiteral = Literal['left', 'top', 'right', 'bottom']
MatchType = Literal['mime', 'ext', 'protocol', 'file', 'path', 'url', 'fragment_matches']
GRT_a = Literal['t', 'T', 'q', 'p', 'd']
GRT_a = Literal['t', 'T', 'q', 'p', 'd', 'f', 'a']
GRT_f = Literal[24, 32, 100]
GRT_t = Literal['d', 'f', 't', 's']
GRT_o = Literal['z']
GRT_m = Literal[0, 1]
GRT_d = Literal['a', 'A', 'c', 'C', 'i', 'I', 'p', 'P', 'q', 'Q', 'x', 'X', 'y', 'Y', 'z', 'Z']
GRT_d = Literal['a', 'A', 'c', 'C', 'i', 'I', 'p', 'P', 'q', 'Q', 'x', 'X', 'y', 'Y', 'z', 'Z', 'f', 'F']
__all__ = (
'EdgeLiteral', 'MatchType', 'GRT_a', 'GRT_f', 'GRT_t', 'GRT_o', 'GRT_m', 'GRT_d',
'GraphicsCommandType', 'HandlerType', 'AbstractEventLoop', 'AddressFamily', 'Socket', 'CompletedProcess',