text
stringlengths
0
828
'urlbase?param1=value1&param2=value2'
@param urlbase: base url (e.g. config.CFG_SITE_URL/search)
@param urlargd: dictionary of parameters. (e.g. p={'recid':3, 'of'='hb'}
@param escape_urlargd: boolean indicating if the function should escape
arguments (e.g. < becomes &lt; or "" becomes &quot;)
@param urlhash: hash string to add at the end of the link
""""""
separator = '&amp;'
output = urlbase
if urlargd:
output += '?'
if escape_urlargd:
arguments = [escape(quote(str(key)), quote=True) + '=' +
escape(quote(str(urlargd[key])), quote=True)
for key in urlargd.keys()]
else:
arguments = [str(key) + '=' + str(urlargd[key])
for key in urlargd.keys()]
output += separator.join(arguments)
if urlhash:
output += ""#"" + escape(quote(str(urlhash)))
return output"
4742,"def same_urls_p(a, b):
"""""" Compare two URLs, ignoring reorganizing of query arguments """"""
ua = list(urlparse(a))
ub = list(urlparse(b))
ua[4] = parse_qs(ua[4])
ub[4] = parse_qs(ub[4])
return ua == ub"
4743,"def urlargs_replace_text_in_arg(urlargs, regexp_argname, text_old, text_new):
""""""Analyze `urlargs' (URL CGI GET query arguments in string form)
and for each occurrence of argument matching `regexp_argname'
replace every substring `text_old' by `text_new'. Return the
resulting new URL.
Used to be used for search engine's create_nearest_terms_box,
now it is not used there anymore. It is left here in case it
will become possibly useful later.
""""""
out = """"
# parse URL arguments into a dictionary:
urlargsdict = parse_qs(urlargs)
# construct new URL arguments:
urlargsdictnew = {}
for key in urlargsdict.keys():
if re.match(regexp_argname, key): # replace `arg' by new values
urlargsdictnew[key] = []
for parg in urlargsdict[key]:
urlargsdictnew[key].append(parg.replace(text_old, text_new))
else: # keep old values
urlargsdictnew[key] = urlargsdict[key]
# build new URL for this word:
for key in urlargsdictnew.keys():
for val in urlargsdictnew[key]:
out += ""&amp;"" + key + ""="" + quote_plus(val, '')
if out.startswith(""&amp;""):
out = out[5:]
return out"
4744,"def make_user_agent_string(component=None):
""""""
Return a nice and uniform user-agent string to be used when Invenio
act as a client in HTTP requests.
""""""
ret = ""Invenio-%s (+%s; \""%s\"")"" % (cfg.get('CFG_VERSION'),
cfg.get('CFG_SITE_URL'), cfg.get('CFG_SITE_NAME'))
if component:
ret += "" %s"" % component
return ret"
4745,"def make_invenio_opener(component=None):
""""""
Return an urllib2 opener with the useragent already set in the appropriate
way.
""""""
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', make_user_agent_string(component))]
return opener"
4746,"def create_AWS_request_url(base_url, argd, _amazon_secret_access_key,
_timestamp=None):
""""""
Create a signed AWS (Amazon Web Service) request URL corresponding
to the given parameters.
Example:
>> create_AWS_request_url(""http://ecs.amazon.com/onca/xml"",
{'AWSAccessKeyID': '0000000000',
'Service': 'AWSECommerceService',
'Operation': 'ItemLookup',
'ItemID': '0679722769',
'ResponseGroup': 'ItemAttributes,Offers,Images,Review'},
""1234567890"")
@param base_url: Service URL of the Amazon store to query
@param argd: dictionary of arguments defining the query
@param _amazon_secret_access_key: your Amazon secret key
@param _timestamp: for testing purpose only (default: current timestamp)
@type base_url: string