text
stringlengths 0
828
|
---|
return file_path + ""?%s"" % file_md5"
|
4749,"def get_relative_url(url):
|
""""""
|
Returns the relative URL from a URL. For example:
|
'http://web.net' -> ''
|
'http://web.net/' -> ''
|
'http://web.net/1222' -> '/1222'
|
'http://web.net/wsadas/asd' -> '/wsadas/asd'
|
It will never return a trailing ""/"".
|
@param url: A url to transform
|
@type url: str
|
@return: relative URL
|
""""""
|
# remove any protocol info before
|
stripped_site_url = url.replace(""://"", """")
|
baseurl = ""/"" + ""/"".join(stripped_site_url.split(""/"")[1:])
|
# remove any trailing slash (""/"")
|
if baseurl[-1] == ""/"":
|
return baseurl[:-1]
|
else:
|
return baseurl"
|
4750,"def function_arg_count(fn):
|
"""""" returns how many arguments a funciton has """"""
|
assert callable(fn), 'function_arg_count needed a callable function, not {0}'.format(repr(fn))
|
if hasattr(fn, '__code__') and hasattr(fn.__code__, 'co_argcount'):
|
return fn.__code__.co_argcount
|
else:
|
return 1"
|
4751,"def map(*args):
|
"""""" this map works just like the builtin.map, except, this one you can also:
|
- give it multiple functions to map over an iterable
|
- give it a single function with multiple arguments to run a window
|
based map operation over an iterable
|
""""""
|
functions_to_apply = [i for i in args if callable(i)]
|
iterables_to_run = [i for i in args if not callable(i)]
|
#print('functions_to_apply:',functions_to_apply)
|
#print('iterables_to_run:',iterables_to_run)
|
assert len(functions_to_apply)>0, 'at least one function needs to be given to map'
|
assert len(iterables_to_run)>0, 'no iterables were given to map'
|
# check for native map usage
|
if len(functions_to_apply) == 1 and len(iterables_to_run) >= 1 and function_arg_count(*functions_to_apply)==1:
|
if hasattr(iter([]), '__next__'): # if python 3
|
return __builtins__.map(functions_to_apply[0], *iterables_to_run)
|
else:
|
return iter(__builtins__.map(functions_to_apply[0], *iterables_to_run))
|
# ---------------------------- new logic below ----------------------------
|
# logic for a single function
|
elif len(functions_to_apply) == 1:
|
fn = functions_to_apply[0]
|
# if there is a single iterable, chop it up
|
if len(iterables_to_run) == 1:
|
return (fn(*i) for i in window(iterables_to_run[0], function_arg_count(functions_to_apply[0])))
|
# logic for more than 1 function
|
elif len(functions_to_apply) > 1 and len(iterables_to_run) == 1:
|
return multi_ops(*(iterables_to_run + functions_to_apply))
|
else:
|
raise ValueError('invalid usage of map()')"
|
4752,"def merge(left, right, how='inner', key=None, left_key=None, right_key=None,
|
left_as='left', right_as='right'):
|
"""""" Performs a join using the union join function. """"""
|
return join(left, right, how, key, left_key, right_key,
|
join_fn=make_union_join(left_as, right_as))"
|
4753,"def join(left, right, how='inner', key=None, left_key=None, right_key=None,
|
join_fn=tuple_join):
|
""""""
|
:param left: left iterable to be joined
|
:param right: right iterable to be joined
|
:param str | function key: either an attr name, dict key, or function that produces hashable value
|
:param how: 'inner', 'left', 'right', or 'outer'
|
:param join_fn: function called on joined left and right iterable items to complete join
|
:rtype: list
|
""""""
|
if key is None and (left_key is None or right_key is None):
|
raise ValueError(""Must provide either key param or both left_key and right_key"")
|
if key is not None:
|
lkey = rkey = key if callable(key) else make_key_fn(key)
|
else:
|
lkey = left_key if callable(left_key) else make_key_fn(left_key)
|
rkey = right_key if callable(right_key) else make_key_fn(right_key)
|
try:
|
join_impl = {
|
""left"": _left_join,
|
""right"": _right_join,
|
""inner"": _inner_join,
|
""outer"": _outer_join,
|
}[how]
|
except KeyError:
|
raise ValueError(""Invalid value for how: {}, must be left, right, ""
|
""inner, or outer."".format(str(how)))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.