Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
serializer.cpython-313.pyc92 linesDownload Raw Back to __pycache__
1�

2��j���:�SrSSKJr SSKrSSKrSSKJr SSKJr SSKJ	r	 SSK3Jr SS	KJ
r
 SS4KJr SSKJr SSKJr SS
KJr /SQr"SS\R,5r\R0"S5r"SS\R45r\R84SjrSSjrg)akSerializer/Deserializer objects for usage with SQLAlchemy query structures,5allowing "contextual" deserialization.6 7.. legacy::8 9    The serializer extension is **legacy** and should not be used for10    new development.11 12Any SQLAlchemy query structure, either based on sqlalchemy.sql.*13or sqlalchemy.orm.* can be used.  The mappers, Tables, Columns, Session14etc. which are referenced by the structure are not persisted in serialized15form, but are instead re-associated with the query structure16when it is deserialized.17 18.. warning:: The serializer extension uses pickle to serialize and19   deserialize objects, so the same security consideration mentioned20   in the `python documentation21   <https://docs.python.org/3/library/pickle.html>`_ apply.22 23Usage is nearly the same as that of the standard Python pickle module::24 25    from sqlalchemy.ext.serializer import loads, dumps26 27    metadata = MetaData(bind=some_engine)28    Session = scoped_session(sessionmaker())29 30    # ... define mappers31 32    query = (33        Session.query(MyClass)34        .filter(MyClass.somedata == "foo")35        .order_by(MyClass.sortkey)36    )37 38    # pickle the query39    serialized = dumps(query)40 41    # unpickle.  Pass in metadata + scoped_session42    query2 = loads(serialized, metadata, Session)43 44    print(query2.all())45 46Similar restrictions as when using raw pickle apply; mapped classes must be47themselves be pickleable, meaning they are importable from a module-level48namespace.49 50The serializer module is only appropriate for query structures.  It is not51needed for:52 53* instances of user-defined classes.   These contain no references to engines,54  sessions or expression constructs in the typical case and can be serialized55  directly.56 57* Table metadata that is to be loaded entirely from the serialized structure58  (i.e. is not already declared in the application).   Regular59  pickle.loads()/dumps() can be used to fully dump any ``MetaData`` object,60  typically one which was reflected from an existing database at some previous61  point in time.  The serializer module is specifically for the opposite case,62  where the Table metadata is already present in memory.63 64�)�BytesION�)�Column)�Table)�Engine)�class_mapper)�MapperProperty)�Mapper)�Session)�	b64decode)�	b64encode)�65Serializer�Deserializer�dumps�loadsc��\rSrSrSrSrg)r�Yc��[U[5(a?UR(d.S[[R66"UR55-nU$[U[5(acURR(dHS[[R67"URR55-S-UR-nU$[U[5(a]SUR;a;S[[R68"URSR55-nU$SUR3nU$[U[5(aG[UR[5(a(SURRSUR3nU$[U[5(aSnU$[U[5(aS	nU$g)69Nzmapper:zmapperprop:�:�parententityzmapper_selectable:ztable:zcolumn:zsession:zengine:)�70isinstancer71�non_primaryr
�pickler�class_r	�parent�keyr�_annotationsr�tablerr)�self�obj�id_s   �_D:\code\apps\devtools\python\user_packages\Python313\site-packages\sqlalchemy/ext/serializer.py�
persistent_id�Serializer.persistent_id[s����c�6�"�"�3�?�?��i����S�Z�Z�(@�A�A�C�.�72�-��^�
,�
,�S�Z�Z�5K�5K���F�L�L����):�):�;�<�=����'�'��
�*�73���U�
#�
#���!1�!1�1�*�Y��L�L��!1�!1�.�!A�!H�!H�I�.����74��s�w�w�i�(���75���V�
$�
$��C�I�I�u�)E�)E��C�I�I�M�M�?�!�C�G�G�9�5�C��76�
��W�
%�
%��C�77�78�	��V�
$�
$��C��79���N)�__name__�80__module__�__qualname__�__firstlineno__r#�__static_attributes__r&r%r"rrYs��r%rzP(mapperprop|mapper|mapper_selectable|table|column|session|attribute|engine):(.*)c�8^�\rSrSrSU4SjjrSrSrSrU=r$)r�~c�H>�[TU]U5 X lX0lX@lg�N)�super�__init__�metadata�scoped_session�engine)r�filer2r3r4�	__class__s     �r"r1�Deserializer.__init__�s ���
����� �
�,���r%c���UR(aUR$UR(a9UR5R(aUR5R$gr/)r4r3�bind)rs r"�81get_engine�Deserializer.get_engine�sE���;�;��;�;��
�
 �
 �T�%8�%8�%:�%?�%?��&�&�(�-�-�-�r%c��[R[U55nU(dgURSS5up4US:Xa=UR	S5upV[82R"[U55n[Xu5$US:Xa*[83R"[U55n[U5$US:Xa8[84R"[U55n[U5R5$US:XaJUR	S5up�[85R"[U55n[U5RU	$US:XaURRU$US	:Xa9UR	S5up�URRU86RU$US87:XaUR5$US:XaUR!5$[#SU-5e)
N�r�	attributer�mapper�mapper_selectable�88mapperpropr�column�sessionr4zUnknown token: %s)�our_ids�match�str�group�splitrrr�getattrr�__clause_element__�attrsr2�tables�cr3r:�	Exception)rr!�m�type_�argsr�clsarg�clsr?�keynamer�colnames            r"�persistent_load�Deserializer.persistent_load�s����M�M�#�c�(�#�����'�'�!�Q�-�K�E���#�"�j�j��o����l�l�9�V�#4�5���s�(�(��(�"��l�l�9�T�?�3��#�C�(�(��-�-��l�l�9�T�?�3��#�C�(�;�;�=�=��,�&�"&�*�*�S�/����l�l�9�V�#4�5��#�C�(�.�.�w�7�7��'�!��}�}�+�+�D�1�1��(�"�!%���C�����}�}�+�+�E�2�4�4�W�=�=��)�#��*�*�,�,��(�"����(�(�� 3�e� ;�<�<r%)r4r2r3�NNN)	r'r(r)r*r1r:rVr+�
__classcell__)r6s@r"rr~s�����=�=r%rc�n�[5n[X!5nURU5 UR5$r/)rr�dump�getvalue)r �protocol�buf�picklers    r"rr�s+��89�)�C���'�G��L�L����<�<�>�r%c�P�[U5n[XAX#5nUR5$r/)rr�load)�datar2r3r4r^�	unpicklers      r"rr�s$��90�$�-�C��S�N�C�I��>�>��r%rX)�__doc__�iorr�re�rrr4r�ormr�orm.interfacesr	�91orm.mapperr92�orm.sessionr�utilrr
�__all__�Picklerr�compilerD�	Unpicklerr�HIGHEST_PROTOCOLrrr&r%r"�<module>rrs���<�|�
�	�����+��!���;�������>
�*�*�&���.=�6�#�#�.=�b�/�/��r%
codekingpro/portable-devtools · Team Ai