Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_context(request, stubs=None, pkg_path=None, data_dir=None):
stubs = stubs or []
_frozen = [s.frozen for s in stubs]
_fware = [s.firmware.frozen for s in stubs if s.firmware is not None]
_stub_paths = [s.stubs for s in stubs]
_paths = setutils.IndexedSet([*_frozen, *_fware, *_stub_paths])
_context = {
'base': {},
'stubs': {
'stubs': set(stubs),
'paths': _paths,
'datadir': data_dir,
},
'reqs': {
'paths': setutils.IndexedSet([pkg_path]),
'local_paths': set([])
}
}
if request == 'all':
request = ",".join(list(_context.keys()))
mods = request.split(',')
if 'reqs' in mods and 'stubs' in mods:
def _get_context(request, stubs=None, pkg_path=None, data_dir=None):
stubs = stubs or []
_frozen = [s.frozen for s in stubs]
_fware = [s.firmware.frozen for s in stubs if s.firmware is not None]
_stub_paths = [s.stubs for s in stubs]
_paths = setutils.IndexedSet([*_frozen, *_fware, *_stub_paths])
_context = {
'base': {},
'stubs': {
'stubs': set(stubs),
'paths': _paths,
'datadir': data_dir,
},
'reqs': {
'paths': setutils.IndexedSet([pkg_path]),
'local_paths': set([])
}
}
if request == 'all':
request = ",".join(list(_context.keys()))
mods = request.split(',')
if 'reqs' in mods and 'stubs' in mods:
_ctx = _context['stubs'].copy()
_ctx['paths'].update(_context['reqs']['paths'])
_ctx['local_paths'] = _context['reqs']['local_paths']
return _ctx
context = {}
for m in mods:
context = {**context, **_context.get(m, {})}
return context
return _get_context
def test_drop_nones(self):
orig = {'a': 1, 'b': None, 'c': [3, None, 4, None]}
ref = {'a': 1, 'c': [3, 4]}
drop_none = lambda p, k, v: v is not None
remapped = remap(orig, visit=drop_none)
assert remapped == ref
orig = [None] * 100
remapped = remap(orig, drop_none)
assert not remapped
def test_invalid_port():
with pytest.raises(ValueError):
URL('http://reader.googlewebsite.com:neverforget')
def test_normalize_with_case():
# from RFC 3986 Section 6.2.2
url1 = URL('example://a/b/c/%7Bfoo%7D')
url2 = URL('eXAMPLE://a/./b/../b/%63/%7bfoo%7d')
assert url1 != url2
url1.normalize()
url2.normalize()
assert url1 == url2
def test_url_copy():
url = URL('http://example.com/foo?bar=baz')
url_copy = URL(url)
assert url == url_copy
def test_netloc_slashes():
# basic sanity checks
url = URL('mailto:mahmoud@hatnote.com')
assert url.scheme == 'mailto'
assert url.to_text() == 'mailto:mahmoud@hatnote.com'
url = URL('http://hatnote.com')
assert url.scheme == 'http'
assert url.to_text() == 'http://hatnote.com'
# test that unrecognized schemes stay consistent with '//'
url = URL('newscheme:a:b:c')
assert url.scheme == 'newscheme'
assert url.to_text() == 'newscheme:a:b:c'
url = URL('newerscheme://a/b/c')
assert url.scheme == 'newerscheme'
assert url.to_text() == 'newerscheme://a/b/c'
# test that reasonable guesses are made
url = URL('git+ftp://gitstub.biz/glyph/lefkowitz')
assert url.scheme == 'git+ftp'
assert url.to_text() == 'git+ftp://gitstub.biz/glyph/lefkowitz'
def test_netloc_slashes():
# basic sanity checks
url = URL('mailto:mahmoud@hatnote.com')
assert url.scheme == 'mailto'
assert url.to_text() == 'mailto:mahmoud@hatnote.com'
url = URL('http://hatnote.com')
assert url.scheme == 'http'
assert url.to_text() == 'http://hatnote.com'
# test that unrecognized schemes stay consistent with '//'
url = URL('newscheme:a:b:c')
assert url.scheme == 'newscheme'
assert url.to_text() == 'newscheme:a:b:c'
url = URL('newerscheme://a/b/c')
assert url.scheme == 'newerscheme'
assert url.to_text() == 'newerscheme://a/b/c'
# test that reasonable guesses are made
url = URL('git+ftp://gitstub.biz/glyph/lefkowitz')
assert url.scheme == 'git+ftp'
assert url.to_text() == 'git+ftp://gitstub.biz/glyph/lefkowitz'
url = URL('what+mailto:freerealestate@enotuniq.org')
assert url.scheme == 'what+mailto'
assert url.to_text() == 'what+mailto:freerealestate@enotuniq.org'
url = URL()
url.scheme = 'ztp'
url.path = '/x/y/z'
assert url.to_text() == 'ztp:/x/y/z'
def test_iri_query():
url = URL(u'http://minerals.mountain.ore/?rock=\N{SHAMROCK}')
assert url.query_params['rock'] == u'\N{SHAMROCK}'
assert url.query_params.to_text(full_quote=True).endswith(u'%E2%98%98')
def test_query_params(test_url):
url_obj = URL(test_url)
if not url_obj.query_params or url_obj.fragment:
return True
qp_text = url_obj.query_params.to_text(full_quote=True)
assert test_url.endswith(qp_text)