1""" 2Integration for attrs/cattrs 3""" 4 5fromtypingimportAbstractSet 6 7importattrs 8fromcattrs.convertersimportConverter 910try:11# ujson is preferred, since muffin&c can also use it12fromcattrs.preconf.ujsonimportconfigure_converter13exceptImportError:14fromcattrs.preconf.jsonimportconfigure_converter15# Omitting orjson, even though it's a preconf, because I'm not confident it's a16# drop-in equivalent to (u)json1718from.importDocumentRegistry192021# All implementations exhibit the conversions:22# * bytes are wrapped in base8523# * dates & datetimes are ISO 860124#: The converter used when talking to CouchDB.25converter=Converter(26unstruct_collection_overrides={27AbstractSet:list,28}29)30configure_converter(converter)3132
[docs]34@classmethod35defdocument(cls,name:str,/,**flags):36"""37 Registers a class as a document of the given type.3839 Passes it through :func:`attrs.define`40 """41func=super().document(name)4243def_(klass:type):44# Disable slots so chaise can attach extra data45klass=attrs.mutable(klass,slots=False,**flags)46returnfunc(klass)4748return_