Repository URL to install this package:
|
Version:
2.1.0.jo1 ▾
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gdata.core</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="gdata.html"><font color="#ffffff">gdata</font></a>.core</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/afshar/src/external-gdata-release/google3/src/gdata/core.py">/usr/local/google/home/afshar/src/external-gdata-release/google3/src/gdata/core.py</a></font></td></tr></table>
<p><tt># Copyright (C) 2010 Google Inc.<br>
#<br>
# Licensed under the Apache License, Version 2.0 (the "License");<br>
# you may not use this file except in compliance with the License.<br>
# You may obtain a copy of the License at<br>
#<br>
# <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a><br>
#<br>
# Unless required by applicable law or agreed to in writing, software<br>
# distributed under the License is distributed on an "AS IS" BASIS,<br>
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br>
# See the License for the specific language governing permissions and<br>
# limitations under the License.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="simplejson.html">simplejson</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="gdata.core.html#Jsonc">Jsonc</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Jsonc">class <strong>Jsonc</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Represents JSON-C data in an easy to access <a href="__builtin__.html#object">object</a> format.<br>
<br>
To access the members of a JSON structure which looks like this:<br>
{<br>
"data": {<br>
"totalItems": 800,<br>
"items": [<br>
{<br>
"content": {<br>
"1": "rtsp://v5.cache3.c.youtube.com/CiILENy.../0/0/0/video.3gp"<br>
},<br>
"viewCount": 220101,<br>
"commentCount": 22,<br>
"favoriteCount": 201<br>
}<br>
]<br>
},<br>
"apiVersion": "2.0"<br>
}<br>
<br>
You would do the following:<br>
x = gdata.core.<a href="#-parse_json">parse_json</a>(the_above_string)<br>
# Gives you 800<br>
x.data.total_items<br>
# Should be 22<br>
x.data.items[0].comment_count<br>
# The apiVersion is '2.0'<br>
x.api_version<br>
<br>
To create a <a href="#Jsonc">Jsonc</a> <a href="__builtin__.html#object">object</a> which would produce the above JSON, you would do:<br>
gdata.core.<a href="#Jsonc">Jsonc</a>(<br>
api_version='2.0',<br>
data=gdata.core.<a href="#Jsonc">Jsonc</a>(<br>
total_items=800,<br>
items=[<br>
gdata.core.<a href="#Jsonc">Jsonc</a>(<br>
view_count=220101,<br>
comment_count=22,<br>
favorite_count=201,<br>
content={<br>
'1': ('rtsp://v5.cache3.c.youtube.com'<br>
'/CiILENy.../0/0/0/video.3gp')})]))<br>
or<br>
x = gdata.core.<a href="#Jsonc">Jsonc</a>()<br>
x.api_version = '2.0'<br>
x.data = gdata.core.<a href="#Jsonc">Jsonc</a>()<br>
x.data.total_items = 800<br>
x.data.items = []<br>
# etc.<br>
<br>
How it works:<br>
The JSON-C data is stored in an internal dictionary (._dict) and the<br>
getattr, setattr, and delattr methods rewrite the name which you provide<br>
to mirror the expected format in JSON-C. (For more details on name<br>
conversion see _to_jsonc_name.) You may also access members using<br>
getitem, setitem, delitem as you would for a dictionary. For example<br>
x.data.total_items is equivalent to x['data']['totalItems']<br>
(Not all dict methods are supported so if you need something other than<br>
the item operations, then you will want to use the ._dict member).<br>
<br>
You may need to use getitem or the _dict member to access certain<br>
properties in cases where the JSON-C syntax does not map neatly to Python<br>
objects. For example the YouTube Video feed has some JSON like this:<br>
"content": {"1": "rtsp://v5.cache3.c.youtube.com..."...}<br>
You cannot do x.content.1 in Python, so you would use the getitem as<br>
follows:<br>
x.content['1']<br>
or you could use the _dict member as follows:<br>
x.content._dict['1']<br>
<br>
If you need to create a new <a href="__builtin__.html#object">object</a> with such a mapping you could use.<br>
<br>
x.content = gdata.core.<a href="#Jsonc">Jsonc</a>(_dict={'1': 'rtsp://cache3.c.youtube.com...'})<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Jsonc-__delattr__"><strong>__delattr__</strong></a>(self, name)</dt></dl>
<dl><dt><a name="Jsonc-__delitem__"><strong>__delitem__</strong></a>(self, key)</dt></dl>
<dl><dt><a name="Jsonc-__getattr__"><strong>__getattr__</strong></a>(self, name)</dt></dl>
<dl><dt><a name="Jsonc-__getitem__"><strong>__getitem__</strong></a>(self, key)</dt><dd><tt># For container methods pass-through to the underlying dict.</tt></dd></dl>
<dl><dt><a name="Jsonc-__init__"><strong>__init__</strong></a>(self, _dict<font color="#909090">=None</font>, **kwargs)</dt></dl>
<dl><dt><a name="Jsonc-__setattr__"><strong>__setattr__</strong></a>(self, name, value)</dt></dl>
<dl><dt><a name="Jsonc-__setitem__"><strong>__setitem__</strong></a>(self, key, value)</dt></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-jsonc_to_string"><strong>jsonc_to_string</strong></a>(jsonc_obj)</dt><dd><tt>Converts a <a href="#Jsonc">Jsonc</a> <a href="__builtin__.html#object">object</a> into a string of JSON-C.</tt></dd></dl>
<dl><dt><a name="-parse_json"><strong>parse_json</strong></a>(json_string)</dt><dd><tt>Converts a JSON-C string into a <a href="#Jsonc">Jsonc</a> <a href="__builtin__.html#object">object</a>.<br>
<br>
Args:<br>
json_string: str or unicode The JSON to be parsed.<br>
<br>
Returns:<br>
A new <a href="#Jsonc">Jsonc</a> <a href="__builtin__.html#object">object</a>.</tt></dd></dl>
<dl><dt><a name="-parse_json_file"><strong>parse_json_file</strong></a>(json_file)</dt></dl>
<dl><dt><a name="-prettify_jsonc"><strong>prettify_jsonc</strong></a>(jsonc_obj, indentation<font color="#909090">=2</font>)</dt><dd><tt>Converts a <a href="#Jsonc">Jsonc</a> <a href="__builtin__.html#object">object</a> to a pretified (intented) JSON string.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>__author__</strong> = 'j.s@google.com (Jeff Scudder)'</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
<tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td>
<td width="100%">j.s@google.com (Jeff Scudder)</td></tr></table>
</body></html>