
     #e                        d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZ d dlmZ d dlmZmZ dZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 dd	Zdd
Zy)    )annotations)partialmethod)import_module)IOAnyAnyStrCallableType)ExtrasNotInstalledError)PathLikeT)jsonmsgpackc                    ||| fi |S N )clss
__callbackkwargss       8/usr/lib/python3/dist-packages/ufoLib2/serde/__init__.py_loadsr      s     a'''    c                    ||| fi |S r   r   )r   fpr   r   s       r   _loadr      s     b#(((r   c           
     @   g }t         D ]  }	 t        d|       }t        | | dt        t	        t
              |j                               t        | | dt        t	        t              |j                               t        | | d|j                         t        | | d|j                         |j                  |        t        | d
t        |             | S # t        $ r6}t        |      }||_        dD ]  }t        | | d| |        Y d	}~d	}~ww xY w)ah  Decorator to add serialization support to a ufoLib2 class.

    This adds f"{format}_loads" / f"{format}_dumps" (from/to bytes) methods, and
    f"{format}_load" / f"{format}_dump" (for file or path) methods to all ufoLib2
    objects, not just Font.

    Currently the supported formats are JSON and MessagePack (msgpack), but other
    formats may be added in the future.

    E.g.::

        from ufoLib2 import Font

        font = Font.open("MyFont.ufo")
        font.json_dump("MyFont.json")
        font2 = Font.json_load("MyFont.json")
        font3 = Font.json_loads(font2.json_dumps())

        font3.msgpack_dump("MyFont.msgpack")
        font4 = Font.msgpack_load("MyFont.msgpack")
        # etc.

    Note this requires additional extras to be installed: e.g. ufoLib2[json,msgpack].
    In additions to the respective serialization library, these installs the `cattrs`
    library for structuring/unstructuring custom objects from/to serializable data
    structures (also available separately as ufoLib2[converters] extra).

    If any of the optional dependencies fails to be imported, the methods will raise
    an ImportError when called.

    If the faster `orjson` library is present, it will be used in place of the
    built-in `json` library on CPython. On PyPy, the `orjson` library is not available,
    so the built-in `json` library will be used (though it's pretty fast anyway).

    If you want a serialization format that works out of the box with all ufoLib2
    objects (but it's mostly limited to Python) you can use the built-in pickle module,
    which doesn't require to use the `cattrs` converters.

    zufoLib2.serde.r   )r   r   _dumps_dump)loadsloaddumpsdump_N_SERDE_FORMATS_)r%   r   setattrr   classmethodr   r    r   r!   r"   r#   appendImportErrorr   	__cause__tuple)r   supported_formatsfmtserde_submoduleexcraise_errormethods          r   serder2   !   s*   R  *	*+nSE,BCO %vk&1o>S>ST
 %uk%0_=Q=QR
 CC5)>)>?CC5(<(<=$$S)-*0 C"E*;$<=J-  	=1#6K$'K!< =uAfX.<=	=s   C	D'+DDN)
r   Type[T]r   zstr | bytesr   Callable[..., T]r   r   returnr   )
r   r3   r   zPathLike | IO[AnyStr]r   r4   r   r   r5   r   )r   r3   r5   r3   )
__future__r   	functoolsr   	importlibr   typingr   r   r   r	   r
   ufoLib2.errorsr   ufoLib2.typingr   r   r%   r   r   r2   r   r   r   <module>r<      s    " # # 2 2 2 &%(	( (1A(MP(()	)) !	)
 ) )Dr   