Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_name(name):
if name:
name = str(name)
else:
raise RecipeError("package name missing")
if not name_pat.match(name) or name.endswith(('.', '-', '_')):
raise RecipeError("invalid package name '%s'" % name)
seq = get_bad_seq(name)
if seq:
raise RecipeError("'%s' is not allowed in "
"package name: '%s'" % (seq, name))
def check_name(name):
if name:
name = str(name)
else:
raise RecipeError("package name missing")
if not name_pat.match(name) or name.endswith(('.', '-', '_')):
raise RecipeError("invalid package name '%s'" % name)
seq = get_bad_seq(name)
if seq:
raise RecipeError("'%s' is not allowed in "
"package name: '%s'" % (seq, name))
def check_license_family(meta):
if not PEDANTIC:
return
lf = get_field(meta, 'about/license_family',
get_field(meta, 'about/license'))
if lf not in LICENSE_FAMILIES:
print("""\
Error: license_family is invalid: %s
Note that about/license_family falls back to about/license.
Allowed license families are:""" % lf)
for x in LICENSE_FAMILIES:
print(" - %s" % x)
raise RecipeError("wrong license family")
src = meta.get('source')
if not src:
return
fn = src.get('fn')
if fn:
for ht in 'md5', 'sha1', 'sha256':
hexgigest = src.get(ht)
if hexgigest and not hash_pat[ht].match(hexgigest):
raise RecipeError("invalid hash: %s" % hexgigest)
url = src.get('url')
if url:
check_url(url)
git_url = src.get('git_url')
if git_url and (src.get('git_tag') and src.get('git_branch')):
raise RecipeError("cannot specify both git_branch and git_tag")
def check_about(meta):
summary = get_field(meta, 'about/summary')
if summary and len(summary) > 80:
msg = "summary exceeds 80 characters"
if PEDANTIC:
raise RecipeError(msg)
else:
print("Warning: %s" % msg)
for field in ('about/home', 'about/dev_url', 'about/doc_url',
'about/license_url'):
url = get_field(meta, field)
if url:
check_url(url)
check_license_family(meta)
def check_url(url):
if not url_pat.match(url):
raise RecipeError("not a valid URL: %s" % url)
def select_lines(data, namespace):
lines = []
for line in data.splitlines():
line = line.rstrip()
m = sel_pat.match(line)
if m:
if PEDANTIC:
x = m.group(1).strip()
# error on comment, unless the whole line is a comment
if '#' in x and not x.startswith('#'):
raise RecipeError("found commented selector: %s" % line)
cond = m.group(2)
if eval(cond, namespace, {}):
lines.append(m.group(1))
continue
lines.append(line)
return '\n'.join(lines) + '\n'