本文整理汇总了Python中paste.util.multidict.MultiDict类的典型用法代码示例。如果您正苦于以下问题:Python MultiDict类的具体用法?Python MultiDict怎么用?Python MultiDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MultiDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_publish_with_multiple_urls
def test_publish_with_multiple_urls(self, mock):
data = MultiDict({'hub.mode': 'publish'})
data.add('hub.url', 'http://www.example.com/')
data.add('hub.url', 'http://www.site.com/')
request = self.r('/publish', self.valid_headers, POST=data)
info = publish(None, request)
self.assertEqual(info.status_code, 204)
示例2: init
def init(self):
plain_http_config = MultiDict()
soap_config = MultiDict()
dol = deepcopy(self.worker_config.http_soap).dict_of_lists()
for url_path in dol:
for item in dol[url_path]:
for soap_action, channel_info in item.items():
if channel_info['connection'] == 'channel':
if channel_info.transport == 'plain_http':
config = plain_http_config.setdefault(url_path, Bunch())
config[soap_action] = deepcopy(channel_info)
else:
config = soap_config.setdefault(url_path, Bunch())
config[soap_action] = deepcopy(channel_info)
self.request_dispatcher = RequestDispatcher(simple_io_config=self.worker_config.simple_io)
self.request_dispatcher.soap_handler = SOAPHandler(soap_config, self.server)
self.request_dispatcher.plain_http_handler = PlainHTTPHandler(plain_http_config, self.server)
# Statistics maintenance
self.stats_maint = MaintenanceTool(self.kvdb.conn)
self.request_dispatcher.security = ConnectionHTTPSOAPSecurity(
self.server.odb.get_url_security(self.server.cluster_id, 'channel')[0],
self.worker_config.basic_auth, self.worker_config.tech_acc, self.worker_config.wss)
# Create all the expected connections
self.init_sql()
self.init_ftp()
self.init_http_soap()
示例3: handle
def handle(self):
"""NOTE: The result of this function is *backwards*. It
returns None for success. Just like C.
"""
sub = self.subscriber
params = dict(sub.params)
params.update(self.data)
h = httplib2.Http()
h.follow_all_redirects = sub.follow_all_redirects
headers = MultiDict(sub.headers)
body = sub.body
if sub.username:
h.add_credentials(sub.username, sub.password)
params = dict((key, simplejson.dumps(value)) for key, value in params.items())
if sub.method == "GET":
#merge params with query string
qs = sub.queryString
if qs:
qs += "&"
else:
qs = "?"
qs += urllib.urlencode(params)
headers['Content-Length'] = '0'
else:
body = urllib.urlencode(params)
headers['Content-Length'] = str(len(body))
if not headers.has_key('Content-Type'):
headers['Content-Type'] = 'application/x-www-form-urlencoded'
username = config.get('username', None)
password = config.get('password', None)
if username:
headers['AUTHORIZATION'] = 'WSSE profile="UsernameToken"'
headers['X_WSSE'] = wsse_header(username, password)
__traceback_info__ = '%s %s (%i bytes in body)' % (sub.method, self.url, len(body))
log.info('Sending event %s %s (%i bytes in body, id=%s' % (self.url, sub.method, len(body), self.id))
self.last_sent = datetime.now()
self.failures += 1 #if we succeed, we won't care that someone called
#us a failure
if self.failures > MAX_SEND_FAILURES:
self.fail()
return None
try:
response = h.request(self.url, method=sub.method, body=body, headers=headers, redirections=sub.redirections)
except socket.error, e:
print >> sys.stderr, 'Error doing %s %s (body length: %i bytes)' % (self.url, sub.method, len(body))
return "%s" % e, ''
示例4: parse_path
def parse_path(self):
# parse path and parameters
path = self.path.split('?')[0]
params = self.path[len(path)+1:].split('&')
param_dict = MultiDict()
for param in params:
key = param.split('=')[0]
value = param[len(key)+1:]
param_dict.add(key, value)
return path, param_dict
示例5: search
def search(self, ver=None, register=None):
id = None
try:
params = MultiDict(self._get_search_params(request.params))
if 'q' in params.keys():
id = params['q']
if 'query' in params.keys():
id = params['query']
except ValueError, e:
log.debug(str(e))
pass
示例6: test_publish_fetches_topic_content
def test_publish_fetches_topic_content(self, mock):
data = MultiDict({'hub.mode': 'publish'})
data.add('hub.url', 'http://www.example.com/')
data.add('hub.url', 'http://www.site.com/')
request = self.r('/publish', self.valid_headers, POST=data)
hub = request.root
info = publish(None, request)
first = hub.topics.get('http://www.example.com/')
second = hub.topics.get('http://www.site.com/')
self.assertEqual(info.status_code, 204)
self.assertTrue(first.timestamp is not None)
self.assertTrue(second.timestamp is not None)
示例7: __init__
def __init__(self, log, location, urls=None, avgs=[1, 7], past_only=False,
config=None):
super(GoalAnalyser, self).__init__()
self.config = config
self.log = log
if urls is None:
if self.config is None:
self.urls = {}
else:
self.urls = config.urls()
else:
self.urls = urls
self.avgs = avgs
self.dir = location
self.past_only = past_only
self.statscounters = MultiDict()
self.outputs = {}
self.files = {}
self.existing_dates = {}
self.parse = logparser()
self.log_entries = {}
if self.config is not None:
for section in self.config.sections():
log = dict(self.config.items(section)).get('log', '').lower()
if log in ('true', 'yes', 'on'):
fn = '%s.log' % section
self.log_entries[section] = fn
self.files[fn] = open(os.path.join(self.dir, fn), 'w')
示例8: copy
def copy(self):
""" Creates a copy of this ConfigStore. All configuration data is copied
over except for SQL connections.
"""
config_store = ConfigStore()
# Grab all ConfigDicts - even if they're actually ZATO_NONE - and make their copies
for attr_name in dir(self):
attr = getattr(self, attr_name)
if isinstance(attr, ConfigDict):
copy_func = getattr(attr, 'copy')
setattr(config_store, attr_name, copy_func())
elif attr is ZATO_NONE:
setattr(config_store, attr_name, ZATO_NONE)
http_soap = MultiDict()
dict_of_lists = self.http_soap.dict_of_lists()
for url_path, lists in dict_of_lists.items():
_info = Bunch()
for elem in lists:
for soap_action, item in elem.items():
_info[soap_action] = Bunch()
_info[soap_action].id = item.id
_info[soap_action].name = item.name
_info[soap_action].is_active = item.is_active
_info[soap_action].is_internal = item.is_internal
_info[soap_action].url_path = item.url_path
_info[soap_action].method = item.method
_info[soap_action].soap_version = item.soap_version
_info[soap_action].service_id = item.service_id
_info[soap_action].service_name = item.service_name
_info[soap_action].impl_name = item.impl_name
_info[soap_action].transport = item.transport
_info[soap_action].connection = item.connection
http_soap.add(url_path, _info)
config_store.http_soap = http_soap
config_store.url_sec = self.url_sec
config_store.broker_config = self.broker_config
config_store.odb_data = deepcopy(self.odb_data)
return config_store
示例9: _get_params
def _get_params(self, request):
'''
Returns the parameter from request, regardless their type
(GET OR POST) and returns a MultiDict containg the values.
'''
params = MultiDict()
if request.method == 'POST':
# this is required by aiohttp. without this,
# request.POST is empty
_ = [f for f in request.post()]
for k, v in request.POST.items():
# when data is transfered via POST, array names are
# appended a '[]'.
params.add(k.replace('[]', ''), v)
elif request.method == 'GET':
for k, v in request.GET.items():
params.add(k, v)
else:
raise TypeError('You need to pass a Request obj')
return params
示例10: _parse_query
def _parse_query(self):
""" Decompose the query string into fields and terms. """
self._combined_fields = MultiDict(self._fields)
self._combined_terms = list(self._terms)
for token in self._query_tokens():
colon_pos = token.find(u':')
if colon_pos != -1:
field = token[:colon_pos]
value = token[colon_pos+1:]
value = value.strip('"').strip("'").strip()
self._combined_fields.add(field, value)
else:
self._combined_terms.append(token)
示例11: params
def params(self):
"""Dictionary-like object of keys from POST, GET, URL dicts
Return a key value from the parameters, they are checked in the
following order: POST, GET, URL
Additional methods supported:
``getlist(key)``
Returns a list of all the values by that key, collected from
POST, GET, URL dicts
Returns a ``MultiDict`` container or a ``UnicodeMultiDict`` when
``charset`` is set.
"""
params = MultiDict()
params.update(self._POST())
params.update(self._GET())
if self.charset:
params = UnicodeMultiDict(params, encoding=self.charset,
errors=self.errors,
decode_keys=self.decode_param_names)
return params
示例12: __init__
def __init__(self, items=()):
self._v = MultiDict([(normalize(key), remove_newlines(val))
for (key, val) in items])
self.changed = False
示例13: _
try:
since_time = h.date_str_to_datetime(since_time_str)
except ValueError, inst:
return self._finish_bad_request('ValueError: %s' % inst)
else:
return self._finish_bad_request(
_("Missing search term ('since_id=UUID' or " +
" 'since_time=TIMESTAMP')"))
revs = model.Session.query(model.Revision) \
.filter(model.Revision.timestamp > since_time) \
.order_by(model.Revision.timestamp) \
.limit(50) # reasonable enough for a page
return self._finish_ok([rev.id for rev in revs])
elif register in ['dataset', 'package', 'resource']:
try:
params = MultiDict(self._get_search_params(request.params))
except ValueError, e:
return self._finish_bad_request(
_('Could not read parameters: %r' % e))
# if using API v2, default to returning the package ID if
# no field list is specified
if register in ['dataset', 'package'] and not params.get('fl'):
params['fl'] = 'id' if ver == 2 else 'name'
try:
if register == 'resource':
query = search.query_for(model.Resource)
# resource search still uses ckan query parser
options = search.QueryOptions()
示例14: _after_init_accepted
def _after_init_accepted(self, server):
if self.singleton_server:
for(_, name, is_active, job_type, start_date, extra, service,\
_, weeks, days, hours, minutes, seconds, repeats, cron_definition)\
in self.odb.get_job_list(server.cluster.id):
if is_active:
job_data = Bunch({'name':name, 'is_active':is_active,
'job_type':job_type, 'start_date':start_date,
'extra':extra, 'service':service, 'weeks':weeks,
'days':days, 'hours':hours, 'minutes':minutes,
'seconds':seconds, 'repeats':repeats,
'cron_definition':cron_definition})
self.singleton_server.scheduler.create_edit('create', job_data)
# Start the connectors only once throughout the whole cluster
self._init_connectors(server)
# Mapping between SOAP actions and internal services.
#for soap_action, service_name in self.odb.get_internal_channel_list(server.cluster.id):
# self.request_handler.soap_handler.soap_config[soap_action] = service_name
# FTP
ftp_conn_params = Bunch()
for item in self.odb.get_out_ftp_list(server.cluster.id):
ftp_conn_params[item.name] = Bunch()
ftp_conn_params[item.name].is_active = item.is_active
ftp_conn_params[item.name].name = item.name
ftp_conn_params[item.name].host = item.host
ftp_conn_params[item.name].user = item.user
ftp_conn_params[item.name].password = item.password
ftp_conn_params[item.name].acct = item.acct
ftp_conn_params[item.name].timeout = item.timeout
ftp_conn_params[item.name].port = item.port
ftp_conn_params[item.name].dircache = item.dircache
self.ftp = FTPFacade(ftp_conn_params)
self.worker_config = Bunch()
# Repo location so that AMQP subprocesses know how where to read
# the server's configuration from.
self.worker_config.repo_location = self.repo_location
# The broker client for each of the worker threads.
self.worker_config.broker_config = Bunch()
self.worker_config.broker_config.name = 'worker-thread'
self.worker_config.broker_config.broker_token = self.broker_token
self.worker_config.broker_config.zmq_context = self.zmq_context
self.worker_config.broker_config.broker_push_client_pull = self.broker_push_worker_pull
self.worker_config.broker_config.client_push_broker_pull = self.worker_push_broker_pull
self.worker_config.broker_config.broker_pub_client_sub = self.broker_pub_worker_sub
# HTTP Basic Auth
ba_config = Bunch()
for item in self.odb.get_basic_auth_list(server.cluster.id):
ba_config[item.name] = Bunch()
ba_config[item.name].is_active = item.is_active
ba_config[item.name].username = item.username
ba_config[item.name].domain = item.domain
ba_config[item.name].password = item.password
# Technical accounts
ta_config = Bunch()
for item in self.odb.get_tech_acc_list(server.cluster.id):
ta_config[item.name] = Bunch()
ta_config[item.name].is_active = item.is_active
ta_config[item.name].name = item.name
ta_config[item.name].password = item.password
ta_config[item.name].salt = item.salt
wss_config = Bunch()
for item in self.odb.get_wss_list(server.cluster.id):
wss_config[item.name] = Bunch()
wss_config[item.name].is_active = item.is_active
wss_config[item.name].username = item.username
wss_config[item.name].password = item.password
wss_config[item.name].password_type = item.password_type
wss_config[item.name].reject_empty_nonce_ts = item.reject_empty_nonce_ts
wss_config[item.name].reject_stale_username = item.reject_stale_username
wss_config[item.name].expiry_limit = item.expiry_limit
wss_config[item.name].nonce_freshness = item.nonce_freshness
# Security configuration of HTTP URLs.
url_sec = self.odb.get_url_security(server)
# All the HTTP/SOAP channels.
http_soap = MultiDict()
for item in self.odb.get_http_soap_list(server.cluster.id, 'channel'):
_info = Bunch()
_info[item.soap_action] = Bunch()
_info[item.soap_action].id = item.id
_info[item.soap_action].name = item.name
_info[item.soap_action].is_internal = item.is_internal
_info[item.soap_action].url_path = item.url_path
_info[item.soap_action].method = item.method
_info[item.soap_action].soap_version = item.soap_version
_info[item.soap_action].service_id = item.service_id
_info[item.soap_action].service_name = item.service_name
_info[item.soap_action].impl_name = item.impl_name
http_soap.add(item.url_path, _info)
#.........这里部分代码省略.........
示例15: __init__
def __init__(self, items=()):
self.v = MultiDict(
[(normalize(key), val) for (key, val) in items])
self.changed = False