From: Sergey Matveev Date: Fri, 15 Nov 2024 13:05:23 +0000 (+0300) Subject: set encoding support X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3d3473b543d6199a31ed5eaacdf335f4f7c67ddb0fb3358d1f48145b21014c24;p=keks.git set encoding support --- diff --git a/pyac/pyac.py b/pyac/pyac.py old mode 100644 new mode 100755 index da93f15..d0789a7 --- a/pyac/pyac.py +++ b/pyac/pyac.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # pyac -- Python YAC implementation # Copyright (C) 2024 Sergey Matveev # @@ -201,6 +202,10 @@ def dumps(v): return b"".join(raws) if isinstance(v, (list, tuple)): return b"".join([_byte(TagList)] + [dumps(i) for i in v] + [_byte(TagEOC)]) + if isinstance(v, set): + if not all(isinstance(i, str) for i in v): + raise ValueError("set can contain only strings") + return dumps({i: None for i in v}) if isinstance(v, dict): raws = [_byte(TagMap)] for k in sorted(v.keys(), key=LenFirstSort):