Skip to content

Commit eb34e8d

Browse files
author
NoWay
committed
Fixes.
1 parent fb7b2c1 commit eb34e8d

28 files changed

+21168
-57
lines changed

InteractionModel.json

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
}
3333
],
3434
"samples": [
35+
"di cercare {query}",
36+
"di cercare musica di {query}",
37+
"di cercare canzone di {query}",
38+
"di cercare canzoni di {query}",
39+
"di cercare le canzoni di {query}",
40+
"di cercare la canzoni di {query}",
3541
"di mettere {query}",
3642
"di mettere musica {query}",
3743
"di mettere musica di {query}",

__pycache__/six.cpython-36.pyc

24.5 KB
Binary file not shown.

get-pip.py

+20,890
Large diffs are not rendered by default.

googleapiclient/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "1.6.6"
15+
__version__ = "1.7.4"
1616

1717
# Set default logging handler to avoid "No handler found" warnings.
1818
import logging

googleapiclient/__init__.pyc

-780 Bytes
Binary file not shown.

googleapiclient/_auth.pyc

-4.27 KB
Binary file not shown.

googleapiclient/_helpers.py

+204
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Copyright 2015 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Helper functions for commonly used utilities."""
16+
17+
import functools
18+
import inspect
19+
import logging
20+
import warnings
21+
22+
import six
23+
from six.moves import urllib
24+
25+
26+
logger = logging.getLogger(__name__)
27+
28+
POSITIONAL_WARNING = 'WARNING'
29+
POSITIONAL_EXCEPTION = 'EXCEPTION'
30+
POSITIONAL_IGNORE = 'IGNORE'
31+
POSITIONAL_SET = frozenset([POSITIONAL_WARNING, POSITIONAL_EXCEPTION,
32+
POSITIONAL_IGNORE])
33+
34+
positional_parameters_enforcement = POSITIONAL_WARNING
35+
36+
_SYM_LINK_MESSAGE = 'File: {0}: Is a symbolic link.'
37+
_IS_DIR_MESSAGE = '{0}: Is a directory'
38+
_MISSING_FILE_MESSAGE = 'Cannot access {0}: No such file or directory'
39+
40+
41+
def positional(max_positional_args):
42+
"""A decorator to declare that only the first N arguments my be positional.
43+
44+
This decorator makes it easy to support Python 3 style keyword-only
45+
parameters. For example, in Python 3 it is possible to write::
46+
47+
def fn(pos1, *, kwonly1=None, kwonly1=None):
48+
...
49+
50+
All named parameters after ``*`` must be a keyword::
51+
52+
fn(10, 'kw1', 'kw2') # Raises exception.
53+
fn(10, kwonly1='kw1') # Ok.
54+
55+
Example
56+
^^^^^^^
57+
58+
To define a function like above, do::
59+
60+
@positional(1)
61+
def fn(pos1, kwonly1=None, kwonly2=None):
62+
...
63+
64+
If no default value is provided to a keyword argument, it becomes a
65+
required keyword argument::
66+
67+
@positional(0)
68+
def fn(required_kw):
69+
...
70+
71+
This must be called with the keyword parameter::
72+
73+
fn() # Raises exception.
74+
fn(10) # Raises exception.
75+
fn(required_kw=10) # Ok.
76+
77+
When defining instance or class methods always remember to account for
78+
``self`` and ``cls``::
79+
80+
class MyClass(object):
81+
82+
@positional(2)
83+
def my_method(self, pos1, kwonly1=None):
84+
...
85+
86+
@classmethod
87+
@positional(2)
88+
def my_method(cls, pos1, kwonly1=None):
89+
...
90+
91+
The positional decorator behavior is controlled by
92+
``_helpers.positional_parameters_enforcement``, which may be set to
93+
``POSITIONAL_EXCEPTION``, ``POSITIONAL_WARNING`` or
94+
``POSITIONAL_IGNORE`` to raise an exception, log a warning, or do
95+
nothing, respectively, if a declaration is violated.
96+
97+
Args:
98+
max_positional_arguments: Maximum number of positional arguments. All
99+
parameters after the this index must be
100+
keyword only.
101+
102+
Returns:
103+
A decorator that prevents using arguments after max_positional_args
104+
from being used as positional parameters.
105+
106+
Raises:
107+
TypeError: if a key-word only argument is provided as a positional
108+
parameter, but only if
109+
_helpers.positional_parameters_enforcement is set to
110+
POSITIONAL_EXCEPTION.
111+
"""
112+
113+
def positional_decorator(wrapped):
114+
@functools.wraps(wrapped)
115+
def positional_wrapper(*args, **kwargs):
116+
if len(args) > max_positional_args:
117+
plural_s = ''
118+
if max_positional_args != 1:
119+
plural_s = 's'
120+
message = ('{function}() takes at most {args_max} positional '
121+
'argument{plural} ({args_given} given)'.format(
122+
function=wrapped.__name__,
123+
args_max=max_positional_args,
124+
args_given=len(args),
125+
plural=plural_s))
126+
if positional_parameters_enforcement == POSITIONAL_EXCEPTION:
127+
raise TypeError(message)
128+
elif positional_parameters_enforcement == POSITIONAL_WARNING:
129+
logger.warning(message)
130+
return wrapped(*args, **kwargs)
131+
return positional_wrapper
132+
133+
if isinstance(max_positional_args, six.integer_types):
134+
return positional_decorator
135+
else:
136+
args, _, _, defaults = inspect.getargspec(max_positional_args)
137+
return positional(len(args) - len(defaults))(max_positional_args)
138+
139+
140+
def parse_unique_urlencoded(content):
141+
"""Parses unique key-value parameters from urlencoded content.
142+
143+
Args:
144+
content: string, URL-encoded key-value pairs.
145+
146+
Returns:
147+
dict, The key-value pairs from ``content``.
148+
149+
Raises:
150+
ValueError: if one of the keys is repeated.
151+
"""
152+
urlencoded_params = urllib.parse.parse_qs(content)
153+
params = {}
154+
for key, value in six.iteritems(urlencoded_params):
155+
if len(value) != 1:
156+
msg = ('URL-encoded content contains a repeated value:'
157+
'%s -> %s' % (key, ', '.join(value)))
158+
raise ValueError(msg)
159+
params[key] = value[0]
160+
return params
161+
162+
163+
def update_query_params(uri, params):
164+
"""Updates a URI with new query parameters.
165+
166+
If a given key from ``params`` is repeated in the ``uri``, then
167+
the URI will be considered invalid and an error will occur.
168+
169+
If the URI is valid, then each value from ``params`` will
170+
replace the corresponding value in the query parameters (if
171+
it exists).
172+
173+
Args:
174+
uri: string, A valid URI, with potential existing query parameters.
175+
params: dict, A dictionary of query parameters.
176+
177+
Returns:
178+
The same URI but with the new query parameters added.
179+
"""
180+
parts = urllib.parse.urlparse(uri)
181+
query_params = parse_unique_urlencoded(parts.query)
182+
query_params.update(params)
183+
new_query = urllib.parse.urlencode(query_params)
184+
new_parts = parts._replace(query=new_query)
185+
return urllib.parse.urlunparse(new_parts)
186+
187+
188+
def _add_query_parameter(url, name, value):
189+
"""Adds a query parameter to a url.
190+
191+
Replaces the current value if it already exists in the URL.
192+
193+
Args:
194+
url: string, url to add the query parameter to.
195+
name: string, query parameter name.
196+
value: string, query parameter value.
197+
198+
Returns:
199+
Updated query parameter. Does not update the url if value is None.
200+
"""
201+
if value is None:
202+
return url
203+
else:
204+
return update_query_params(url, {name: value})

googleapiclient/channel.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2014 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
"""Channel notifications support.
216
317
Classes and functions to support channel subscriptions and notifications
@@ -61,15 +75,9 @@
6175
import uuid
6276

6377
from googleapiclient import errors
78+
from googleapiclient import _helpers as util
6479
import six
6580

66-
# Oauth2client < 3 has the positional helper in 'util', >= 3 has it
67-
# in '_helpers'.
68-
try:
69-
from oauth2client import util
70-
except ImportError:
71-
from oauth2client import _helpers as util
72-
7381

7482
# The unix time epoch starts at midnight 1970.
7583
EPOCH = datetime.datetime.utcfromtimestamp(0)

googleapiclient/channel.pyc

-10.7 KB
Binary file not shown.

googleapiclient/discovery.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,9 @@
7272
from googleapiclient.model import MediaModel
7373
from googleapiclient.model import RawModel
7474
from googleapiclient.schema import Schemas
75-
from oauth2client.client import GoogleCredentials
7675

77-
# Oauth2client < 3 has the positional helper in 'util', >= 3 has it
78-
# in '_helpers'.
79-
try:
80-
from oauth2client.util import _add_query_parameter
81-
from oauth2client.util import positional
82-
except ImportError:
83-
from oauth2client._helpers import _add_query_parameter
84-
from oauth2client._helpers import positional
76+
from googleapiclient._helpers import _add_query_parameter
77+
from googleapiclient._helpers import positional
8578

8679

8780
# The client library requires a version of httplib2 that supports RETRIES.
@@ -139,7 +132,7 @@ def fix_method_name(name):
139132
name: string, method name.
140133
141134
Returns:
142-
The name with a '_' prefixed if the name is a reserved word.
135+
The name with an '_' appended if the name is a reserved word.
143136
"""
144137
if keyword.iskeyword(name) or name in RESERVED_WORDS:
145138
return name + '_'
@@ -455,7 +448,7 @@ def _media_path_url_from_info(root_desc, path_url):
455448
}
456449

457450

458-
def _fix_up_parameters(method_desc, root_desc, http_method):
451+
def _fix_up_parameters(method_desc, root_desc, http_method, schema):
459452
"""Updates parameters of an API method with values specific to this library.
460453
461454
Specifically, adds whatever global parameters are specified by the API to the
@@ -473,6 +466,7 @@ def _fix_up_parameters(method_desc, root_desc, http_method):
473466
root_desc: Dictionary; the entire original deserialized discovery document.
474467
http_method: String; the HTTP method used to call the API method described
475468
in method_desc.
469+
schema: Object, mapping of schema names to schema descriptions.
476470
477471
Returns:
478472
The updated Dictionary stored in the 'parameters' key of the method
@@ -493,6 +487,9 @@ def _fix_up_parameters(method_desc, root_desc, http_method):
493487
if http_method in HTTP_PAYLOAD_METHODS and 'request' in method_desc:
494488
body = BODY_PARAMETER_DEFAULT_VALUE.copy()
495489
body.update(method_desc['request'])
490+
# Make body optional for requests with no parameters.
491+
if not _methodProperties(method_desc, schema, 'request'):
492+
body['required'] = False
496493
parameters['body'] = body
497494

498495
return parameters
@@ -543,7 +540,7 @@ def _fix_up_media_upload(method_desc, root_desc, path_url, parameters):
543540
return accept, max_size, media_path_url
544541

545542

546-
def _fix_up_method_description(method_desc, root_desc):
543+
def _fix_up_method_description(method_desc, root_desc, schema):
547544
"""Updates a method description in a discovery document.
548545
549546
SIDE EFFECTS: Changes the parameters dictionary in the method description with
@@ -554,6 +551,7 @@ def _fix_up_method_description(method_desc, root_desc):
554551
from the dictionary of methods stored in the 'methods' key in the
555552
deserialized discovery document.
556553
root_desc: Dictionary; the entire original deserialized discovery document.
554+
schema: Object, mapping of schema names to schema descriptions.
557555
558556
Returns:
559557
Tuple (path_url, http_method, method_id, accept, max_size, media_path_url)
@@ -578,7 +576,7 @@ def _fix_up_method_description(method_desc, root_desc):
578576
http_method = method_desc['httpMethod']
579577
method_id = method_desc['id']
580578

581-
parameters = _fix_up_parameters(method_desc, root_desc, http_method)
579+
parameters = _fix_up_parameters(method_desc, root_desc, http_method, schema)
582580
# Order is important. `_fix_up_media_upload` needs `method_desc` to have a
583581
# 'parameters' key and needs to know if there is a 'body' parameter because it
584582
# also sets a 'media_body' parameter.
@@ -706,7 +704,7 @@ def createMethod(methodName, methodDesc, rootDesc, schema):
706704
"""
707705
methodName = fix_method_name(methodName)
708706
(pathUrl, httpMethod, methodId, accept,
709-
maxSize, mediaPathUrl) = _fix_up_method_description(methodDesc, rootDesc)
707+
maxSize, mediaPathUrl) = _fix_up_method_description(methodDesc, rootDesc, schema)
710708

711709
parameters = ResourceMethodParameters(methodDesc)
712710

googleapiclient/discovery.pyc

-38.9 KB
Binary file not shown.
-1.2 KB
Binary file not shown.
Binary file not shown.
-1.44 KB
Binary file not shown.

googleapiclient/discovery_cache/file_cache.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
try:
3737
from oauth2client.locked_file import LockedFile
3838
except ImportError:
39-
# oauth2client > 4.0.0
39+
# oauth2client > 4.0.0 or google-auth
4040
raise ImportError(
41-
'file_cache is unavailable when using oauth2client >= 4.0.0')
41+
'file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth')
4242

4343
from . import base
4444
from ..discovery_cache import DISCOVERY_DOC_MAX_AGE
-4.44 KB
Binary file not shown.

googleapiclient/errors.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@
2323

2424
import json
2525

26-
# Oauth2client < 3 has the positional helper in 'util', >= 3 has it
27-
# in '_helpers'.
28-
try:
29-
from oauth2client import util
30-
except ImportError:
31-
from oauth2client import _helpers as util
26+
from googleapiclient import _helpers as util
3227

3328

3429
class Error(Exception):

googleapiclient/errors.pyc

-7.15 KB
Binary file not shown.

0 commit comments

Comments
 (0)