Files
Home-AssistantConfig/deps/sqlalchemy/dialects/postgresql/__pycache__/json.cpython-34.pyc

208 lines
13 KiB
Plaintext
Raw Normal View History

2016-10-11 16:42:06 +00:00
<EFBFBD>
}<7D><>W<EFBFBD>/<00>@s<>ddlmZddlZddlmZddlmZddlm Z ddlm
Z
dd l
m Z m Z dd
lm Z dZGdd <00>d e j<00>ZGdd <00>d ej<00>Zeed<Gdd <00>d e<00>Zeed<dS)<14>)<01>absolute_importN<74>)<01> ischema_names<65>)<01>types)<01> custom_op)<01>sql)<02>elements<74>default_comparator)<01>util<69>JSON<4F> JSONElement<6E>JSONBcsOeZdZdZddd<00>fdd<00>Zedd<00><00>Zdd <00>Z<00>S)
r a<>Represents accessing an element of a :class:`.JSON` value.
The :class:`.JSONElement` is produced whenever using the Python index
operator on an expression that has the type :class:`.JSON`::
expr = mytable.c.json_data['some_key']
The expression typically compiles to a JSON access such as ``col -> key``.
Modifiers are then available for typing behavior, including
:meth:`.JSONElement.cast` and :attr:`.JSONElement.astext`.
FNcs<>||_|dkrit|d<00>r`t|tj<00> r`d}ddjdd<00>|D<><00>}qid}n||_t|dd <00>}tj |||<00>}t
t |<00>j |||d
|<00>dS) N<>__iter__z#>z{%s}z, css|]}tj|<00>VqdS)N)r <00> text_type)<02>.0<EFBFBD>elem<65>r<00>I/tmp/pip-build-zkr322cu/sqlalchemy/sqlalchemy/dialects/postgresql/json.py<70> <genexpr>+sz'JSONElement.__init__.<locals>.<genexpr>z-><3E>
precedence<EFBFBD><00>type_) <0A>_astext<78>hasattr<74>
isinstancer <00> string_types<65>join<69>_json_opstringrr
Z_check_literal<61>superr <00>__init__)<07>self<6C>left<66>right<68>astext<78>opstring<6E> result_type<70>operator)<01> __class__rrr #s     zJSONElement.__init__c CsI|jr |St|j|jddd|jddtjdd<00><01>SdS)z<>Convert this :class:`.JSONElement` to use the 'astext' operator
when evaluated.
E.g.::
select([data_table.c.data['some key'].astext])
.. seealso::
:meth:`.JSONElement.cast`
r$Tr%<00>>r&Zconvert_unicodeN)rr r"r#r<00>sqltypes<65>String)r!rrrr$6s   zJSONElement.astextcCs-|js|jj|<00>Stj||<00>SdS)aConvert this :class:`.JSONElement` to apply both the 'astext' operator
as well as an explicit type cast when evaluated.
E.g.::
select([data_table.c.data['some key'].cast(Integer)])
.. seealso::
:attr:`.JSONElement.astext`
N)rr$<00>castr)r!rrrrr,Os zJSONElement.cast)<08>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__r <00>propertyr$r,rr)r(rr s
c@s_eZdZdZdZddd<00>ZGdd<00>dejj<00>Z dd<00>Z
d d
<00>Z d S) r a<> Represent the Postgresql JSON type.
The :class:`.JSON` type stores arbitrary JSON format data, e.g.::
data_table = Table('data_table', metadata,
Column('id', Integer, primary_key=True),
Column('data', JSON)
)
with engine.connect() as conn:
conn.execute(
data_table.insert(),
data = {"key1": "value1", "key2": "value2"}
)
:class:`.JSON` provides several operations:
* Index operations::
data_table.c.data['some key']
* Index operations returning text (required for text comparison)::
data_table.c.data['some key'].astext == 'some value'
* Index operations with a built-in CAST call::
data_table.c.data['some key'].cast(Integer) == 5
* Path index operations::
data_table.c.data[('key_1', 'key_2', ..., 'key_n')]
* Path index operations returning text (required for text comparison)::
data_table.c.data[('key_1', 'key_2', ..., 'key_n')].astext == \
'some value'
Index operations return an instance of :class:`.JSONElement`, which
represents an expression such as ``column -> index``. This element then
defines methods such as :attr:`.JSONElement.astext` and
:meth:`.JSONElement.cast` for setting up type behavior.
The :class:`.JSON` type, when used with the SQLAlchemy ORM, does not
detect in-place mutations to the structure. In order to detect these, the
:mod:`sqlalchemy.ext.mutable` extension must be used. This extension will
allow "in-place" changes to the datastructure to produce events which
will be detected by the unit of work. See the example at :class:`.HSTORE`
for a simple example involving a dictionary.
Custom serializers and deserializers are specified at the dialect level,
that is using :func:`.create_engine`. The reason for this is that when
using psycopg2, the DBAPI only allows serializers at the per-cursor
or per-connection level. E.g.::
engine = create_engine("postgresql://scott:tiger@localhost/test",
json_serializer=my_serialize_fn,
json_deserializer=my_deserialize_fn
)
When using the psycopg2 dialect, the json_deserializer is registered
against the database using ``psycopg2.extras.register_default_json``.
.. versionadded:: 0.9
FcCs ||_dS)aConstruct a :class:`.JSON` type.
:param none_as_null: if True, persist the value ``None`` as a
SQL NULL value, not the JSON encoding of ``null``. Note that
when this flag is False, the :func:`.null` construct can still
be used to persist a NULL value::
from sqlalchemy import null
conn.execute(table.insert(), data=null())
.. versionchanged:: 0.9.8 - Added ``none_as_null``, and :func:`.null`
is now supported in order to persist a NULL value.
N)<01> none_as_null)r!r2rrrr <00>sz JSON.__init__c@s.eZdZdZdd<00>Zdd<00>ZdS)zJSON.comparator_factoryz0Define comparison operations for :class:`.JSON`.cCst|j|<00>S)zGet the value at a given key.)r <00>expr)r!<00>otherrrr<00> __getitem__<5F>sz#JSON.comparator_factory.__getitem__cCsGt|t<00>r.|jdkr.|tjfSntjjj|||<00>S)Nz->)rrr%r*<00>Text<78> Concatenable<6C>
Comparator<EFBFBD>_adapt_expression)r!<00>op<6F>other_comparatorrrrr9<00>sz)JSON.comparator_factory._adapt_expressionN)r-r.r/r0r5r9rrrr<00>comparator_factory<72>s  r<csX|jptj<00>tjr?|j<00><00><00><00>fdd<00>}n<00><00>fdd<00>}|S)Ncs>t|tj<00>s'|dkr+<00>jr+dS<>|<00>j<00><00>S)N)rr <00>Nullr2<00>encode)<01>value)<03>encoding<6E>json_serializerr!rr<00>process<73>sz$JSON.bind_processor.<locals>.processcs5t|tj<00>s'|dkr+<00>jr+dS<>|<00>S)N)rr r=r2)r?)rAr!rrrB<00>s)Z_json_serializer<65>json<6F>dumpsr <00>py2kr@)r!<00>dialectrBr)r@rAr!r<00>bind_processor<6F>s   zJSON.bind_processorcsR|jptj<00>tjr<|j<00><00><00>fdd<00>}n<00>fdd<00>}|S)Ncs#|dkrdS<>|j<00><00><00>S)N)<01>decode)r?)r@<00>json_deserializerrrrB<00>s z&JSON.result_processor.<locals>.processcs|dkrdS<>|<00>S)Nr)r?)rIrrrB<00>s )Z_json_deserializerrC<00>loadsr rEr@)r!rFZcoltyperBr)r@rIr<00>result_processor<6F>s   zJSON.result_processorN) r-r.r/r0<00>__visit_name__r r*r7r8r<rGrKrrrrr bs B rCc@s>eZdZdZdZdZGdd<00>dejj<00>Z dS)ra<> Represent the Postgresql JSONB type.
The :class:`.JSONB` type stores arbitrary JSONB format data, e.g.::
data_table = Table('data_table', metadata,
Column('id', Integer, primary_key=True),
Column('data', JSONB)
)
with engine.connect() as conn:
conn.execute(
data_table.insert(),
data = {"key1": "value1", "key2": "value2"}
)
:class:`.JSONB` provides several operations:
* Index operations::
data_table.c.data['some key']
* Index operations returning text (required for text comparison)::
data_table.c.data['some key'].astext == 'some value'
* Index operations with a built-in CAST call::
data_table.c.data['some key'].cast(Integer) == 5
* Path index operations::
data_table.c.data[('key_1', 'key_2', ..., 'key_n')]
* Path index operations returning text (required for text comparison)::
data_table.c.data[('key_1', 'key_2', ..., 'key_n')].astext == \
'some value'
Index operations return an instance of :class:`.JSONElement`, which
represents an expression such as ``column -> index``. This element then
defines methods such as :attr:`.JSONElement.astext` and
:meth:`.JSONElement.cast` for setting up type behavior.
The :class:`.JSON` type, when used with the SQLAlchemy ORM, does not
detect in-place mutations to the structure. In order to detect these, the
:mod:`sqlalchemy.ext.mutable` extension must be used. This extension will
allow "in-place" changes to the datastructure to produce events which
will be detected by the unit of work. See the example at :class:`.HSTORE`
for a simple example involving a dictionary.
Custom serializers and deserializers are specified at the dialect level,
that is using :func:`.create_engine`. The reason for this is that when
using psycopg2, the DBAPI only allows serializers at the per-cursor
or per-connection level. E.g.::
engine = create_engine("postgresql://scott:tiger@localhost/test",
json_serializer=my_serialize_fn,
json_deserializer=my_deserialize_fn
)
When using the psycopg2 dialect, the json_deserializer is registered
against the database using ``psycopg2.extras.register_default_json``.
.. versionadded:: 0.9.7
Fc@sjeZdZdZdd<00>Zdd<00>Zdd<00>Zdd <00>Zd
d <00>Zd d <00>Z dd<00>Z
dS)zJSONB.comparator_factoryz0Define comparison operations for :class:`.JSON`.cCst|j|<00>S)zGet the value at a given key.)r r3)r!r4rrrr5:sz$JSONB.comparator_factory.__getitem__cCsct|t<00>rJ|jdkr+|tjfS|jdkrJ|tjfSntjjj|||<00>S)N<>?<3F>?&<26>?|<7C>@><3E><@z->)rMrNrOrPrQ) rrr%r*<00>Booleanr6r7r8r9)r!r:r;rrrr9?s  z*JSONB.comparator_factory._adapt_expressioncCs|jjd<00>|<00>S)zvBoolean expression. Test for presence of a key. Note that the
key may be a SQLA expression.
rM)r3r:)r!r4rrr<00>has_keyJsz JSONB.comparator_factory.has_keycCs|jjd<00>|<00>S)zHBoolean expression. Test for presence of all keys in jsonb
z?&)r3r:)r!r4rrr<00>has_allPsz JSONB.comparator_factory.has_allcCs|jjd<00>|<00>S)zGBoolean expression. Test for presence of any key in jsonb
z?|)r3r:)r!r4rrr<00>has_anyUsz JSONB.comparator_factory.has_anycKs|jjd<00>|<00>S)z<>Boolean expression. Test if keys (or array) are a superset of/contained
the keys of the argument jsonb expression.
z@>)r3r:)r!r4<00>kwargsrrr<00>containsZsz!JSONB.comparator_factory.containscCs|jjd<00>|<00>S)z|Boolean expression. Test if keys are a proper subset of the
keys of the argument jsonb expression.
z<@)r3r:)r!r4rrr<00> contained_by`sz%JSONB.comparator_factory.contained_byN) r-r.r/r0r5r9rSrTrUrWrXrrrrr<7s      r<N)
r-r.r/r0rLZhashabler*r7r8r<rrrrr<00>s BZjsonb)zJSONz JSONElementzJSONB)<14>
__future__rrC<00>baser<00>rr*Z sql.operatorsrrr r
r <00>__all__ZBinaryExpressionr Z
TypeEnginer rrrrr<00><module>s M<19>
v