本文整理汇总了Python中six.moves.urllib.parse.unquote_plus函数的典型用法代码示例。如果您正苦于以下问题:Python unquote_plus函数的具体用法?Python unquote_plus怎么用?Python unquote_plus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unquote_plus函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, uri):
u = urlparse(uri)
self.host = u.hostname
self.port = int(u.port or "22")
self.username = unquote_plus(u.username)
self.password = unquote_plus(u.password)
self.path = u.path
开发者ID:redapple,项目名称:scrapy-feedexporter-sftp,代码行数:7,代码来源:__init__.py
示例2: load
def load(self, url, offset, length):
if not s3_avail: #pragma: no cover
raise IOError('To load from s3 paths, ' +
'you must install boto: pip install boto')
aws_access_key_id = self.aws_access_key_id
aws_secret_access_key = self.aws_secret_access_key
parts = urlsplit(url)
if parts.username and parts.password:
aws_access_key_id = unquote_plus(parts.username)
aws_secret_access_key = unquote_plus(parts.password)
bucket_name = parts.netloc.split('@', 1)[-1]
else:
bucket_name = parts.netloc
if not self.s3conn:
try:
self.s3conn = connect_s3(aws_access_key_id, aws_secret_access_key)
except Exception: #pragma: no cover
self.s3conn = connect_s3(anon=True)
bucket = self.s3conn.get_bucket(bucket_name)
key = bucket.get_key(parts.path)
if offset == 0 and length == -1:
headers = {}
else:
headers = {'Range': BlockLoader._make_range_header(offset, length)}
# Read range
key.open_read(headers=headers)
return key
开发者ID:gwu-libraries,项目名称:pywb,代码行数:35,代码来源:loaders.py
示例3: on_get
def on_get(self, external_project_id, **kw):
LOG.debug('Start certificate_authorities on_get (limited)')
plugin_name = kw.get('plugin_name')
if plugin_name is not None:
plugin_name = parse.unquote_plus(plugin_name)
plugin_ca_id = kw.get('plugin_ca_id', None)
if plugin_ca_id is not None:
plugin_ca_id = parse.unquote_plus(plugin_ca_id)
# refresh CA table, in case plugin entries have expired
cert_resources.refresh_certificate_resources()
project_model = res.get_or_create_project(external_project_id)
if self._project_cas_defined(project_model.id):
cas, offset, limit, total = self._get_subcas_and_project_cas(
offset=kw.get('offset', 0),
limit=kw.get('limit', None),
plugin_name=plugin_name,
plugin_ca_id=plugin_ca_id,
project_id=project_model.id)
else:
cas, offset, limit, total = self._get_subcas_and_root_cas(
offset=kw.get('offset', 0),
limit=kw.get('limit', None),
plugin_name=plugin_name,
plugin_ca_id=plugin_ca_id,
project_id=project_model.id)
return self._display_cas(cas, offset, limit, total)
开发者ID:abattye,项目名称:barbican,代码行数:32,代码来源:cas.py
示例4: url_unquote_plus
def url_unquote_plus(v, name='(Unknown name)', md={}):
if six.PY2 and isinstance(v, unicode):
# unquote_plus does not handle unicode. Encoding to a "safe"
# intermediate encoding before quoting, then unencoding the result.
return unquote_plus(v.encode('utf-8')).decode('utf-8')
elif six.PY3 and isinstance(v, bytes):
return unquote_plus(v.decode('utf-8')).encode('utf-8')
return unquote_plus(str(v))
开发者ID:zopefoundation,项目名称:DocumentTemplate,代码行数:8,代码来源:DT_Var.py
示例5: unquote_plus
def unquote_plus(text):
"""unquote('%7e/abc+def') -> '~/abc def'"""
try:
if six.PY2 and isinstance(text, six.text_type):
text = text.encode('utf-8')
if six.PY2:
result = parse.unquote_plus(text).decode('utf-8')
else:
# Enforce utf-8 validation
result = parse.unquote_plus(text, errors="strict")
return result
except (UnicodeEncodeError, UnicodeDecodeError) as e:
# for some reason there is a non-ascii character here. Let's assume it
# is already unicode (because of originally decoding the file)
return text
开发者ID:diorcety,项目名称:translate,代码行数:15,代码来源:pocommon.py
示例6: load_crypto_meta
def load_crypto_meta(value, b64decode=True):
"""
Build the crypto_meta from the json object.
Note that json.loads always produces unicode strings; to ensure the
resultant crypto_meta matches the original object:
* cast all keys to str (effectively a no-op on py3),
* base64 decode 'key' and 'iv' values to bytes, and
* encode remaining string values as UTF-8 on py2 (while leaving them
as native unicode strings on py3).
:param value: a string serialization of a crypto meta dict
:param b64decode: decode the 'key' and 'iv' values to bytes, default True
:returns: a dict containing crypto meta items
:raises EncryptionException: if an error occurs while parsing the
crypto meta
"""
def b64_decode_meta(crypto_meta):
return {
str(name): (
base64.b64decode(val) if name in ('iv', 'key') and b64decode
else b64_decode_meta(val) if isinstance(val, dict)
else val.encode('utf8') if six.PY2 else val)
for name, val in crypto_meta.items()}
try:
if not isinstance(value, six.string_types):
raise ValueError('crypto meta not a string')
val = json.loads(urlparse.unquote_plus(value))
if not isinstance(val, collections.Mapping):
raise ValueError('crypto meta not a Mapping')
return b64_decode_meta(val)
except (KeyError, ValueError, TypeError) as err:
msg = 'Bad crypto meta %r: %s' % (value, err)
raise EncryptionException(msg)
开发者ID:mahak,项目名称:swift,代码行数:35,代码来源:crypto_utils.py
示例7: load_crypto_meta
def load_crypto_meta(value):
"""
Build the crypto_meta from the json object.
Note that json.loads always produces unicode strings, to ensure the
resultant crypto_meta matches the original object cast all key and value
data to a str except the key and iv which are base64 decoded. This will
work in py3 as well where all strings are unicode implying the cast is
effectively a no-op.
:param value: a string serialization of a crypto meta dict
:returns: a dict containing crypto meta items
:raises EncryptionException: if an error occurs while parsing the
crypto meta
"""
def b64_decode_meta(crypto_meta):
return {
str(name): (base64.b64decode(val) if name in ('iv', 'key')
else b64_decode_meta(val) if isinstance(val, dict)
else val.encode('utf8'))
for name, val in crypto_meta.items()}
try:
if not isinstance(value, six.string_types):
raise ValueError('crypto meta not a string')
val = json.loads(urlparse.unquote_plus(value))
if not isinstance(val, collections.Mapping):
raise ValueError('crypto meta not a Mapping')
return b64_decode_meta(val)
except (KeyError, ValueError, TypeError) as err:
msg = 'Bad crypto meta %r: %s' % (value, err)
raise EncryptionException(msg)
开发者ID:SmartInfrastructures,项目名称:swift,代码行数:32,代码来源:crypto_utils.py
示例8: parse
def parse(body):
body = unquote_plus(body)
soup = BeautifulSoup(body, 'html.parser')
tr_tags = soup.find_all('tr')
pairs = [parse_tr(tr) for tr in tr_tags if len(tr.find_all('td')) >= 4 and has_time(str(tr))]
favorites, underdogs = zip(*pairs)
df_picks = pd.DataFrame({'favorite': favorites, 'underdog': underdogs})
df_picks['my_pick'] = df_picks.apply(
lambda row: choice([row['favorite'], row['underdog']]), axis=1)
best_bets = sample(set(df_picks.my_pick.unique()), 3)
def add_best_bet(pick,):
pick = pick + '^^^' if pick in best_bets else pick
pick = pick.replace('*', '')
pick = pick.replace('^^^', '***')
pick = pick[3:] if pick.startswith('At ') else pick
return pick
df_picks.my_pick = df_picks.my_pick.apply(add_best_bet)
body_output = '\n'.join(df_picks.my_pick)
text_joined = soup.get_text(" ").lower()
text_joined = text_joined.replace('last week', '').replace('other week', '').replace('this week', '')
text_parts = [t.strip() for t in text_joined.split()]
week_index = text_parts.index("week")
week_num = text_parts[week_index + 1]
return body_output, week_num
开发者ID:tavinathanson,项目名称:football-picks,代码行数:26,代码来源:picks.py
示例9: on_get
def on_get(self, external_project_id, **kw):
LOG.debug('Start transport_keys on_get')
plugin_name = kw.get('plugin_name', None)
if plugin_name is not None:
plugin_name = parse.unquote_plus(plugin_name)
result = self.repo.get_by_create_date(
plugin_name=plugin_name,
offset_arg=kw.get('offset', 0),
limit_arg=kw.get('limit', None),
suppress_exception=True
)
transport_keys, offset, limit, total = result
if not transport_keys:
transport_keys_resp_overall = {'transport_keys': [],
'total': total}
else:
transport_keys_resp = [
hrefs.convert_transport_key_to_href(s.id)
for s in transport_keys
]
transport_keys_resp_overall = hrefs.add_nav_hrefs(
'transport_keys',
offset,
limit,
total,
{'transport_keys': transport_keys_resp}
)
transport_keys_resp_overall.update({'total': total})
return transport_keys_resp_overall
开发者ID:openstack,项目名称:barbican,代码行数:34,代码来源:transportkeys.py
示例10: _verify_postback
def _verify_postback(self):
# ### Now we don't really care what result was, just whether a flag was set or not.
from paypal.standard.pdt.forms import PayPalPDTForm
response_list = self.response.split('\n')
response_dict = {}
for i, line in enumerate(response_list):
unquoted_line = unquote_plus(line).strip()
if i == 0:
self.st = unquoted_line
else:
if self.st != "SUCCESS":
self.set_flag(line)
break
try:
if not unquoted_line.startswith(' -'):
k, v = unquoted_line.split('=')
response_dict[k.strip()] = v.strip()
except ValueError:
pass
qd = QueryDict('', mutable=True)
qd.update(response_dict)
qd.update(dict(ipaddress=self.ipaddress, st=self.st, flag_info=self.flag_info, flag=self.flag,
flag_code=self.flag_code))
pdt_form = PayPalPDTForm(qd, instance=self)
pdt_form.save(commit=False)
开发者ID:adamziel,项目名称:django-paypal,代码行数:27,代码来源:models.py
示例11: decode_post_data
def decode_post_data(self, post_data):
result = {}
for item in post_data.split('&'):
key, _sep, value = item.partition('=')
result[key] = jsonutils.loads(urlparse.unquote_plus(value))
return result
开发者ID:yanheven,项目名称:oslo-incubator,代码行数:7,代码来源:test_policy.py
示例12: generate_asset_url
def generate_asset_url(match):
data = match.groupdict()
return ':download:`{name} <resources/{filename}>`'.format(
name=data['display'],
filename=unquote_plus(data['asset']),
)
开发者ID:coddingtonbear,项目名称:quiver-to-rst,代码行数:7,代码来源:main.py
示例13: process_key_event
def process_key_event(event, context):
processor = EncryptExtantKeys(config)
for record in event.get('Records', []):
bucket = record['s3']['bucket']['name']
key = {'Key': unquote_plus(record['s3']['object']['key']),
'Size': record['s3']['object']['size']}
version = record['s3']['object'].get('versionId')
if version is not None:
key['VersionId'] = version
# lambda event is always latest version, but IsLatest
# is not in record
key['IsLatest'] = True
method = processor.process_version
else:
method = processor.process_key
try:
result = retry(method, s3, key, bucket)
except ClientError as e:
# Ensure we know which key caused an issue
print("error %s:%s code:%s" % (
bucket, key['Key'], e.response['Error']))
raise
if not result:
return
print("remediated %s:%s" % (bucket, key['Key']))
开发者ID:SiahaanBernard,项目名称:cloud-custodian,代码行数:25,代码来源:s3crypt.py
示例14: _get_tool
def _get_tool(self, id, tool_version=None, user=None):
id = unquote_plus(id)
tool = self.app.toolbox.get_tool(id, tool_version)
if not tool:
raise exceptions.ObjectNotFound("Could not find tool with id '%s'." % id)
if not tool.allow_user_access(user):
raise exceptions.AuthenticationFailed("Access denied, please login for tool with id '%s'." % id)
return tool
开发者ID:ImmPortDB,项目名称:immport-galaxy,代码行数:8,代码来源:tools.py
示例15: test_quoter_char
def test_quoter_char(self):
"""
Test if an ASCII character is quoted correctly
"""
char = u'A'
encoded = unicode_quoter(char)
self.assertEqual(char, unquote_plus(encoded))
开发者ID:Tribler,项目名称:tribler,代码行数:9,代码来源:test_util.py
示例16: test_quoter_unichar
def test_quoter_unichar(self):
"""
Test if a unicode character is quoted correctly
"""
char = u'\u9b54'
encoded = unicode_quoter(char)
self.assertEqual(char, unquote_plus(encoded))
开发者ID:Tribler,项目名称:tribler,代码行数:9,代码来源:test_util.py
示例17: test_quote_plus_unicode_unichar
def test_quote_plus_unicode_unichar(self):
"""
Test if unicode characters are quoted correctly
"""
s = u'\u9b54\u11b3\uaf92\u1111'
encoded = quote_plus_unicode(s)
self.assertEqual(s, unquote_plus(encoded))
开发者ID:Tribler,项目名称:tribler,代码行数:9,代码来源:test_util.py
示例18: test_quote_plus_unicode_char
def test_quote_plus_unicode_char(self):
"""
Test if a ASCII characters are quoted correctly
"""
s = u'Ab09'
encoded = quote_plus_unicode(s)
self.assertEqual(s, unquote_plus(encoded))
开发者ID:Tribler,项目名称:tribler,代码行数:9,代码来源:test_util.py
示例19: __init__
def __init__(self, url, user='', password='', host='localhost',
protocol='', path='', port=0, parameters=[]):
errmsg = "".join( ("Invalid url <",url,">") )
# chop protocol
pieces = url.split('://')
if len(pieces) == 1:
url = pieces[0]
elif len(pieces) == 2:
protocol = pieces[0]
url = pieces[1]
else:
raise ValueError(errmsg)
pos = url.find('/')
if pos < 0:
server = url
else:
server = url[:pos]
path = url[pos+1:]
if '@' in server:
user,server = server.split('@')
if ':' in user:
user,password = user.split(':')
if ':' in server:
server,port = server.split(':')
port = int(port)
if server != '': host = server
if '?' in path:
path, pars = path.split('?')
parameters = [pair.split('=') for pair in pars.split('&')]
if any(len(pair) > 2 for pair in parameters):
raise ValueError(errmsg)
parameters = [[parse.unquote_plus(p) for p in pair]
for pair in parameters]
self.protocol = protocol
self.user = user
self.password = password
self.host = host
self.port = port
self.path = parse.unquote_plus(path)
self.parameters = parameters[:]
开发者ID:HMP1,项目名称:bumps,代码行数:44,代码来源:url.py
示例20: on_get
def on_get(self, external_project_id, **kw):
def secret_fields(field):
return putil.mime_types.augment_fields_with_content_types(field)
LOG.debug('Start secrets on_get '
'for project-ID %s:', external_project_id)
name = kw.get('name', '')
if name:
name = parse.unquote_plus(name)
bits = kw.get('bits', 0)
try:
bits = int(bits)
except ValueError:
# as per Github issue 171, if bits is invalid then
# the default should be used.
bits = 0
ctxt = controllers._get_barbican_context(pecan.request)
user_id = None
if ctxt:
user_id = ctxt.user
result = self.secret_repo.get_by_create_date(
external_project_id,
offset_arg=kw.get('offset', 0),
limit_arg=kw.get('limit', None),
name=name,
alg=kw.get('alg'),
mode=kw.get('mode'),
bits=bits,
suppress_exception=True,
acl_only=kw.get('acl_only', None),
user_id=user_id
)
secrets, offset, limit, total = result
if not secrets:
secrets_resp_overall = {'secrets': [],
'total': total}
else:
secrets_resp = [
hrefs.convert_to_hrefs(secret_fields(s))
for s in secrets
]
secrets_resp_overall = hrefs.add_nav_hrefs(
'secrets', offset, limit, total,
{'secrets': secrets_resp}
)
secrets_resp_overall.update({'total': total})
LOG.info(u._LI('Retrieved secret list for project: %s'),
external_project_id)
return secrets_resp_overall
开发者ID:abattye,项目名称:barbican,代码行数:56,代码来源:secrets.py
注:本文中的six.moves.urllib.parse.unquote_plus函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论