Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_strip():
string = "foobar"
assert strip(string) == string
string = "\n foobar\nfoobar \n "
assert strip(string) == "foobar\nfoobar"
string = "\n\n\n"
assert strip(string) == ""
def test_strip():
string = "foobar"
assert strip(string) == string
string = "\n foobar\nfoobar \n "
assert strip(string) == "foobar\nfoobar"
string = "\n\n\n"
assert strip(string) == ""
def _get_pip_info(*args, **kwargs):
packages = args
pip_exec = kwargs.get("pip_exec", None)
_, out, _ = _pip.call("show", *packages, pip_exec = pip_exec,
output = True)
results = [strip(o) for o in out.split("---")]
info = dict()
for i, package in enumerate(packages):
result = results[i]
detail = dict((kebab_case(k), v) \
for k, v in \
iteritems(
dict([(s + [""]) if len(s) == 1 else s \
for s in [re.split(r":\s?", o, maxsplit = 1) \
for o in result.split("\n")]]
)
)
)
code = proc.wait()
if code and raise_err:
raise PopenError(code, command)
if output:
output, error = proc.communicate()
if output:
output = safe_decode(output)
output = strip(output)
if error:
error = safe_decode(error)
error = strip(error)
if quiet:
return code
else:
return code, output, error
else:
return code
env = environ,
cwd = directory,
shell = shell
)
code = proc.wait()
if code and raise_err:
raise PopenError(code, command)
if output:
output, error = proc.communicate()
if output:
output = safe_decode(output)
output = strip(output)
if error:
error = safe_decode(error)
error = strip(error)
if quiet:
return code
else:
return code, output, error
else:
return code
def _get_queries(buffer):
queries = [ ]
lines = buffer.split(";")
for line in lines:
line = strip(line)
queries.append(line)
return queries
def _render_yaml(packages):
try:
import yaml
content = _render_json(packages)
dict_ = dict()
for details in content:
name = details.pop("name")
dict_[name] = details
string = strip(yaml.safe_dump(dict_))
return string
except ImportError:
raise ValueError((
"Unable to import yaml. "
"Please install pyyaml. https://github.com/yaml/pyyaml."
def _render_dependency_tree(packages):
rendered = [ ]
for package in packages:
dependencies = package.dependency_tree
string = dependencies.render(indent = 4,
formatter = lambda package: _format_package(package)
)
sanitized = strip(string)
rendered.append(sanitized)
string = strip("\n".join(rendered))
return string