forked from google/gdata-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.py
More file actions
110 lines (88 loc) · 4.64 KB
/
service.py
File metadata and controls
110 lines (88 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: utf-8 -*-
#
# Copyright (c) 2007 Benoit Chesneau <benoitc@metavers.net>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""CodesearchService extends GDataService to streamline Google Codesearch
operations"""
__author__ = 'Benoit Chesneau'
import atom
import gdata.service
import gdata.codesearch
class CodesearchService(gdata.service.GDataService):
"""Client extension for Google codesearch service"""
ssl = True
def __init__(self, email=None, password=None, source=None,
server='www.google.com', additional_headers=None, **kwargs):
"""Creates a client for the Google codesearch service.
Args:
email: string (optional) The user's email address, used for
authentication.
password: string (optional) The user's password.
source: string (optional) The name of the user's application.
server: string (optional) The name of the server to which a connection
will be opened. Default value: 'www.google.com'.
**kwargs: The other parameters to pass to gdata.service.GDataService
constructor.
"""
gdata.service.GDataService.__init__(
self, email=email, password=password, service='codesearch',
source=source, server=server, additional_headers=additional_headers,
**kwargs)
def Query(self, uri, converter=gdata.codesearch.CodesearchFeedFromString):
"""Queries the Codesearch feed and returns the resulting feed of
entries.
Args:
uri: string The full URI to be queried. This can contain query
parameters, a hostname, or simply the relative path to a Document
List feed. The DocumentQuery object is useful when constructing
query parameters.
converter: func (optional) A function which will be executed on the
retrieved item, generally to render it into a Python object.
By default the CodesearchFeedFromString function is used to
return a CodesearchFeed object. This is because most feed
queries will result in a feed and not a single entry.
Returns :
A CodesearchFeed objects representing the feed returned by the server
"""
return self.Get(uri, converter=converter)
def GetSnippetsFeed(self, text_query=None):
"""Retrieve Codesearch feed for a keyword
Args:
text_query : string (optional) The contents of the q query parameter. This
string is URL escaped upon conversion to a URI.
Returns:
A CodesearchFeed objects representing the feed returned by the server
"""
query=gdata.codesearch.service.CodesearchQuery(text_query=text_query)
feed = self.Query(query.ToUri())
return feed
class CodesearchQuery(gdata.service.Query):
"""Object used to construct the query to the Google Codesearch feed. here only as a shorcut"""
def __init__(self, feed='/codesearch/feeds/search', text_query=None,
params=None, categories=None):
"""Constructor for Codesearch Query.
Args:
feed: string (optional) The path for the feed. (e.g. '/codesearch/feeds/search')
text_query: string (optional) The contents of the q query parameter. This
string is URL escaped upon conversion to a URI.
params: dict (optional) Parameter value string pairs which become URL
params when translated to a URI. These parameters are added to
the query's items.
categories: list (optional) List of category strings which should be
included as query categories. See gdata.service.Query for
additional documentation.
Yelds:
A CodesearchQuery object to construct a URI based on Codesearch feed
"""
gdata.service.Query.__init__(self, feed, text_query, params, categories)