googlecloud 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +4 -0
- data/LICENSE +674 -0
- data/Manifest +111 -0
- data/README.md +4 -3
- data/bin/gcutil +53 -0
- data/googlecloud.gemspec +4 -3
- data/packages/gcutil-1.7.1/CHANGELOG +197 -0
- data/packages/gcutil-1.7.1/LICENSE +202 -0
- data/packages/gcutil-1.7.1/VERSION +1 -0
- data/packages/gcutil-1.7.1/gcutil +53 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/LICENSE +23 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/__init__.py +1 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/discovery.py +743 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/errors.py +123 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/ext/__init__.py +0 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/http.py +1443 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/mimeparse.py +172 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/model.py +385 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/apiclient/schema.py +303 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/__init__.py +1 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/anyjson.py +32 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/appengine.py +528 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/client.py +1139 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/clientsecrets.py +105 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/crypt.py +244 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/django_orm.py +124 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/file.py +107 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/locked_file.py +343 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.py +379 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/tools.py +174 -0
- data/packages/gcutil-1.7.1/lib/google_api_python_client/uritemplate/__init__.py +147 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/LICENSE +202 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/__init__.py +3 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/__init__.py +3 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/app.py +356 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/appcommands.py +783 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/basetest.py +1260 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/datelib.py +421 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/debug.py +60 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/file_util.py +181 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/resources.py +67 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/run_script_module.py +217 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/setup_command.py +159 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/shellutil.py +49 -0
- data/packages/gcutil-1.7.1/lib/google_apputils/google/apputils/stopwatch.py +204 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/__init__.py +0 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auth_helper.py +140 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auth_helper_test.py +149 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auto_auth.py +130 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/auto_auth_test.py +75 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/basic_cmds.py +128 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/basic_cmds_test.py +111 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base.py +1808 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/command_base_test.py +1651 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/compute/v1beta13.json +2851 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/compute/v1beta14.json +3361 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/disk_cmds.py +342 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/disk_cmds_test.py +474 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/firewall_cmds.py +344 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/firewall_cmds_test.py +231 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/flags_cache.py +274 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/gcutil +89 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/gcutil_logging.py +69 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/image_cmds.py +262 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/image_cmds_test.py +172 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/instance_cmds.py +1506 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/instance_cmds_test.py +1904 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/kernel_cmds.py +91 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/kernel_cmds_test.py +56 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/machine_type_cmds.py +106 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/machine_type_cmds_test.py +59 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/metadata.py +96 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/metadata_lib.py +357 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/metadata_test.py +84 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/mock_api.py +420 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/mock_metadata.py +58 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/move_cmds.py +824 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/move_cmds_test.py +307 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/network_cmds.py +178 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/network_cmds_test.py +133 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/operation_cmds.py +181 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/operation_cmds_test.py +196 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/path_initializer.py +38 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/project_cmds.py +173 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/project_cmds_test.py +111 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/scopes.py +61 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/scopes_test.py +50 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/snapshot_cmds.py +276 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/snapshot_cmds_test.py +260 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/ssh_keys.py +266 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/ssh_keys_test.py +128 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/table_formatter.py +563 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool.py +188 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/thread_pool_test.py +88 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/utils.py +208 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/utils_test.py +193 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/version.py +17 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/version_checker.py +246 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/version_checker_test.py +271 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/zone_cmds.py +151 -0
- data/packages/gcutil-1.7.1/lib/google_compute_engine/gcutil/zone_cmds_test.py +60 -0
- data/packages/gcutil-1.7.1/lib/httplib2/LICENSE +21 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/__init__.py +1630 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/cacerts.txt +714 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/iri2uri.py +110 -0
- data/packages/gcutil-1.7.1/lib/httplib2/httplib2/socks.py +438 -0
- data/packages/gcutil-1.7.1/lib/iso8601/LICENSE +20 -0
- data/packages/gcutil-1.7.1/lib/iso8601/iso8601/__init__.py +1 -0
- data/packages/gcutil-1.7.1/lib/iso8601/iso8601/iso8601.py +102 -0
- data/packages/gcutil-1.7.1/lib/iso8601/iso8601/test_iso8601.py +111 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/AUTHORS +2 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/LICENSE +28 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/gflags.py +2862 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/gflags2man.py +544 -0
- data/packages/gcutil-1.7.1/lib/python_gflags/gflags_validators.py +187 -0
- metadata +118 -5
- metadata.gz.sig +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Copyright (C) 2010 Google Inc.
|
|
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
|
+
"""Command-line tools for authenticating via OAuth 2.0
|
|
16
|
+
|
|
17
|
+
Do the OAuth 2.0 Web Server dance for a command line application. Stores the
|
|
18
|
+
generated credentials in a common file that is used by other example apps in
|
|
19
|
+
the same directory.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
__all__ = ['run']
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
import BaseHTTPServer
|
|
27
|
+
import gflags
|
|
28
|
+
import socket
|
|
29
|
+
import sys
|
|
30
|
+
import webbrowser
|
|
31
|
+
|
|
32
|
+
from client import FlowExchangeError
|
|
33
|
+
from client import OOB_CALLBACK_URN
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
from urlparse import parse_qsl
|
|
37
|
+
except ImportError:
|
|
38
|
+
from cgi import parse_qsl
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
FLAGS = gflags.FLAGS
|
|
42
|
+
|
|
43
|
+
gflags.DEFINE_boolean('auth_local_webserver', True,
|
|
44
|
+
('Run a local web server to handle redirects during '
|
|
45
|
+
'OAuth authorization.'))
|
|
46
|
+
|
|
47
|
+
gflags.DEFINE_string('auth_host_name', 'localhost',
|
|
48
|
+
('Host name to use when running a local web server to '
|
|
49
|
+
'handle redirects during OAuth authorization.'))
|
|
50
|
+
|
|
51
|
+
gflags.DEFINE_multi_int('auth_host_port', [8080, 8090],
|
|
52
|
+
('Port to use when running a local web server to '
|
|
53
|
+
'handle redirects during OAuth authorization.'))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ClientRedirectServer(BaseHTTPServer.HTTPServer):
|
|
57
|
+
"""A server to handle OAuth 2.0 redirects back to localhost.
|
|
58
|
+
|
|
59
|
+
Waits for a single request and parses the query parameters
|
|
60
|
+
into query_params and then stops serving.
|
|
61
|
+
"""
|
|
62
|
+
query_params = {}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class ClientRedirectHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|
66
|
+
"""A handler for OAuth 2.0 redirects back to localhost.
|
|
67
|
+
|
|
68
|
+
Waits for a single request and parses the query parameters
|
|
69
|
+
into the servers query_params and then stops serving.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
def do_GET(s):
|
|
73
|
+
"""Handle a GET request.
|
|
74
|
+
|
|
75
|
+
Parses the query parameters and prints a message
|
|
76
|
+
if the flow has completed. Note that we can't detect
|
|
77
|
+
if an error occurred.
|
|
78
|
+
"""
|
|
79
|
+
s.send_response(200)
|
|
80
|
+
s.send_header("Content-type", "text/html")
|
|
81
|
+
s.end_headers()
|
|
82
|
+
query = s.path.split('?', 1)[-1]
|
|
83
|
+
query = dict(parse_qsl(query))
|
|
84
|
+
s.server.query_params = query
|
|
85
|
+
s.wfile.write("<html><head><title>Authentication Status</title></head>")
|
|
86
|
+
s.wfile.write("<body><p>The authentication flow has completed.</p>")
|
|
87
|
+
s.wfile.write("</body></html>")
|
|
88
|
+
|
|
89
|
+
def log_message(self, format, *args):
|
|
90
|
+
"""Do not log messages to stdout while running as command line program."""
|
|
91
|
+
pass
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def run(flow, storage, http=None):
|
|
95
|
+
"""Core code for a command-line application.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
flow: Flow, an OAuth 2.0 Flow to step through.
|
|
99
|
+
storage: Storage, a Storage to store the credential in.
|
|
100
|
+
http: An instance of httplib2.Http.request
|
|
101
|
+
or something that acts like it.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Credentials, the obtained credential.
|
|
105
|
+
"""
|
|
106
|
+
if FLAGS.auth_local_webserver:
|
|
107
|
+
success = False
|
|
108
|
+
port_number = 0
|
|
109
|
+
for port in FLAGS.auth_host_port:
|
|
110
|
+
port_number = port
|
|
111
|
+
try:
|
|
112
|
+
httpd = ClientRedirectServer((FLAGS.auth_host_name, port),
|
|
113
|
+
ClientRedirectHandler)
|
|
114
|
+
except socket.error, e:
|
|
115
|
+
pass
|
|
116
|
+
else:
|
|
117
|
+
success = True
|
|
118
|
+
break
|
|
119
|
+
FLAGS.auth_local_webserver = success
|
|
120
|
+
if not success:
|
|
121
|
+
print 'Failed to start a local webserver listening on either port 8080'
|
|
122
|
+
print 'or port 9090. Please check your firewall settings and locally'
|
|
123
|
+
print 'running programs that may be blocking or using those ports.'
|
|
124
|
+
print
|
|
125
|
+
print 'Falling back to --noauth_local_webserver and continuing with',
|
|
126
|
+
print 'authorization.'
|
|
127
|
+
print
|
|
128
|
+
|
|
129
|
+
if FLAGS.auth_local_webserver:
|
|
130
|
+
oauth_callback = 'http://%s:%s/' % (FLAGS.auth_host_name, port_number)
|
|
131
|
+
else:
|
|
132
|
+
oauth_callback = OOB_CALLBACK_URN
|
|
133
|
+
authorize_url = flow.step1_get_authorize_url(oauth_callback)
|
|
134
|
+
|
|
135
|
+
if FLAGS.auth_local_webserver:
|
|
136
|
+
webbrowser.open(authorize_url, new=1, autoraise=True)
|
|
137
|
+
print 'Your browser has been opened to visit:'
|
|
138
|
+
print
|
|
139
|
+
print ' ' + authorize_url
|
|
140
|
+
print
|
|
141
|
+
print 'If your browser is on a different machine then exit and re-run this'
|
|
142
|
+
print 'application with the command-line parameter '
|
|
143
|
+
print
|
|
144
|
+
print ' --noauth_local_webserver'
|
|
145
|
+
print
|
|
146
|
+
else:
|
|
147
|
+
print 'Go to the following link in your browser:'
|
|
148
|
+
print
|
|
149
|
+
print ' ' + authorize_url
|
|
150
|
+
print
|
|
151
|
+
|
|
152
|
+
code = None
|
|
153
|
+
if FLAGS.auth_local_webserver:
|
|
154
|
+
httpd.handle_request()
|
|
155
|
+
if 'error' in httpd.query_params:
|
|
156
|
+
sys.exit('Authentication request was rejected.')
|
|
157
|
+
if 'code' in httpd.query_params:
|
|
158
|
+
code = httpd.query_params['code']
|
|
159
|
+
else:
|
|
160
|
+
print 'Failed to find "code" in the query parameters of the redirect.'
|
|
161
|
+
sys.exit('Try running with --noauth_local_webserver.')
|
|
162
|
+
else:
|
|
163
|
+
code = raw_input('Enter verification code: ').strip()
|
|
164
|
+
|
|
165
|
+
try:
|
|
166
|
+
credential = flow.step2_exchange(code, http)
|
|
167
|
+
except FlowExchangeError, e:
|
|
168
|
+
sys.exit('Authentication has failed: %s' % e)
|
|
169
|
+
|
|
170
|
+
storage.put(credential)
|
|
171
|
+
credential.set_store(storage)
|
|
172
|
+
print 'Authentication successful.'
|
|
173
|
+
|
|
174
|
+
return credential
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Early, and incomplete implementation of -04.
|
|
2
|
+
#
|
|
3
|
+
import re
|
|
4
|
+
import urllib
|
|
5
|
+
|
|
6
|
+
RESERVED = ":/?#[]@!$&'()*+,;="
|
|
7
|
+
OPERATOR = "+./;?|!@"
|
|
8
|
+
EXPLODE = "*+"
|
|
9
|
+
MODIFIER = ":^"
|
|
10
|
+
TEMPLATE = re.compile(r"{(?P<operator>[\+\./;\?|!@])?(?P<varlist>[^}]+)}", re.UNICODE)
|
|
11
|
+
VAR = re.compile(r"^(?P<varname>[^=\+\*:\^]+)((?P<explode>[\+\*])|(?P<partial>[:\^]-?[0-9]+))?(=(?P<default>.*))?$", re.UNICODE)
|
|
12
|
+
|
|
13
|
+
def _tostring(varname, value, explode, operator, safe=""):
|
|
14
|
+
if type(value) == type([]):
|
|
15
|
+
if explode == "+":
|
|
16
|
+
return ",".join([varname + "." + urllib.quote(x, safe) for x in value])
|
|
17
|
+
else:
|
|
18
|
+
return ",".join([urllib.quote(x, safe) for x in value])
|
|
19
|
+
if type(value) == type({}):
|
|
20
|
+
keys = value.keys()
|
|
21
|
+
keys.sort()
|
|
22
|
+
if explode == "+":
|
|
23
|
+
return ",".join([varname + "." + urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
|
|
24
|
+
else:
|
|
25
|
+
return ",".join([urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
|
|
26
|
+
else:
|
|
27
|
+
return urllib.quote(value, safe)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _tostring_path(varname, value, explode, operator, safe=""):
|
|
31
|
+
joiner = operator
|
|
32
|
+
if type(value) == type([]):
|
|
33
|
+
if explode == "+":
|
|
34
|
+
return joiner.join([varname + "." + urllib.quote(x, safe) for x in value])
|
|
35
|
+
elif explode == "*":
|
|
36
|
+
return joiner.join([urllib.quote(x, safe) for x in value])
|
|
37
|
+
else:
|
|
38
|
+
return ",".join([urllib.quote(x, safe) for x in value])
|
|
39
|
+
elif type(value) == type({}):
|
|
40
|
+
keys = value.keys()
|
|
41
|
+
keys.sort()
|
|
42
|
+
if explode == "+":
|
|
43
|
+
return joiner.join([varname + "." + urllib.quote(key, safe) + joiner + urllib.quote(value[key], safe) for key in keys])
|
|
44
|
+
elif explode == "*":
|
|
45
|
+
return joiner.join([urllib.quote(key, safe) + joiner + urllib.quote(value[key], safe) for key in keys])
|
|
46
|
+
else:
|
|
47
|
+
return ",".join([urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
|
|
48
|
+
else:
|
|
49
|
+
if value:
|
|
50
|
+
return urllib.quote(value, safe)
|
|
51
|
+
else:
|
|
52
|
+
return ""
|
|
53
|
+
|
|
54
|
+
def _tostring_query(varname, value, explode, operator, safe=""):
|
|
55
|
+
joiner = operator
|
|
56
|
+
varprefix = ""
|
|
57
|
+
if operator == "?":
|
|
58
|
+
joiner = "&"
|
|
59
|
+
varprefix = varname + "="
|
|
60
|
+
if type(value) == type([]):
|
|
61
|
+
if 0 == len(value):
|
|
62
|
+
return ""
|
|
63
|
+
if explode == "+":
|
|
64
|
+
return joiner.join([varname + "=" + urllib.quote(x, safe) for x in value])
|
|
65
|
+
elif explode == "*":
|
|
66
|
+
return joiner.join([urllib.quote(x, safe) for x in value])
|
|
67
|
+
else:
|
|
68
|
+
return varprefix + ",".join([urllib.quote(x, safe) for x in value])
|
|
69
|
+
elif type(value) == type({}):
|
|
70
|
+
if 0 == len(value):
|
|
71
|
+
return ""
|
|
72
|
+
keys = value.keys()
|
|
73
|
+
keys.sort()
|
|
74
|
+
if explode == "+":
|
|
75
|
+
return joiner.join([varname + "." + urllib.quote(key, safe) + "=" + urllib.quote(value[key], safe) for key in keys])
|
|
76
|
+
elif explode == "*":
|
|
77
|
+
return joiner.join([urllib.quote(key, safe) + "=" + urllib.quote(value[key], safe) for key in keys])
|
|
78
|
+
else:
|
|
79
|
+
return varprefix + ",".join([urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
|
|
80
|
+
else:
|
|
81
|
+
if value:
|
|
82
|
+
return varname + "=" + urllib.quote(value, safe)
|
|
83
|
+
else:
|
|
84
|
+
return varname
|
|
85
|
+
|
|
86
|
+
TOSTRING = {
|
|
87
|
+
"" : _tostring,
|
|
88
|
+
"+": _tostring,
|
|
89
|
+
";": _tostring_query,
|
|
90
|
+
"?": _tostring_query,
|
|
91
|
+
"/": _tostring_path,
|
|
92
|
+
".": _tostring_path,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def expand(template, vars):
|
|
97
|
+
def _sub(match):
|
|
98
|
+
groupdict = match.groupdict()
|
|
99
|
+
operator = groupdict.get('operator')
|
|
100
|
+
if operator is None:
|
|
101
|
+
operator = ''
|
|
102
|
+
varlist = groupdict.get('varlist')
|
|
103
|
+
|
|
104
|
+
safe = "@"
|
|
105
|
+
if operator == '+':
|
|
106
|
+
safe = RESERVED
|
|
107
|
+
varspecs = varlist.split(",")
|
|
108
|
+
varnames = []
|
|
109
|
+
defaults = {}
|
|
110
|
+
for varspec in varspecs:
|
|
111
|
+
m = VAR.search(varspec)
|
|
112
|
+
groupdict = m.groupdict()
|
|
113
|
+
varname = groupdict.get('varname')
|
|
114
|
+
explode = groupdict.get('explode')
|
|
115
|
+
partial = groupdict.get('partial')
|
|
116
|
+
default = groupdict.get('default')
|
|
117
|
+
if default:
|
|
118
|
+
defaults[varname] = default
|
|
119
|
+
varnames.append((varname, explode, partial))
|
|
120
|
+
|
|
121
|
+
retval = []
|
|
122
|
+
joiner = operator
|
|
123
|
+
prefix = operator
|
|
124
|
+
if operator == "+":
|
|
125
|
+
prefix = ""
|
|
126
|
+
joiner = ","
|
|
127
|
+
if operator == "?":
|
|
128
|
+
joiner = "&"
|
|
129
|
+
if operator == "":
|
|
130
|
+
joiner = ","
|
|
131
|
+
for varname, explode, partial in varnames:
|
|
132
|
+
if varname in vars:
|
|
133
|
+
value = vars[varname]
|
|
134
|
+
#if not value and (type(value) == type({}) or type(value) == type([])) and varname in defaults:
|
|
135
|
+
if not value and value != "" and varname in defaults:
|
|
136
|
+
value = defaults[varname]
|
|
137
|
+
elif varname in defaults:
|
|
138
|
+
value = defaults[varname]
|
|
139
|
+
else:
|
|
140
|
+
continue
|
|
141
|
+
retval.append(TOSTRING[operator](varname, value, explode, operator, safe=safe))
|
|
142
|
+
if "".join(retval):
|
|
143
|
+
return prefix + joiner.join(retval)
|
|
144
|
+
else:
|
|
145
|
+
return ""
|
|
146
|
+
|
|
147
|
+
return TEMPLATE.sub(_sub, template)
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|