try:<EOL><INDENT>import ipdb as pdb<EOL><DEDENT>except ImportError:<EOL><INDENT>import pdb<EOL>print("<STR_LIT>")<EOL><DEDENT>print("<STR_LIT>")<EOL>render = lambda s: template.Template(s).render(context)<EOL>availables = get_variables(context)<EOL>pprint(availables)<EOL>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>for var in availables:<EOL><INDENT>locals()[var] = context[var]<EOL><DEDENT>pdb.set_trace()<EOL>return '<STR_LIT>'<EOL>

Start a pdb set_trace inside of the template with the context available as
'context'. Uses ipdb if available.


global pdevd_not_available<EOL>if pdevd_not_available:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>try:<EOL><INDENT>import pydevd<EOL><DEDENT>except ImportError:<EOL><INDENT>pdevd_not_available = True<EOL>return '<STR_LIT>'<EOL><DEDENT>render = lambda s: template.Template(s).render(context)<EOL>availables = get_variables(context)<EOL>for var in availables:<EOL><INDENT>locals()[var] = context[var]<EOL><DEDENT>try:<EOL><INDENT>pydevd.settrace()<EOL><DEDENT>except socket.error:<EOL><INDENT>pdevd_not_available = True<EOL><DEDENT>return '<STR_LIT>'<EOL>


for i in iterable:<EOL><INDENT>if isinstance(i, Iterable) and not isinstance(i, string_types):<EOL><INDENT>for sub_i in _flatten(i):<EOL><INDENT>yield sub_i<EOL><DEDENT><DEDENT>else:<EOL><INDENT>yield i<EOL><DEDENT><DEDENT>

Given an iterable with nested iterables, generate a flat iterable


return sorted(set(_flatten(context.dicts)))<EOL>

Given a context, return a sorted list of variable names in the context


var_data = {}<EOL>module = getattr(var, '<STR_LIT>', '<STR_LIT>')<EOL>kls = getattr(getattr(var, '<STR_LIT>', '<STR_LIT>'), '<STR_LIT>', '<STR_LIT>')<EOL>if module:<EOL><INDENT>var_data['<STR_LIT>'] = module<EOL><DEDENT>if kls:<EOL><INDENT>var_data['<STR_LIT>'] = kls<EOL><DEDENT>for attr in get_attributes(var):<EOL><INDENT>value = _get_detail_value(var, attr)<EOL>if value is not None:<EOL><INDENT>var_data[attr] = value<EOL><DEDENT><DEDENT>return var_data<EOL>

Given a variable inside the context, obtain the attributes/callables,
their values where possible, and the module name and class name if possible


value = getattr(var, attr)<EOL>kls = getattr(getattr(value, '<STR_LIT>', '<STR_LIT>'), '<STR_LIT>', '<STR_LIT>')<EOL>if kls in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>return kls<EOL><DEDENT>if callable(value):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return value<EOL>

Given a variable and one of its attributes that are available inside of
a template, return its 'method' if it is a callable, its class name if it
is a model manager, otherwise return its value


is_valid = partial(is_valid_in_template, var)<EOL>return list(filter(is_valid, dir(var)))<EOL>

Given a varaible, return the list of attributes that are available inside
of a template


<EOL>if attr.startswith('<STR_LIT:_>'):<EOL><INDENT>return False<EOL><DEDENT>try:<EOL><INDENT>value = getattr(var, attr)<EOL><DEDENT>except:<EOL><INDENT>return False<EOL><DEDENT>if isroutine(value):<EOL><INDENT>if getattr(value, '<STR_LIT>', False):<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>argspec = getargspec(value)<EOL>num_args = len(argspec.args) if argspec.args else <NUM_LIT:0><EOL>num_defaults = len(argspec.defaults) if argspec.defaults else <NUM_LIT:0><EOL>if num_args - num_defaults > <NUM_LIT:1>:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>return True<EOL>

Given a variable and one of its attributes, determine if the attribute is
accessible inside of a Django template and return True or False accordingly


path = os.path.abspath(os.path.dirname(__file__))<EOL>filepath = os.path.join(path, filename)<EOL>try:<EOL><INDENT>return open(filepath).read()<EOL><DEDENT>except IOError:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>


def volcano(differential_dfs, title='<STR_LIT>', scripts_mode="<STR_LIT>", data_mode="<STR_LIT>",<EOL>organism="<STR_LIT>", q_value_column_name="<STR_LIT:q>", log2FC_column_name="<STR_LIT>",<EOL>output_dir="<STR_LIT:.>", filename="<STR_LIT>", version=this_version):

output_dir = Path(output_dir)<EOL>output_dir.mkdir(exist_ok=True, parents=True)<EOL>if isinstance(differential_dfs, pd.DataFrame):<EOL><INDENT>differential_dfs = {'<STR_LIT>': differential_dfs}<EOL><DEDENT>for name, df in differential_dfs.items():<EOL><INDENT>df = df[[q_value_column_name, log2FC_column_name]]<EOL>df.columns = ['<STR_LIT:q>', '<STR_LIT>']<EOL>df = df.round(<NUM_LIT:2>)<EOL>_verify_differential_df(df)<EOL>del differential_dfs[name]<EOL>differential_dfs[_sanitize(name)] = df<EOL><DEDENT>names_and_differentials = f"<STR_LIT>"<EOL>data_block = _data_block(data_mode, [('<STR_LIT>', names_and_differentials)], output_dir, include_gene_sets=False, organism=organism)<EOL>scripts = third_party_scripts + [CDN_url(version)+"<STR_LIT>", CDN_url(version)+"<STR_LIT>", CDN_url(version)+"<STR_LIT>"]<EOL>scripts_block = _scripts_block(scripts, scripts_mode, output_dir)<EOL>html = templateEnv.get_template('<STR_LIT>').render(title=title, scripts_block=scripts_block+'<STR_LIT:\n>'+data_block, organism="<STR_LIT>")<EOL>(output_dir / filename).write_text(html)<EOL>return (output_dir / filename).resolve()<EOL>

Arguments:
    differential_dfs (dict or pandas.DataFrame): python dict of names to pandas dataframes, or a single dataframe, indexed by gene symbols which must have columns named log2FC and qval.
    title (str): The title of the plot (to be embedded in the html).
    scripts_mode (str): Choose from [`"CDN"`, `"directory"`, `"inline"`]:

        - `"CDN"` compiles a single HTML page with links to scripts hosted on a CDN,

        - `"directory"` compiles a directory with all scripts locally cached,

        - `"inline"` compiles a single HTML file with all scripts/styles inlined.

    data_mode (str): Choose from ["directory", "inline"]:

        - "directory" compiles a directory with all data locally cached,

        - "inline" compiles a single HTML file with all data inlined.

    organism (str): `"human"` or `"mouse"`
    q_value_column_name (str):
    log2FC_column_name (str):
    output_dir (str): the directory in which to output the file
    filename (str): the filename of the output file
    version (str): the version of the javascripts to use.
        Leave the default to pin the version, or choose "latest" to get updates,
        or choose part of the version string to get minor updates.
Returns:
    Path: The filepath which the html was outputted to.


def bar(differential_dfs, title='<STR_LIT>', scripts_mode="<STR_LIT>", data_mode="<STR_LIT>",<EOL>organism="<STR_LIT>", q_value_column_name="<STR_LIT:q>", log2FC_column_name="<STR_LIT>",<EOL>output_dir="<STR_LIT:.>", filename="<STR_LIT>", version=this_version):

output_dir = Path(output_dir)<EOL>output_dir.mkdir(exist_ok=True, parents=True)<EOL>if isinstance(differential_dfs, pd.DataFrame):<EOL><INDENT>differential_dfs = {'<STR_LIT>': differential_dfs}<EOL><DEDENT>for name, df in differential_dfs.items():<EOL><INDENT>df = df[[q_value_column_name, log2FC_column_name]]<EOL>df.columns = ['<STR_LIT:q>', '<STR_LIT>']<EOL>df = df.round(<NUM_LIT:2>)<EOL>_verify_differential_df(df)<EOL>del differential_dfs[name]<EOL>differential_dfs[_sanitize(name)] = df<EOL><DEDENT>names_and_differentials = f"<STR_LIT>"<EOL>data_block = _data_block(data_mode, [('<STR_LIT>', names_and_differentials)], output_dir, organism=organism)<EOL>scripts = third_party_scripts + [ CDN_url(version)+"<STR_LIT>", CDN_url(version)+"<STR_LIT>"]<EOL>scripts_block = _scripts_block(scripts, scripts_mode, output_dir)<EOL>html = templateEnv.get_template('<STR_LIT>').render(title=title, scripts_block=scripts_block+'<STR_LIT:\n>'+data_block)<EOL>(output_dir / filename).write_text(html)<EOL>return (output_dir / filename).resolve()<EOL>


def braid(genes_by_samples_matrix, sample_attributes, title='<STR_LIT>', scripts_mode="<STR_LIT>", data_mode="<STR_LIT>",<EOL>organism="<STR_LIT>", output_dir="<STR_LIT:.>", filename="<STR_LIT>", version=this_version):

output_dir = Path(output_dir)<EOL>output_dir.mkdir(exist_ok=True, parents=True)<EOL>_verify_sample_by_genes_matrix(genes_by_samples_matrix)<EOL>_verify_sample_attributes(genes_by_samples_matrix, sample_attributes)<EOL>genes_by_samples_matrix = genes_by_samples_matrix.round(<NUM_LIT:2>)<EOL>matrix = f"<STR_LIT>"<EOL>classes = f"<STR_LIT>"<EOL>data_block = _data_block(data_mode, [('<STR_LIT>', matrix), ('<STR_LIT>', classes)], output_dir, organism=organism)<EOL>scripts = third_party_scripts + [CDN_url(version)+"<STR_LIT>", CDN_url(version)+"<STR_LIT>", CDN_url(version)+"<STR_LIT>"]<EOL>scripts_block = _scripts_block(scripts, scripts_mode, output_dir)<EOL>html = templateEnv.get_template('<STR_LIT>').render(title=title, scripts_block=scripts_block+'<STR_LIT:\n>'+data_block)<EOL>(output_dir / filename).write_text(html)<EOL>return (output_dir / filename).resolve()<EOL>

Arguments:
    genes_by_samples_matrix (pandas.DataFrame): dataframe indexed by genes, columns are samples
    sample_attributes (pandas.DataFrame): dataframe indexed by samples, columns are sample attributes (e.g. classes)
    title (str): The title of the plot (to be embedded in the html).
    scripts_mode (str): Choose from [`"CDN"`, `"directory"`, `"inline"`]:

        - `"CDN"` compiles a single HTML page with links to scripts hosted on a CDN,

        - `"directory"` compiles a directory with all scripts locally cached,

        - `"inline"` compiles a single HTML file with all scripts/styles inlined.

    data_mode (str): Choose from ["directory", "inline"]:

        - "directory" compiles a directory with all data locally cached,

        - "inline" compiles a single HTML file with all data inlined.

    organism (str): `"human"` or `"mouse"`
    output_dir (str): the directory in which to output the file
    filename (str): the filename of the output file
    version (str): the version of the javascripts to use.
        Leave the default to pin the version, or choose "latest" to get updates,
        or choose part of the version string to get minor updates.
Returns:
    Path: The filepath which the html was outputted to.


def heatmap(genes_by_samples_matrix, sample_attributes, title='<STR_LIT>', scripts_mode="<STR_LIT>", data_mode="<STR_LIT>",<EOL>organism="<STR_LIT>", separate_zscore_by=["<STR_LIT>"],<EOL>output_dir="<STR_LIT:.>", filename="<STR_LIT>", version=this_version):

output_dir = Path(output_dir)<EOL>output_dir.mkdir(exist_ok=True, parents=True)<EOL>_verify_sample_by_genes_matrix(genes_by_samples_matrix)<EOL>_verify_sample_attributes(genes_by_samples_matrix, sample_attributes)<EOL>genes_by_samples_matrix = genes_by_samples_matrix.round(<NUM_LIT:2>)<EOL>matrix = f"<STR_LIT>"<EOL>classes = f"<STR_LIT>"<EOL>data_block = _data_block(data_mode, [('<STR_LIT>', matrix), ('<STR_LIT>', classes)], output_dir, organism=organism)<EOL>scripts = third_party_scripts + [CDN_url(version)+"<STR_LIT>", CDN_url(version)+"<STR_LIT>", CDN_url(version)+"<STR_LIT>"]<EOL>scripts_block = _scripts_block(scripts, scripts_mode, output_dir)<EOL>html = templateEnv.get_template('<STR_LIT>').render(title=title, scripts_block=scripts_block+'<STR_LIT:\n>'+data_block, separate_zscore_by=separate_zscore_by)<EOL>(output_dir / filename).write_text(html)<EOL>return (output_dir / filename).resolve()<EOL>

Arguments:
    genes_by_samples_matrix (pandas.DataFrame): dataframe indexed by genes, columns are samples
    sample_attributes (pandas.DataFrame): dataframe indexed by samples, columns are sample attributes (e.g. classes)
    title (str): The title of the plot (to be embedded in the html).
    scripts_mode (str): Choose from [`"CDN"`, `"directory"`, `"inline"`]:

        - `"CDN"` compiles a single HTML page with links to scripts hosted on a CDN,

        - `"directory"` compiles a directory with all scripts locally cached,

        - `"inline"` compiles a single HTML file with all scripts/styles inlined.

    data_mode (str): Choose from ["directory", "inline"]:

        - "directory" compiles a directory with all data locally cached,

        - "inline" compiles a single HTML file with all data inlined.

    organism (str): `"human"` or `"mouse"`
    separate_zscore_by (list):
    output_dir (str): the directory in which to output the file
    filename (str): the filename of the output file
    version (str): the version of the javascripts to use.
        Leave the default to pin the version, or choose "latest" to get updates,
        or choose part of the version string to get minor updates.
Returns:
    Path: The filepath which the html was outputted to.


def graph(networkx_graph, title='<STR_LIT>', scripts_mode="<STR_LIT>", data_mode="<STR_LIT>",<EOL>output_dir="<STR_LIT:.>", filename="<STR_LIT>", version=this_version):

output_dir = Path(output_dir)<EOL>output_dir.mkdir(exist_ok=True, parents=True)<EOL>scripts = third_party_scripts + [CDN_url(version)+"<STR_LIT>", CDN_url(version)+"<STR_LIT>"]<EOL>scripts_block = _scripts_block(scripts, scripts_mode, output_dir)<EOL>graph_json = nx_json.node_link_data(networkx_graph)<EOL>for node in graph_json['<STR_LIT>']:<EOL><INDENT>for attr, val in node.items():<EOL><INDENT>if isinstance(val, numbers.Number):<EOL><INDENT>node[attr] = round(val, <NUM_LIT:2>)<EOL><DEDENT><DEDENT><DEDENT>for link in graph_json['<STR_LIT>']:<EOL><INDENT>for attr, val in link.items():<EOL><INDENT>if isinstance(val, numbers.Number):<EOL><INDENT>link[attr] = round(val, <NUM_LIT:2>)<EOL><DEDENT><DEDENT><DEDENT>graph_json = f"<STR_LIT>"<EOL>data_block = _data_block(data_mode, [('<STR_LIT>', graph_json)], output_dir)<EOL>html = templateEnv.get_template('<STR_LIT>').render(title=title, scripts_block=scripts_block+'<STR_LIT:\n>'+data_block, nodes=networkx_graph.nodes())<EOL>(output_dir / filename).write_text(html)<EOL>return (output_dir / filename).resolve()<EOL>

Arguments:
    networkx_graph (networkx.Graph): any instance of networkx.Graph
    title (str): The title of the plot (to be embedded in the html).
    scripts_mode (str): Choose from [`"CDN"`, `"directory"`, `"inline"`]:

        - `"CDN"` compiles a single HTML page with links to scripts hosted on a CDN,

        - `"directory"` compiles a directory with all scripts locally cached,

        - `"inline"` compiles a single HTML file with all scripts/styles inlined.

    data_mode (str): Choose from ["directory", "inline"]:

        - "directory" compiles a directory with all data locally cached,

        - "inline" compiles a single HTML file with all data inlined.

    output_dir (str): the directory in which to output the file
    filename (str): the filename of the output file
    version (str): the version of the javascripts to use.
        Leave the default to pin the version, or choose "latest" to get updates,
        or choose part of the version string to get minor updates.
Returns:
    Path: The filepath which the html was outputted to.


ver = Version()<EOL>ver.conn = self.conn<EOL>ver.attrs = {<EOL>'<STR_LIT>': self.attrs['<STR_LIT:id>'],<EOL>}<EOL>ver.save()<EOL>return ver<EOL>

Create a new version under this service.


vcl = VCL()<EOL>vcl.conn = self.conn<EOL>vcl.attrs = {<EOL>'<STR_LIT>': self.attrs['<STR_LIT>'],<EOL>'<STR_LIT:version>': self.attrs['<STR_LIT>'],<EOL>'<STR_LIT:name>': name,<EOL>'<STR_LIT:content>': content,<EOL>}<EOL>vcl.save()<EOL>return vcl<EOL>


try:<EOL><INDENT>activate = options.virtualenv.activate_cmd<EOL><DEDENT>except AttributeError:<EOL><INDENT>activate = None<EOL><DEDENT>if activate is None:<EOL><INDENT>virtualenv = path(os.environ.get('<STR_LIT>', '<STR_LIT>'))<EOL>if not virtualenv:<EOL><INDENT>virtualenv = options.paved.cwd<EOL><DEDENT>else:<EOL><INDENT>virtualenv = path(virtualenv)<EOL><DEDENT>activate = virtualenv / '<STR_LIT>' / '<STR_LIT>'<EOL>if activate.exists():<EOL><INDENT>info('<STR_LIT>' % activate)<EOL>options.setdotted('<STR_LIT>', '<STR_LIT>' % activate)<EOL><DEDENT><DEDENT>

Attempt to set the virtualenv activate command, if it hasn't been specified.


kwargs['<STR_LIT:action>'] = '<STR_LIT>'<EOL>kwargs['<STR_LIT>'] = '<STR_LIT>'<EOL>return _walkWithAction(*patterns, **kwargs)<EOL>

Remove all files under the given path with the given patterns.


Remove all directories under the current path with the given patterns.


def shv(command, capture=False, ignore_error=False, cwd=None):

_setVirtualEnv()<EOL>try:<EOL><INDENT>command = "<STR_LIT>" % (options.virtualenv.activate_cmd, command)<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>return bash(command, capture=capture, ignore_error=ignore_error, cwd=cwd)<EOL>

Run the given command inside the virtual environment, if available:


stack = [(dst, src)]<EOL>def isdict(o):<EOL><INDENT>return hasattr(o, '<STR_LIT>')<EOL><DEDENT>while stack:<EOL><INDENT>current_dst, current_src = stack.pop()<EOL>for key in current_src:<EOL><INDENT>if key not in current_dst:<EOL><INDENT>current_dst[key] = current_src[key]<EOL><DEDENT>else:<EOL><INDENT>if isdict(current_src[key]) and isdict(current_dst[key]):<EOL><INDENT>stack.append((current_dst[key], current_src[key]))<EOL><DEDENT>else:<EOL><INDENT>current_dst[key] = current_src[key]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return dst<EOL>

Recursively update the destination dict-like object with the source dict-like object.

    Useful for merging options and Bunches together!

    Based on:
    http://code.activestate.com/recipes/499335-recursively-update-a-dictionary-without-hitting-py/#c1


download_cache = ('<STR_LIT>' % options.paved.pip.download_cache) if options.paved.pip.download_cache else '<STR_LIT>'<EOL>shv('<STR_LIT>' % (download_cache, '<STR_LIT:U+0020>'.join(args)))<EOL>

Send the given arguments to `pip install`.


shv('<STR_LIT>' % ('<STR_LIT:U+0020>'.join(args)))<EOL>

Send the given arguments to `easy_install`.


<EOL>args = '<STR_LIT:U+0020>'.join(args) if args else "<STR_LIT>"<EOL>call_manage(args)<EOL>

Run the provided commands against Django's manage.py

    `options.paved.django.settings`: the dotted path to the django
        project module containing settings.

    `options.paved.django.manage_py`: the path where the django
        project's `manage.py` resides.


def call_manage(cmd, capture=False, ignore_error=False):

settings = (options.paved.django.settings or<EOL>os.environ.get('<STR_LIT>'))<EOL>if settings is None:<EOL><INDENT>raise BuildFailure("<STR_LIT>")<EOL><DEDENT>manage_py = options.paved.django.manage_py<EOL>if manage_py is None:<EOL><INDENT>manage_py = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>manage_py = path(manage_py)<EOL>manage_py = '<STR_LIT>'.format(**locals())<EOL><DEDENT>return util.shv('<STR_LIT>'.format(**locals()), capture=capture, ignore_error=ignore_error)<EOL>

Utility function to run commands against Django's `django-admin.py`/`manage.py`.

    `options.paved.django.project`: the path to the django project
        files (where `settings.py` typically resides).
        Will fall back to a DJANGO_SETTINGS_MODULE environment variable.

    `options.paved.django.manage_py`: the path where the django
        project's `manage.py` resides.


cmd = args and '<STR_LIT>' % '<STR_LIT:U+0020>'.join(options.args) or '<STR_LIT>'<EOL>call_manage(cmd)<EOL>for fixture in options.paved.django.syncdb.fixtures:<EOL><INDENT>call_manage("<STR_LIT>" % fixture)<EOL><DEDENT>

Update the database with model schema. Shorthand for `paver manage syncdb`.


cmd = '<STR_LIT>'<EOL>try:<EOL><INDENT>import django_extensions<EOL>cmd = '<STR_LIT>'<EOL><DEDENT>except ImportError:<EOL><INDENT>info("<STR_LIT>")<EOL><DEDENT>call_manage(cmd)<EOL>

Run the ipython shell. Shorthand for `paver manage shell`.

    Uses `django_extensions <http://pypi.python.org/pypi/django-extensions/0.5>`, if
    available, to provide `shell_plus`.


cmd = options.paved.django.runserver<EOL>if cmd == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>import django_extensions<EOL><DEDENT>except ImportError:<EOL><INDENT>info("<STR_LIT>")<EOL>cmd = '<STR_LIT>'<EOL><DEDENT><DEDENT>port = options.paved.django.runserver_port<EOL>if port:<EOL><INDENT>cmd = '<STR_LIT>' % (cmd, port)<EOL><DEDENT>call_manage(cmd)<EOL>

Run the dev server.

    Uses `django_extensions <http://pypi.python.org/pypi/django-extensions/0.5>`, if
    available, to provide `runserver_plus`.

    Set the command to use with `options.paved.django.runserver`
    Set the port to use with `options.paved.django.runserver_port`


try:<EOL><INDENT>import south<EOL>cmd = args and '<STR_LIT>' % '<STR_LIT:U+0020>'.join(options.args) or '<STR_LIT>'<EOL>call_manage(cmd)<EOL><DEDENT>except ImportError:<EOL><INDENT>error('<STR_LIT>')<EOL><DEDENT>


<EOL>setup = options.get('<STR_LIT>')<EOL>packages = options.get('<STR_LIT>') if setup else None<EOL>if packages:<EOL><INDENT>dirs = [x for x in packages if '<STR_LIT:.>' not in x]<EOL><DEDENT>else:<EOL><INDENT>dirs = ['<STR_LIT:.>']<EOL><DEDENT>ls=[]<EOL>for d in dirs:<EOL><INDENT>ls += list(path(d).walkfiles())<EOL><DEDENT>files='<STR_LIT:U+0020>'.join(ls)<EOL>param=options.paved.pycheck.sloccount.param<EOL>sh('<STR_LIT>'.format(param=param, files=files))<EOL>

Print "Source Lines of Code" and export to file.

    Export is hudson_ plugin_ compatible: sloccount.sc

    requirements:
     - sloccount_ should be installed.
     - tee and pipes are used

    options.paved.pycheck.sloccount.param

    .. _sloccount: http://www.dwheeler.com/sloccount/
    .. _hudson: http://hudson-ci.org/
    .. _plugin: http://wiki.hudson-ci.org/display/HUDSON/SLOCCount+Plugin


<EOL>packages = [x for x in options.setup.packages if '<STR_LIT:.>' not in x]<EOL>sh('<STR_LIT>'.format(param=options.paved.pycheck.findimports.param, files='<STR_LIT:U+0020>'.join(packages)))<EOL>

print python module dependencies by findimports.

    requirements:
     - findimports_ should be installed. ``easy_install findimports``

    options.paved.pycheck.findimports.param

    .. _findimports: http://pypi.python.org/pypi/findimports


<EOL>packages = [x for x in options.setup.packages if '<STR_LIT:.>' not in x]<EOL>sh('<STR_LIT>'.format(param=options.paved.pycheck.pyflakes.param, files='<STR_LIT:U+0020>'.join(packages)))<EOL>

passive check of python programs by pyflakes.

    requirements:
     - pyflakes_ should be installed. ``easy_install pyflakes``

    options.paved.pycheck.pyflakes.param

    .. _pyflakes: http://pypi.python.org/pypi/pyflakes


<EOL>packages = [x for x in options.setup.packages if '<STR_LIT:.>' not in x]<EOL>sh('<STR_LIT>'.format(param=options.paved.pycheck.pychecker.param, files='<STR_LIT:U+0020>'.join(packages)))<EOL>

check of python programs by pychecker.

    requirements:
     - pychecker_ should be installed.

    options.paved.pycheck.pychecker.param

    .. _pychecker: http://pychecker.sourceforge.net/


sh('<STR_LIT>'.format(param=options.paved.pycheck.nose.param))<EOL>

Run unit tests using nosetests.

    requirements:
     - nose_ should be installed.

    options.paved.pycheck.nose.param

    .. _nose: http://somethingaboutorange.com/mrl/projects/nose/1.0.0/


@task<EOL>@needs('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>def pycheckall():


info("<STR_LIT>", options.paved.clean.patterns)<EOL>for wd in options.paved.clean.dirs:<EOL><INDENT>info("<STR_LIT>", wd)<EOL>for p in options.paved.clean.patterns:<EOL><INDENT>for f in wd.walkfiles(p):<EOL><INDENT>f.remove()<EOL><DEDENT><DEDENT><DEDENT>

Clean up extra files littering the source tree.

    options.paved.clean.dirs: directories to search recursively
    options.paved.clean.patterns: patterns to search for and remove


x = json.dumps(environment.options,<EOL>indent=<NUM_LIT:4>,<EOL>sort_keys=True,<EOL>skipkeys=True,<EOL>cls=MyEncoder)<EOL>print(x)<EOL>

print paver options.

    Prettified by json.
    `long_description` is removed


conn = boto.connect_s3(options.paved.s3.access_id, options.paved.s3.secret)<EOL>try:<EOL><INDENT>bucket = conn.get_bucket(bucket)<EOL><DEDENT>except boto.exception.S3ResponseError:<EOL><INDENT>bucket = conn.create_bucket(bucket)<EOL><DEDENT>return bucket<EOL>

Opens connection to S3 returning bucket and key


def upload_s3(file_path, bucket_name, file_key, force=False, acl='<STR_LIT>'):

file_path = path(file_path)<EOL>bucket = open_s3(bucket_name)<EOL>if file_path.isdir():<EOL><INDENT>paths = file_path.listdir()<EOL>paths_keys = list(zip(paths, ['<STR_LIT>' % (file_key, p.name) for p in paths]))<EOL><DEDENT>else:<EOL><INDENT>paths_keys = [(file_path, file_key)]<EOL><DEDENT>for p, k in paths_keys:<EOL><INDENT>headers = {}<EOL>s3_key = bucket.get_key(k)<EOL>if not s3_key:<EOL><INDENT>from boto.s3.key import Key<EOL>s3_key = Key(bucket, k)<EOL><DEDENT>content_type = mimetypes.guess_type(p)[<NUM_LIT:0>]<EOL>if content_type:<EOL><INDENT>headers['<STR_LIT:Content-Type>'] = content_type<EOL><DEDENT>file_size = p.stat().st_size<EOL>file_data = p.bytes()<EOL>file_md5, file_md5_64 = s3_key.get_md5_from_hexdigest(hashlib.md5(file_data).hexdigest())<EOL>if s3_key.etag:<EOL><INDENT>s3_md5 = s3_key.etag.replace('<STR_LIT:">', '<STR_LIT>')<EOL>if s3_md5 == file_md5:<EOL><INDENT>info('<STR_LIT>' % file_path)<EOL>continue<EOL><DEDENT>elif not force:<EOL><INDENT>s3_datetime = datetime.datetime(*time.strptime(<EOL>s3_key.last_modified, '<STR_LIT>')[<NUM_LIT:0>:<NUM_LIT:6>])<EOL>local_datetime = datetime.datetime.utcfromtimestamp(p.stat().st_mtime)<EOL>if local_datetime < s3_datetime:<EOL><INDENT>info("<STR_LIT>""<STR_LIT>" % (file_key))<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>info("<STR_LIT>" % (file_key))<EOL>try:<EOL><INDENT>s3_key.set_contents_from_string(file_data, headers, policy=acl, replace=True, md5=(file_md5, file_md5_64))<EOL><DEDENT>except Exception as e:<EOL><INDENT>error("<STR_LIT>" % e)<EOL>raise<EOL><DEDENT><DEDENT>


def download_s3(bucket_name, file_key, file_path, force=False):

file_path = path(file_path)<EOL>bucket = open_s3(bucket_name)<EOL>file_dir = file_path.dirname()<EOL>file_dir.makedirs()<EOL>s3_key = bucket.get_key(file_key)<EOL>if file_path.exists():<EOL><INDENT>file_data = file_path.bytes()<EOL>file_md5, file_md5_64 = s3_key.get_md5_from_hexdigest(hashlib.md5(file_data).hexdigest())<EOL>try:<EOL><INDENT>s3_md5 = s3_key.etag.replace('<STR_LIT:">', '<STR_LIT>')<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>if s3_md5 == file_md5:<EOL><INDENT>info('<STR_LIT>' % file_path)<EOL>return<EOL><DEDENT>elif not force:<EOL><INDENT>s3_datetime = datetime.datetime(*time.strptime(<EOL>s3_key.last_modified, '<STR_LIT>')[<NUM_LIT:0>:<NUM_LIT:6>])<EOL>local_datetime = datetime.datetime.utcfromtimestamp(file_path.stat().st_mtime)<EOL>if s3_datetime < local_datetime:<EOL><INDENT>info("<STR_LIT>" % (file_key))<EOL>return<EOL><DEDENT><DEDENT><DEDENT><DEDENT>info("<STR_LIT>" % (file_key))<EOL>try:<EOL><INDENT>with open(file_path, '<STR_LIT:w>') as fo:<EOL><INDENT>s3_key.get_contents_to_file(fo)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>error("<STR_LIT>" % e)<EOL>raise<EOL><DEDENT>


sh('<STR_LIT>' % '<STR_LIT:U+0020>'.join(targets), cwd=options.paved.docs.path)<EOL>

Call the Sphinx Makefile with the specified targets.

    `options.paved.docs.path`: the path to the Sphinx folder (where the Makefile resides).


sphinx_make(*options.paved.docs.targets)<EOL>

Make Sphinx docs.

    `options.paved.docs.path`: the path to the Sphinx folder (where the Makefile resides).

    `options.paved.docs.targets`: the Make targets to send to `sphinx_make`. Default is `html`.


Clean Sphinx docs.

    `options.paved.docs.path`: the path to the Sphinx folder (where the Makefile resides).


assert options.paved.docs.rsync_location, "<STR_LIT>"<EOL>sh('<STR_LIT>' % (path(options.paved.docs.path) / options.paved.docs.build_rel,<EOL>options.paved.docs.rsync_location))<EOL>

Upload the docs to a remote location via rsync.

    `options.paved.docs.rsync_location`: the target location to rsync files to.

    `options.paved.docs.path`: the path to the Sphinx folder (where the Makefile resides).

    `options.paved.docs.build_rel`: the path of the documentation
        build folder, relative to `options.paved.docs.path`.


<EOL>opts = options<EOL>docroot = path(opts.get('<STR_LIT>', '<STR_LIT>'))<EOL>if not docroot.exists():<EOL><INDENT>raise BuildFailure("<STR_LIT>"<EOL>% docroot)<EOL><DEDENT>builddir = docroot / opts.get("<STR_LIT>", "<STR_LIT>")<EOL>builddir=builddir / '<STR_LIT:html>'<EOL>if not builddir.exists():<EOL><INDENT>raise BuildFailure("<STR_LIT>"<EOL>% builddir)<EOL><DEDENT>nojekyll = path(builddir) / '<STR_LIT>'<EOL>nojekyll.touch()<EOL>sh('<STR_LIT>' % (builddir))<EOL>

Push Sphinx docs to github_ gh-pages branch.

     1. Create file .nojekyll
     2. Push the branch to origin/gh-pages
        after committing using ghp-import_

    Requirements:
     - easy_install ghp-import

    Options:
     - `options.paved.docs.*` is not used
     - `options.sphinx.docroot` is used (default=docs)
     - `options.sphinx.builddir` is used (default=.build)

    .. warning::
        This will DESTROY your gh-pages branch.
        If you love it, you'll want to take backups
        before playing with this. This script assumes
        that gh-pages is 100% derivative. You should
        never edit files in your gh-pages branch by hand
        if you're using this script because you will
        lose your work.

    .. _github: https://github.com
    .. _ghp-import: https://github.com/davisp/ghp-import


import webbrowser<EOL>opts = options<EOL>docroot = path(opts.get('<STR_LIT>', '<STR_LIT>'))<EOL>if not docroot.exists():<EOL><INDENT>raise BuildFailure("<STR_LIT>"<EOL>% docroot)<EOL><DEDENT>builddir = docroot / opts.get("<STR_LIT>", "<STR_LIT>")<EOL>builddir=builddir / '<STR_LIT:html>'<EOL>if not builddir.exists():<EOL><INDENT>raise BuildFailure("<STR_LIT>"<EOL>% builddir)<EOL><DEDENT>webbrowser.open(builddir / '<STR_LIT>')<EOL>

Open your web browser and display the generated html documentation.


prune = options.paved.dist.manifest.prune<EOL>graft = set()<EOL>if options.paved.dist.manifest.include_sphinx_docroot:<EOL><INDENT>docroot = options.get('<STR_LIT>', '<STR_LIT>')<EOL>graft.update([docroot])<EOL>if options.paved.dist.manifest.exclude_sphinx_builddir:<EOL><INDENT>builddir = docroot + '<STR_LIT:/>' + options.get("<STR_LIT>", "<STR_LIT>")<EOL>prune.update([builddir])<EOL><DEDENT><DEDENT>with open(options.paved.cwd / '<STR_LIT>', '<STR_LIT:w>') as fo:<EOL><INDENT>for item in graft:<EOL><INDENT>fo.write('<STR_LIT>' % item)<EOL><DEDENT>for item in options.paved.dist.manifest.include:<EOL><INDENT>fo.write('<STR_LIT>' % item)<EOL><DEDENT>for item in options.paved.dist.manifest.recursive_include:<EOL><INDENT>fo.write('<STR_LIT>' % item)<EOL><DEDENT>for item in prune:<EOL><INDENT>fo.write('<STR_LIT>' % item)<EOL><DEDENT><DEDENT>

Guarantee the existence of a basic MANIFEST.in.

    manifest doc: http://docs.python.org/distutils/sourcedist.html#manifest

    `options.paved.dist.manifest.include`: set of files (or globs) to include with the `include` directive.

    `options.paved.dist.manifest.recursive_include`: set of files (or globs) to include with the `recursive-include` directive.

    `options.paved.dist.manifest.prune`: set of files (or globs) to exclude with the `prune` directive.

    `options.paved.dist.manifest.include_sphinx_docroot`: True -> sphinx docroot is added as `graft`

    `options.paved.dist.manifest.include_sphinx_docroot`: True -> sphinx builddir is added as `prune`


@task<EOL>@needs('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>def sdist():

pass<EOL>

Overrides sdist to make sure that our setup.py is generated.


pass<EOL>


Send the given arguments to `pip install`.


Send the given arguments to `easy_install`.


messages = self.validate_creators(messages)<EOL>messages = self.validate_created(messages)<EOL>return messages<EOL>

Returns True if the fields are valid according to the SPDX standard.
        Appends user friendly messages to the messages parameter.


licenses_map = {}<EOL>with codecs.open(file_name, '<STR_LIT:rb>', encoding='<STR_LIT:utf-8>') as lics:<EOL><INDENT>licenses = json.load(lics)<EOL>version = licenses['<STR_LIT>'].split('<STR_LIT:.>')<EOL>for lic in licenses['<STR_LIT>']:<EOL><INDENT>if lic.get('<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>name = lic['<STR_LIT:name>']<EOL>identifier = lic['<STR_LIT>']<EOL>licenses_map[name] = identifier<EOL>licenses_map[identifier] = name<EOL><DEDENT><DEDENT>return version, licenses_map<EOL>

Return the licenses list version tuple and a mapping of licenses
name->id and id->name loaded from a JSON file
from https://github.com/spdx/license-list-data


return '<STR_LIT>'.format(text) if required else text<EOL>

Add parens around a license expression if `required` is True, otherwise
return `text` unmodified.


messages = self.validate_ext_doc_id(messages)<EOL>messages = self.validate_spdx_doc_uri(messages)<EOL>messages = self.validate_checksum(messages)<EOL>return messages<EOL>

Validate all fields of the ExternalDocumentRef class and update the
messages list with user friendly error messages for display.


if identifier in config.LICENSE_MAP.keys():<EOL><INDENT>return cls(config.LICENSE_MAP[identifier], identifier)<EOL><DEDENT>else:<EOL><INDENT>return cls(identifier, identifier)<EOL><DEDENT>

If identifier exists in config.LICENSE_MAP
        the full_name is retrieved from it. Otherwise
        the full_name is the same as the identifier.


if full_name in config.LICENSE_MAP.keys():<EOL><INDENT>return cls(full_name, config.LICENSE_MAP[full_name])<EOL><DEDENT>else:<EOL><INDENT>return cls(full_name, full_name)<EOL><DEDENT>

Returna new License for a full_name. If the full_name exists in
config.LICENSE_MAP the identifier is retrieved from it.
Otherwise the identifier is the same as the full_name.


messages = self.validate_version(messages)<EOL>messages = self.validate_data_lics(messages)<EOL>messages = self.validate_name(messages)<EOL>messages = self.validate_spdx_id(messages)<EOL>messages = self.validate_namespace(messages)<EOL>messages = self.validate_ext_document_references(messages)<EOL>messages = self.validate_creation_info(messages)<EOL>messages = self.validate_package(messages)<EOL>messages = self.validate_extracted_licenses(messages)<EOL>messages = self.validate_reviews(messages)<EOL>return messages<EOL>

Validate all fields of the document and update the
messages list with user friendly error messages for display.


m = cls.VERS_STR_REGEX.match(value)<EOL>if m is not None:<EOL><INDENT>return cls(int(m.group(<NUM_LIT:1>)), int(m.group(<NUM_LIT:2>)))<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Constructs a Version from a string.
        Returns None if string not in N.N form where N represents a
        number.


parser = Parser(Builder(), StandardLogger())<EOL>parser.build()<EOL>with open(infile_name) as infile:<EOL><INDENT>data = infile.read()<EOL>document, error = parser.parse(data)<EOL>if not error:<EOL><INDENT>with open(outfile_name, mode='<STR_LIT:w>') as outfile:<EOL><INDENT>write_document(document, outfile)<EOL><DEDENT>return True<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL>messages = []<EOL>document.validate(messages)<EOL>print('<STR_LIT:\n>'.join(messages))<EOL>return False<EOL><DEDENT><DEDENT>

Convert a SPDX file from tag/value format to RDF format.
Return True on sucess, False otherwise.


messages = self.validate_reviewer(messages)<EOL>messages = self.validate_review_date(messages)<EOL>return messages<EOL>

Returns True if all the fields are valid.
        Appends any error messages to messages parameter.


def write_document(document, out, validate=True):

if validate:<EOL><INDENT>messages = []<EOL>messages = document.validate(messages)<EOL>if messages:<EOL><INDENT>raise InvalidDocumentError(messages)<EOL><DEDENT><DEDENT>writer = Writer(document, out)<EOL>writer.write()<EOL>

Write an SPDX RDF document.
- document - spdx.document instance.
- out - file like object that will be written to.
Optionally `validate` the document before writing and raise
InvalidDocumentError if document.validate returns False.


chksum_node = BNode()<EOL>type_triple = (chksum_node, RDF.type, self.spdx_namespace.Checksum)<EOL>self.graph.add(type_triple)<EOL>algorithm_triple = (chksum_node, self.spdx_namespace.algorithm, Literal(chksum.identifier))<EOL>self.graph.add(algorithm_triple)<EOL>value_triple = (chksum_node, self.spdx_namespace.checksumValue, Literal(chksum.value))<EOL>self.graph.add(value_triple)<EOL>return chksum_node<EOL>

Return a node representing spdx.checksum.


if isinstance(value, utils.NoAssert):<EOL><INDENT>return self.spdx_namespace.noassertion<EOL><DEDENT>elif isinstance(value, utils.SPDXNone):<EOL><INDENT>return self.spdx_namespace.none<EOL><DEDENT>else:<EOL><INDENT>return Literal(value)<EOL><DEDENT>


<EOL>licenses = set()<EOL>self.licenses_from_tree_helper(tree, licenses)<EOL>return licenses<EOL>

Traverse conjunctions and disjunctions like trees and return a
set of all licenses in it as nodes.


node = BNode()<EOL>type_triple = (node, RDF.type, self.spdx_namespace.ConjunctiveLicenseSet)<EOL>self.graph.add(type_triple)<EOL>licenses = self.licenses_from_tree(conjunction)<EOL>for lic in licenses:<EOL><INDENT>member_triple = (node, self.spdx_namespace.member, lic)<EOL>self.graph.add(member_triple)<EOL><DEDENT>return node<EOL>

Return a node representing a conjunction of licenses.


node = BNode()<EOL>type_triple = (node, RDF.type, self.spdx_namespace.DisjunctiveLicenseSet)<EOL>self.graph.add(type_triple)<EOL>licenses = self.licenses_from_tree(disjunction)<EOL>for lic in licenses:<EOL><INDENT>member_triple = (node, self.spdx_namespace.member, lic)<EOL>self.graph.add(member_triple)<EOL><DEDENT>return node<EOL>

Return a node representing a disjunction of licenses.


if isinstance(lic, document.ExtractedLicense):<EOL><INDENT>return self.create_extracted_license(lic)<EOL><DEDENT>if lic.identifier.rstrip('<STR_LIT:+>') in config.LICENSE_MAP:<EOL><INDENT>return URIRef(lic.url)<EOL><DEDENT>else:<EOL><INDENT>matches = [l for l in self.document.extracted_licenses if l.identifier == lic.identifier]<EOL>if len(matches) != <NUM_LIT:0>:<EOL><INDENT>return self.create_extracted_license(matches[<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>raise InvalidDocumentError('<STR_LIT>'.format(lic.identifier))<EOL><DEDENT><DEDENT>

Handle single(no conjunction/disjunction) licenses.
Return the created node.


licenses = list(self.graph.triples((None, self.spdx_namespace.licenseId, lic.identifier)))<EOL>if len(licenses) != <NUM_LIT:0>:<EOL><INDENT>return licenses[<NUM_LIT:0>][<NUM_LIT:0>]  <EOL><DEDENT>else:<EOL><INDENT>license_node = BNode()<EOL>type_triple = (license_node, RDF.type, self.spdx_namespace.ExtractedLicensingInfo)<EOL>self.graph.add(type_triple)<EOL>ident_triple = (license_node, self.spdx_namespace.licenseId, Literal(lic.identifier))<EOL>self.graph.add(ident_triple)<EOL>text_triple = (license_node, self.spdx_namespace.extractedText, Literal(lic.text))<EOL>self.graph.add(text_triple)<EOL>if lic.full_name is not None:<EOL><INDENT>name_triple = (license_node, self.spdx_namespace.licenseName, self.to_special_value(lic.full_name))<EOL>self.graph.add(name_triple)<EOL><DEDENT>for ref in lic.cross_ref:<EOL><INDENT>triple = (license_node, RDFS.seeAlso, URIRef(ref))<EOL>self.graph.add(triple)<EOL><DEDENT>if lic.comment is not None:<EOL><INDENT>comment_triple = (license_node, RDFS.comment, Literal(lic.comment))<EOL>self.graph.add(comment_triple)<EOL><DEDENT>return license_node<EOL><DEDENT>

Handle extracted license.
Return the license node.


if isinstance(lic, document.LicenseConjunction):<EOL><INDENT>return self.create_conjunction_node(lic)<EOL><DEDENT>elif isinstance(lic, document.LicenseDisjunction):<EOL><INDENT>return self.create_disjunction_node(lic)<EOL><DEDENT>else:<EOL><INDENT>return self.create_license_helper(lic)<EOL><DEDENT>

Return a node representing a license.
Could be a single license (extracted or part of license list.) or
a conjunction/disjunction of licenses.


if isinstance(lic, utils.NoAssert):<EOL><INDENT>return self.spdx_namespace.noassertion<EOL><DEDENT>elif isinstance(lic, utils.SPDXNone):<EOL><INDENT>return self.spdx_namespace.none<EOL><DEDENT>else:<EOL><INDENT>return self.create_license_node(lic)<EOL><DEDENT>

Check for special values spdx:none and spdx:noassertion.
Return the term for the special value or the result of passing
license to create_license_node.


file_node = URIRef('<STR_LIT>'.format(<EOL>id=str(doc_file.spdx_id)))<EOL>type_triple = (file_node, RDF.type, self.spdx_namespace.File)<EOL>self.graph.add(type_triple)<EOL>name_triple = (file_node, self.spdx_namespace.fileName, Literal(doc_file.name))<EOL>self.graph.add(name_triple)<EOL>if doc_file.has_optional_field('<STR_LIT>'):<EOL><INDENT>comment_triple = (file_node, RDFS.comment, Literal(doc_file.comment))<EOL>self.graph.add(comment_triple)<EOL><DEDENT>if doc_file.has_optional_field('<STR_LIT:type>'):<EOL><INDENT>ftype = self.spdx_namespace[self.FILE_TYPES[doc_file.type]]<EOL>ftype_triple = (file_node, self.spdx_namespace.fileType, ftype)<EOL>self.graph.add(ftype_triple)<EOL><DEDENT>self.graph.add((file_node, self.spdx_namespace.checksum, self.create_checksum_node(doc_file.chk_sum)))<EOL>conc_lic_node = self.license_or_special(doc_file.conc_lics)<EOL>conc_lic_triple = (file_node, self.spdx_namespace.licenseConcluded, conc_lic_node)<EOL>self.graph.add(conc_lic_triple)<EOL>license_info_nodes = map(self.license_or_special, doc_file.licenses_in_file)<EOL>for lic in license_info_nodes:<EOL><INDENT>triple = (file_node, self.spdx_namespace.licenseInfoInFile, lic)<EOL>self.graph.add(triple)<EOL><DEDENT>if doc_file.has_optional_field('<STR_LIT>'):<EOL><INDENT>comment_triple = (file_node, self.spdx_namespace.licenseComments, Literal(doc_file.license_comment))<EOL>self.graph.add(comment_triple)<EOL><DEDENT>cr_text_node = self.to_special_value(doc_file.copyright)<EOL>cr_text_triple = (file_node, self.spdx_namespace.copyrightText, cr_text_node)<EOL>self.graph.add(cr_text_triple)<EOL>if doc_file.has_optional_field('<STR_LIT>'):<EOL><INDENT>notice_triple = (file_node, self.spdx_namespace.noticeText, doc_file.notice)<EOL>self.graph.add(notice_triple)<EOL><DEDENT>contrib_nodes = map(lambda c: Literal(c), doc_file.contributors)<EOL>contrib_triples = [(file_node, self.spdx_namespace.fileContributor, node) for node in contrib_nodes]<EOL>for triple in contrib_triples:<EOL><INDENT>self.graph.add(triple)<EOL><DEDENT>return file_node<EOL>


return map(self.create_file_node, self.document.files)<EOL>


subj_triples = list(self.graph.triples((None, self.spdx_namespace.fileName, Literal(doc_file.name))))<EOL>if len(subj_triples) != <NUM_LIT:1>:<EOL><INDENT>raise InvalidDocumentError('<STR_LIT>'.format(doc_file.name))<EOL><DEDENT>subject_node = subj_triples[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>for dependency in doc_file.dependencies:<EOL><INDENT>dep_triples = list(self.graph.triples((None, self.spdx_namespace.fileName, Literal(dependency))))<EOL>if len(dep_triples) == <NUM_LIT:1>:<EOL><INDENT>dep_node = dep_triples[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>dep_triple = (subject_node, self.spdx_namespace.fileDependency, dep_node)<EOL>self.graph.add(dep_triple)<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>'.format(doc_file.name, dependency))<EOL><DEDENT><DEDENT>

Handle dependencies for a single file.
- doc_file - instance of spdx.file.File.


for doc_file in self.document.files:<EOL><INDENT>self.add_file_dependencies_helper(doc_file)<EOL><DEDENT>

Add file dependencies to the graph.
Called after all files have been added.


review_node = BNode()<EOL>type_triple = (review_node, RDF.type, self.spdx_namespace.Review)<EOL>self.graph.add(type_triple)<EOL>reviewer_node = Literal(review.reviewer.to_value())<EOL>self.graph.add((review_node, self.spdx_namespace.reviewer, reviewer_node))<EOL>reviewed_date_node = Literal(review.review_date_iso_format)<EOL>reviewed_triple = (review_node, self.spdx_namespace.reviewDate, reviewed_date_node)<EOL>self.graph.add(reviewed_triple)<EOL>if review.has_comment:<EOL><INDENT>comment_node = Literal(review.comment)<EOL>comment_triple = (review_node, RDFS.comment, comment_node)<EOL>self.graph.add(comment_triple)<EOL><DEDENT>return review_node<EOL>


return map(self.create_review_node, self.document.reviews)<EOL>


annotation_node = URIRef(str(annotation.spdx_id))<EOL>type_triple = (annotation_node, RDF.type, self.spdx_namespace.Annotation)<EOL>self.graph.add(type_triple)<EOL>annotator_node = Literal(annotation.annotator.to_value())<EOL>self.graph.add((annotation_node, self.spdx_namespace.annotator, annotator_node))<EOL>annotation_date_node = Literal(annotation.annotation_date_iso_format)<EOL>annotation_triple = (annotation_node, self.spdx_namespace.annotationDate, annotation_date_node)<EOL>self.graph.add(annotation_triple)<EOL>if annotation.has_comment:<EOL><INDENT>comment_node = Literal(annotation.comment)<EOL>comment_triple = (annotation_node, RDFS.comment, comment_node)<EOL>self.graph.add(comment_triple)<EOL><DEDENT>annotation_type_node = Literal(annotation.annotation_type)<EOL>annotation_type_triple = (annotation_node, self.spdx_namespace.annotationType, annotation_type_node)<EOL>self.graph.add(annotation_type_triple)<EOL>return annotation_node<EOL>


return map(self.create_annotation_node, self.document.annotations)<EOL>


return map(lambda c: Literal(c.to_value()), self.document.creation_info.creators)<EOL>

Return a list of creator nodes.
Note: Does not add anything to the graph.


ci_node = BNode()<EOL>type_triple = (ci_node, RDF.type, self.spdx_namespace.CreationInfo)<EOL>self.graph.add(type_triple)<EOL>created_date = Literal(self.document.creation_info.created_iso_format)<EOL>created_triple = (ci_node, self.spdx_namespace.created, created_date)<EOL>self.graph.add(created_triple)<EOL>creators = self.creators()<EOL>for creator in creators:<EOL><INDENT>self.graph.add((ci_node, self.spdx_namespace.creator, creator))<EOL><DEDENT>if self.document.creation_info.has_comment:<EOL><INDENT>comment_node = Literal(self.document.creation_info.comment)<EOL>comment_triple = (ci_node, RDFS.comment, comment_node)<EOL>self.graph.add(comment_triple)<EOL><DEDENT>return ci_node<EOL>

Add and return a creation info node to graph


ext_doc_ref_node = BNode()<EOL>type_triple = (ext_doc_ref_node, RDF.type, self.spdx_namespace.ExternalDocumentRef)<EOL>self.graph.add(type_triple)<EOL>ext_doc_id = Literal(<EOL>ext_document_references.external_document_id)<EOL>ext_doc_id_triple = (<EOL>ext_doc_ref_node, self.spdx_namespace.externalDocumentId, ext_doc_id)<EOL>self.graph.add(ext_doc_id_triple)<EOL>doc_uri = Literal(<EOL>ext_document_references.spdx_document_uri)<EOL>doc_uri_triple = (<EOL>ext_doc_ref_node, self.spdx_namespace.spdxDocument, doc_uri)<EOL>self.graph.add(doc_uri_triple)<EOL>checksum_node = self.create_checksum_node(<EOL>ext_document_references.check_sum)<EOL>self.graph.add(<EOL>(ext_doc_ref_node, self.spdx_namespace.checksum, checksum_node))<EOL>return ext_doc_ref_node<EOL>


return map(self.create_external_document_ref_node,<EOL>self.document.ext_document_references)<EOL>


verif_node = BNode()<EOL>type_triple = (verif_node, RDF.type, self.spdx_namespace.PackageVerificationCode)<EOL>self.graph.add(type_triple)<EOL>value_triple = (verif_node, self.spdx_namespace.packageVerificationCodeValue, Literal(package.verif_code))<EOL>self.graph.add(value_triple)<EOL>excl_file_nodes = map(<EOL>lambda excl: Literal(excl), package.verif_exc_files)<EOL>excl_predicate = self.spdx_namespace.packageVerificationCodeExcludedFile<EOL>excl_file_triples = [(verif_node, excl_predicate, xcl_file) for xcl_file in excl_file_nodes]<EOL>for trp in excl_file_triples:<EOL><INDENT>self.graph.add(trp)<EOL><DEDENT>return verif_node<EOL>

Return a node representing package verification code.


def handle_package_literal_optional(self, package, package_node, predicate, field):

if package.has_optional_field(field):<EOL><INDENT>value = getattr(package, field, None)<EOL>value_node = self.to_special_value(value)<EOL>triple = (package_node, predicate, value_node)<EOL>self.graph.add(triple)<EOL><DEDENT>

Check if optional field is set.
If so it adds the triple (package_node, predicate, $) to the graph.
Where $ is a literal or special value term of the value of the field.


def handle_pkg_optional_fields(self, package, package_node):

self.handle_package_literal_optional(package, package_node, self.spdx_namespace.versionInfo, '<STR_LIT:version>')<EOL>self.handle_package_literal_optional(package, package_node, self.spdx_namespace.packageFileName, '<STR_LIT>')<EOL>self.handle_package_literal_optional(package, package_node, self.spdx_namespace.supplier, '<STR_LIT>')<EOL>self.handle_package_literal_optional(package, package_node, self.spdx_namespace.originator, '<STR_LIT>')<EOL>self.handle_package_literal_optional(package, package_node, self.spdx_namespace.sourceInfo, '<STR_LIT>')<EOL>self.handle_package_literal_optional(package, package_node, self.spdx_namespace.licenseComments, '<STR_LIT>')<EOL>self.handle_package_literal_optional(package, package_node, self.spdx_namespace.summary, '<STR_LIT>')<EOL>self.handle_package_literal_optional(package, package_node, self.spdx_namespace.description, '<STR_LIT:description>')<EOL>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>checksum_node = self.create_checksum_node(package.check_sum)<EOL>self.graph.add((package_node, self.spdx_namespace.checksum, checksum_node))<EOL><DEDENT>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>homepage_node = URIRef(self.to_special_value(package.homepage))<EOL>homepage_triple = (package_node, self.doap_namespace.homepage, homepage_node)<EOL>self.graph.add(homepage_triple)<EOL><DEDENT>


package_node = BNode()<EOL>type_triple = (package_node, RDF.type, self.spdx_namespace.Package)<EOL>self.graph.add(type_triple)<EOL>self.handle_pkg_optional_fields(package, package_node)<EOL>name_triple = (package_node, self.spdx_namespace.name, Literal(package.name))<EOL>self.graph.add(name_triple)<EOL>down_loc_node = (package_node, self.spdx_namespace.downloadLocation, self.to_special_value(package.download_location))<EOL>self.graph.add(down_loc_node)<EOL>verif_node = self.package_verif_node(package)<EOL>verif_triple = (package_node, self.spdx_namespace.packageVerificationCode, verif_node)<EOL>self.graph.add(verif_triple)<EOL>conc_lic_node = self.license_or_special(package.conc_lics)<EOL>conc_lic_triple = (package_node, self.spdx_namespace.licenseConcluded, conc_lic_node)<EOL>self.graph.add(conc_lic_triple)<EOL>decl_lic_node = self.license_or_special(package.license_declared)<EOL>decl_lic_triple = (package_node, self.spdx_namespace.licenseDeclared, decl_lic_node)<EOL>self.graph.add(decl_lic_triple)<EOL>licenses_from_files_nodes = map(lambda el: self.license_or_special(el), package.licenses_from_files)<EOL>lic_from_files_predicate = self.spdx_namespace.licenseInfoFromFiles<EOL>lic_from_files_triples = [(package_node, lic_from_files_predicate, node) for node in licenses_from_files_nodes]<EOL>for triple in lic_from_files_triples:<EOL><INDENT>self.graph.add(triple)<EOL><DEDENT>cr_text_node = self.to_special_value(package.cr_text)<EOL>cr_text_triple = (package_node, self.spdx_namespace.copyrightText, cr_text_node)<EOL>self.graph.add(cr_text_triple)<EOL>self.handle_package_has_file(package, package_node)<EOL>return package_node<EOL>

Return a Node representing the package.
Files must have been added to the graph before this method is called.


<EOL>return self.create_package_node(self.document.package)<EOL>

Return a node that represents the package in the graph.
Call this function to write package info.


nodes = list(self.graph.triples((None, self.spdx_namespace.fileName, Literal(pkg_file.name))))<EOL>if len(nodes) == <NUM_LIT:1>:<EOL><INDENT>return nodes[<NUM_LIT:0>][<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>raise InvalidDocumentError('<STR_LIT>' +<EOL>'<STR_LIT>'.format(pkg_file.name))<EOL><DEDENT>

Return node representing pkg_file
pkg_file should be instance of spdx.file.


def handle_package_has_file(self, package, package_node):

file_nodes = map(self.handle_package_has_file_helper, package.files)<EOL>triples = [(package_node, self.spdx_namespace.hasFile, node) for node in file_nodes]<EOL>for triple in triples:<EOL><INDENT>self.graph.add(triple)<EOL><DEDENT>

Add hasFile triples to graph.
Must be called after files have been added.


super(Writer, self).__init__(document, out)<EOL>

- document is spdx.document instance that will be written.
- out is a file-like object that will be written to.


doc_node = URIRef('<STR_LIT>')<EOL>self.graph.add((doc_node, RDF.type, self.spdx_namespace.SpdxDocument))<EOL>vers_literal = Literal(str(self.document.version))<EOL>self.graph.add((doc_node, self.spdx_namespace.specVersion, vers_literal))<EOL>data_lics = URIRef(self.document.data_license.url)<EOL>self.graph.add((doc_node, self.spdx_namespace.dataLicense, data_lics))<EOL>doc_name = URIRef(self.document.name)<EOL>self.graph.add((doc_node, self.spdx_namespace.name, doc_name))<EOL>return doc_node<EOL>

Add and return the root document node to graph.


out.write('<STR_LIT>')<EOL>for creator in sorted(creation_info.creators):<EOL><INDENT>write_value('<STR_LIT>', creator, out)<EOL><DEDENT>write_value('<STR_LIT>', creation_info.created_iso_format, out)<EOL>if creation_info.has_comment:<EOL><INDENT>write_text_value('<STR_LIT>', creation_info.comment, out)<EOL><DEDENT>


out.write('<STR_LIT>')<EOL>write_value('<STR_LIT>', review.reviewer, out)<EOL>write_value('<STR_LIT>', review.review_date_iso_format, out)<EOL>if review.has_comment:<EOL><INDENT>write_text_value('<STR_LIT>', review.comment, out)<EOL><DEDENT>

Write the fields of a single review to out.


out.write('<STR_LIT>')<EOL>write_value('<STR_LIT>', annotation.annotator, out)<EOL>write_value('<STR_LIT>', annotation.annotation_date_iso_format, out)<EOL>if annotation.has_comment:<EOL><INDENT>write_text_value('<STR_LIT>', annotation.comment, out)<EOL><DEDENT>write_value('<STR_LIT>', annotation.annotation_type, out)<EOL>write_value('<STR_LIT>', annotation.spdx_id, out)<EOL>

Write the fields of a single annotation to out.


out.write('<STR_LIT>')<EOL>write_value('<STR_LIT>', spdx_file.name, out)<EOL>write_value('<STR_LIT>', spdx_file.spdx_id, out)<EOL>if spdx_file.has_optional_field('<STR_LIT:type>'):<EOL><INDENT>write_file_type(spdx_file.type, out)<EOL><DEDENT>write_value('<STR_LIT>', spdx_file.chk_sum.to_tv(), out)<EOL>if isinstance(spdx_file.conc_lics, (document.LicenseConjunction, document.LicenseDisjunction)):<EOL><INDENT>write_value('<STR_LIT>', u'<STR_LIT>'.format(spdx_file.conc_lics), out)<EOL><DEDENT>else:<EOL><INDENT>write_value('<STR_LIT>', spdx_file.conc_lics, out)<EOL><DEDENT>for lics in sorted(spdx_file.licenses_in_file):<EOL><INDENT>write_value('<STR_LIT>', lics, out)<EOL><DEDENT>if isinstance(spdx_file.copyright, six.string_types):<EOL><INDENT>write_text_value('<STR_LIT>', spdx_file.copyright, out)<EOL><DEDENT>else:<EOL><INDENT>write_value('<STR_LIT>', spdx_file.copyright, out)<EOL><DEDENT>if spdx_file.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_text_value('<STR_LIT>', spdx_file.license_comment, out)<EOL><DEDENT>if spdx_file.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_text_value('<STR_LIT>', spdx_file.comment, out)<EOL><DEDENT>if spdx_file.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_text_value('<STR_LIT>', spdx_file.notice, out)<EOL><DEDENT>for contributor in sorted(spdx_file.contributors):<EOL><INDENT>write_value('<STR_LIT>', contributor, out)<EOL><DEDENT>for dependency in sorted(spdx_file.dependencies):<EOL><INDENT>write_value('<STR_LIT>', dependency, out)<EOL><DEDENT>names = spdx_file.artifact_of_project_name<EOL>homepages = spdx_file.artifact_of_project_home<EOL>uris = spdx_file.artifact_of_project_uri<EOL>for name, homepage, uri in sorted(zip_longest(names, homepages, uris)):<EOL><INDENT>write_value('<STR_LIT>', name, out)<EOL>if homepage is not None:<EOL><INDENT>write_value('<STR_LIT>', homepage, out)<EOL><DEDENT>if uri is not None:<EOL><INDENT>write_value('<STR_LIT>', uri, out)<EOL><DEDENT><DEDENT>


out.write('<STR_LIT>')<EOL>write_value('<STR_LIT>', package.name, out)<EOL>if package.has_optional_field('<STR_LIT:version>'):<EOL><INDENT>write_value('<STR_LIT>', package.version, out)<EOL><DEDENT>write_value('<STR_LIT>', package.download_location, out)<EOL>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_text_value('<STR_LIT>', package.summary, out)<EOL><DEDENT>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_text_value('<STR_LIT>', package.source_info, out)<EOL><DEDENT>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_value('<STR_LIT>', package.file_name, out)<EOL><DEDENT>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_value('<STR_LIT>', package.supplier, out)<EOL><DEDENT>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_value('<STR_LIT>', package.originator, out)<EOL><DEDENT>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_value('<STR_LIT>', package.check_sum.to_tv(), out)<EOL><DEDENT>write_value('<STR_LIT>', format_verif_code(package), out)<EOL>if package.has_optional_field('<STR_LIT:description>'):<EOL><INDENT>write_text_value('<STR_LIT>', package.description, out)<EOL><DEDENT>if isinstance(package.license_declared, (document.LicenseConjunction,<EOL>document.LicenseDisjunction)):<EOL><INDENT>write_value('<STR_LIT>', u'<STR_LIT>'.format(package.license_declared), out)<EOL><DEDENT>else:<EOL><INDENT>write_value('<STR_LIT>', package.license_declared, out)<EOL><DEDENT>if isinstance(package.conc_lics, (document.LicenseConjunction,<EOL>document.LicenseDisjunction)):<EOL><INDENT>write_value('<STR_LIT>', u'<STR_LIT>'.format(package.conc_lics), out)<EOL><DEDENT>else:<EOL><INDENT>write_value('<STR_LIT>', package.conc_lics, out)<EOL><DEDENT>for lics in sorted(package.licenses_from_files):<EOL><INDENT>write_value('<STR_LIT>', lics, out)<EOL><DEDENT>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_text_value('<STR_LIT>', package.license_comment, out)<EOL><DEDENT>if isinstance(package.cr_text, six.string_types):<EOL><INDENT>write_text_value('<STR_LIT>', package.cr_text, out)<EOL><DEDENT>else:<EOL><INDENT>write_value('<STR_LIT>', package.cr_text, out)<EOL><DEDENT>if package.has_optional_field('<STR_LIT>'):<EOL><INDENT>write_value('<STR_LIT>', package.homepage, out)<EOL><DEDENT>for spdx_file in sorted(package.files):<EOL><INDENT>write_separators(out)<EOL>write_file(spdx_file, out)<EOL><DEDENT>


write_value('<STR_LIT>', lics.identifier, out)<EOL>if lics.full_name is not None:<EOL><INDENT>write_value('<STR_LIT>', lics.full_name, out)<EOL><DEDENT>if lics.comment is not None:<EOL><INDENT>write_text_value('<STR_LIT>', lics.comment, out)<EOL><DEDENT>for xref in sorted(lics.cross_ref):<EOL><INDENT>write_value('<STR_LIT>', xref, out)<EOL><DEDENT>write_text_value('<STR_LIT>', lics.text, out)<EOL>


messages = []<EOL>messages = document.validate(messages)<EOL>if validate and messages:<EOL><INDENT>raise InvalidDocumentError(messages)<EOL><DEDENT>out.write('<STR_LIT>')<EOL>write_value('<STR_LIT>', str(document.version), out)<EOL>write_value('<STR_LIT>', document.data_license.identifier, out)<EOL>write_value('<STR_LIT>', document.name, out)<EOL>write_value('<STR_LIT>', '<STR_LIT>', out)<EOL>write_value('<STR_LIT>', document.namespace, out)<EOL>if document.has_comment:<EOL><INDENT>write_text_value('<STR_LIT>', document.comment, out)<EOL><DEDENT>for doc_ref in document.ext_document_references:<EOL><INDENT>doc_ref_str = '<STR_LIT:U+0020>'.join([doc_ref.external_document_id,<EOL>doc_ref.spdx_document_uri,<EOL>doc_ref.check_sum.identifier + '<STR_LIT::>' +<EOL>doc_ref.check_sum.value])<EOL>write_value('<STR_LIT>', doc_ref_str, out)<EOL><DEDENT>write_separators(out)<EOL>write_creation_info(document.creation_info, out)<EOL>write_separators(out)<EOL>for review in sorted(document.reviews):<EOL><INDENT>write_review(review, out)<EOL>write_separators(out)<EOL><DEDENT>for annotation in sorted(document.annotations):<EOL><INDENT>write_annotation(annotation, out)<EOL>write_separators(out)<EOL><DEDENT>write_package(document.package, out)<EOL>write_separators(out)<EOL>out.write('<STR_LIT>')<EOL>for lic in sorted(document.extracted_licenses):<EOL><INDENT>write_extracted_licenses(lic, out)<EOL>write_separators(out)<EOL><DEDENT>

Write an SPDX tag value document.
- document - spdx.document instance.
- out - file like object that will be written to.
Optionally `validate` the document before writing and raise
InvalidDocumentError if document.validate returns False.


symbol = '<STR_LIT>'.format(symbol)<EOL>artifact = getattr(self, symbol)<EOL>artifact.append(value)<EOL>

Add value as artifact_of_project{symbol}.


messages = self.validate_concluded_license(messages)<EOL>messages = self.validate_type(messages)<EOL>messages = self.validate_checksum(messages)<EOL>messages = self.validate_licenses_in_file(messages)<EOL>messages = self.validate_copyright(messages)<EOL>messages = self.validate_artifacts(messages)<EOL>messages = self.validate_spdx_id(messages)<EOL>return messages<EOL>

Validates the fields and appends user friendly messages
        to messages parameter if there are errors.


messages = self.validate_checksum(messages)<EOL>messages = self.validate_optional_str_fields(messages)<EOL>messages = self.validate_mandatory_str_fields(messages)<EOL>messages = self.validate_files(messages)<EOL>messages = self.validate_mandatory_fields(messages)<EOL>messages = self.validate_optional_fields(messages)<EOL>return messages<EOL>

Validate the package fields.
Append user friendly error messages to the `messages` list.


FIELDS = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT:version>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT:description>'<EOL>]<EOL>messages = self.validate_str_fields(FIELDS, True, messages)<EOL>return messages<EOL>

Fields marked as optional and of type string in class
        docstring must be of a type that provides __str__ method.


FIELDS = ['<STR_LIT:name>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>messages = self.validate_str_fields(FIELDS, False, messages)<EOL>return messages<EOL>

Fields marked as Mandatory and of type string in class
        docstring must be of a type that provides __str__ method.


def validate_str_fields(self, fields, optional, messages):

for field_str in fields:<EOL><INDENT>field = getattr(self, field_str)<EOL>if field is not None:<EOL><INDENT>attr = getattr(field, '<STR_LIT>', None)<EOL>if not callable(attr):<EOL><INDENT>messages = messages + [<EOL>'<STR_LIT>'.format(field)<EOL>]<EOL><DEDENT><DEDENT>elif not optional:<EOL><INDENT>messages = messages + [<EOL>'<STR_LIT>'.format(field_str)<EOL>]<EOL><DEDENT><DEDENT>return messages<EOL>

Helper for validate_mandatory_str_field and
        validate_optional_str_fields


if not self.doc_version_set:<EOL><INDENT>self.doc_version_set = True<EOL>m = self.VERS_STR_REGEX.match(value)<EOL>if m is None:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>doc.version = version.Version(major=int(m.group(<NUM_LIT:1>)),<EOL>minor=int(m.group(<NUM_LIT:2>)))<EOL>return True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Set the document version.
Raise exceptions:
- SPDXValueError if malformed value,
- CardinalityError if already defined,


if not self.doc_data_lics_set:<EOL><INDENT>self.doc_data_lics_set = True<EOL>res_parts = res.split('<STR_LIT:/>')<EOL>if len(res_parts) != <NUM_LIT:0>:<EOL><INDENT>identifier = res_parts[-<NUM_LIT:1>]<EOL>doc.data_license = document.License.from_identifier(identifier)<EOL><DEDENT>else:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Set the document data license.
Raise exceptions:
- SPDXValueError if malformed value,
- CardinalityError if already defined.


if not self.doc_name_set:<EOL><INDENT>doc.name = name<EOL>self.doc_name_set = True<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Sets the document name, raises CardinalityError if already defined.


def set_doc_spdx_id(self, doc, doc_spdx_id_line):

if not self.doc_spdx_id_set:<EOL><INDENT>if validations.validate_doc_spdx_id(doc_spdx_id_line):<EOL><INDENT>doc.spdx_id = doc_spdx_id_line<EOL>self.doc_spdx_id_set = True<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Sets the document SPDX Identifier.
        Raises value error if malformed value, CardinalityError
        if already defined.


def set_doc_comment(self, doc, comment):

if not self.doc_comment_set:<EOL><INDENT>self.doc_comment_set = True<EOL>doc.comment = comment<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Sets document comment, Raises CardinalityError if
        comment already set.


def set_doc_namespace(self, doc, namespace):

if not self.doc_namespace_set:<EOL><INDENT>self.doc_namespace_set = True<EOL>if validations.validate_doc_namespace(namespace):<EOL><INDENT>doc.namespace = namespace<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Sets the document namespace.
        Raise SPDXValueError if malformed value, CardinalityError
        if already defined.


<EOL>self.doc_version_set = False<EOL>self.doc_comment_set = False<EOL>self.doc_namespace_set = False<EOL>self.doc_data_lics_set = False<EOL>self.doc_name_set = False<EOL>self.doc_spdx_id_set = False<EOL>

Reset the internal state to allow building new document


if chk_sum:<EOL><INDENT>doc.ext_document_references[-<NUM_LIT:1>].check_sum = checksum.Algorithm(<EOL>'<STR_LIT>', chk_sum)<EOL><DEDENT>else:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT>

Sets the external document reference's check sum, if not already set.
chk_sum - The checksum value in the form of a string.


def set_creation_comment(self, doc, comment):

if not self.creation_comment_set:<EOL><INDENT>self.creation_comment_set = True<EOL>doc.creation_info.comment = comment<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Sets creation comment, Raises CardinalityError if
        comment already set.
        Raises SPDXValueError if not free form text.


def set_pkg_chk_sum(self, doc, chk_sum):

self.assert_package_exists()<EOL>if not self.package_chk_sum_set:<EOL><INDENT>self.package_chk_sum_set = True<EOL>doc.package.check_sum = checksum.Algorithm('<STR_LIT>', chk_sum)<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Sets the package check sum, if not already set.
        chk_sum - A string
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.


def set_pkg_source_info(self, doc, text):

self.assert_package_exists()<EOL>if not self.package_source_info_set:<EOL><INDENT>self.package_source_info_set = True<EOL>doc.package.source_info = text<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Sets the package's source information, if not already set.
        text - Free form text.
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.


def set_pkg_verif_code(self, doc, code):

self.assert_package_exists()<EOL>if not self.package_verif_set:<EOL><INDENT>self.package_verif_set = True<EOL>doc.package.verif_code = code<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Sets the package verification code, if not already set.
        code - A string.
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.


def set_pkg_excl_file(self, doc, filename):

self.assert_package_exists()<EOL>doc.package.add_exc_file(filename)<EOL>

Sets the package's verification code excluded file.
        Raises OrderError if no package previously defined.


def set_pkg_license_comment(self, doc, text):

self.assert_package_exists()<EOL>if not self.package_license_comment_set:<EOL><INDENT>self.package_license_comment_set = True<EOL>doc.package.license_comment = text<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Sets the package's license comment.
        Raises OrderError if no package previously defined.
        Raises CardinalityError if already set.


self.assert_package_exists()<EOL>if not self.package_cr_text_set:<EOL><INDENT>self.package_cr_text_set = True<EOL>doc.package.cr_text = text<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>


self.assert_package_exists()<EOL>if not self.package_summary_set:<EOL><INDENT>self.package_summary_set = True<EOL>doc.package.summary = text<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Set's the package summary.
        Raises CardinalityError if summary already set.
        Raises OrderError if no package previously defined.


self.assert_package_exists()<EOL>if not self.package_desc_set:<EOL><INDENT>self.package_desc_set = True<EOL>doc.package.description = text<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT>

Set's the package's description.
        Raises CardinalityError if description already set.
        Raises OrderError if no package previously defined.


def set_file_chksum(self, doc, chk_sum):

if self.has_package(doc) and self.has_file(doc):<EOL><INDENT>if not self.file_chksum_set:<EOL><INDENT>self.file_chksum_set = True<EOL>self.file(doc).chk_sum = checksum.Algorithm('<STR_LIT>', chk_sum)<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Sets the file check sum, if not already set.
        chk_sum - A string
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.


def set_file_license_comment(self, doc, text):

if self.has_package(doc) and self.has_file(doc):<EOL><INDENT>if not self.file_license_comment_set:<EOL><INDENT>self.file_license_comment_set = True<EOL>self.file(doc).license_comment = text<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Raises OrderError if no package or file defined.
Raises CardinalityError if more than one per file.


def set_file_copyright(self, doc, text):

if self.has_package(doc) and self.has_file(doc):<EOL><INDENT>if not self.file_copytext_set:<EOL><INDENT>self.file_copytext_set = True<EOL>self.file(doc).copyright = text<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Raises OrderError if no package or file defined.
        Raises CardinalityError if more than one.


if self.has_package(doc) and self.has_file(doc):<EOL><INDENT>if not self.file_comment_set:<EOL><INDENT>self.file_comment_set = True<EOL>self.file(doc).comment = text<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Raises OrderError if no package or no file defined.
        Raises CardinalityError if more than one comment set.


if self.has_package(doc) and self.has_file(doc):<EOL><INDENT>if not self.file_notice_set:<EOL><INDENT>self.file_notice_set = True<EOL>self.file(doc).notice = tagvaluebuilders.str_from_text(text)<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>


def add_review_comment(self, doc, comment):

if len(doc.reviews) != <NUM_LIT:0>:<EOL><INDENT>if not self.review_comment_set:<EOL><INDENT>self.review_comment_set = True<EOL>doc.reviews[-<NUM_LIT:1>].comment = comment<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Sets the review comment. Raises CardinalityError if
        already set. OrderError if no reviewer defined before.


def add_annotation_comment(self, doc, comment):

if len(doc.annotations) != <NUM_LIT:0>:<EOL><INDENT>if not self.annotation_comment_set:<EOL><INDENT>self.annotation_comment_set = True<EOL>doc.annotations[-<NUM_LIT:1>].comment = comment<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Sets the annotation comment. Raises CardinalityError if
        already set. OrderError if no annotator defined before.


def add_annotation_type(self, doc, annotation_type):

if len(doc.annotations) != <NUM_LIT:0>:<EOL><INDENT>if not self.annotation_type_set:<EOL><INDENT>if annotation_type.endswith('<STR_LIT>'):<EOL><INDENT>self.annotation_type_set = True<EOL>doc.annotations[-<NUM_LIT:1>].annotation_type = '<STR_LIT>'<EOL>return True<EOL><DEDENT>elif annotation_type.endswith('<STR_LIT>'):<EOL><INDENT>self.annotation_type_set = True<EOL>doc.annotations[-<NUM_LIT:1>].annotation_type = '<STR_LIT>'<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise CardinalityError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Sets the annotation type. Raises CardinalityError if
        already set. OrderError if no annotator defined before.


<EOL>self.reset_creation_info()<EOL>self.reset_document()<EOL>self.reset_package()<EOL>self.reset_file_stat()<EOL>self.reset_reviews()<EOL>self.reset_annotations()<EOL>

Resets builder's state for building new documents.
        Must be called between usage with different documents.


msg = '<STR_LIT>'.format(field)<EOL>self.logger.log(msg)<EOL>self.error = True<EOL>

Logs a more than one error.
        field is the field/property that has more than one defined.


msg = ERROR_MESSAGES[key].format(bad_value)<EOL>self.logger.log(msg)<EOL>self.error = True<EOL>

Reports a value error using ERROR_MESSAGES dict.
        key - key to use for ERROR_MESSAGES.
        bad_value - is passed to format which is called on what key maps to
        in ERROR_MESSAGES.


if value == self.spdx_namespace.none:<EOL><INDENT>return utils.SPDXNone()<EOL><DEDENT>elif value == self.spdx_namespace.noassertion:<EOL><INDENT>return utils.NoAssert()<EOL><DEDENT>elif value == self.spdx_namespace.unknown:<EOL><INDENT>return utils.UnKnown()<EOL><DEDENT>else:<EOL><INDENT>return value<EOL><DEDENT>

Checks if value is a special SPDX value such as
        NONE, NOASSERTION or UNKNOWN if so returns proper model.
        else returns value


<EOL>if (lics, RDF.type, self.spdx_namespace['<STR_LIT>']) in self.graph:<EOL><INDENT>return self.parse_only_extr_license(lics)<EOL><DEDENT>ident_start = lics.rfind('<STR_LIT:/>') + <NUM_LIT:1><EOL>if ident_start == <NUM_LIT:0>:<EOL><INDENT>special = self.to_special_value(lics)<EOL>if special == lics:<EOL><INDENT>if self.LICS_REF_REGEX.match(lics):<EOL><INDENT>return document.License.from_identifier(lics)<EOL><DEDENT>else:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return special<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return document.License.from_identifier(lics[ident_start:])<EOL><DEDENT>

Return a License from a `lics` license resource.


identifier_tripples = list(self.graph.triples((extr_lic, self.spdx_namespace['<STR_LIT>'], None)))<EOL>if not identifier_tripples:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL>return<EOL><DEDENT>if len(identifier_tripples) > <NUM_LIT:1>:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>return<EOL><DEDENT>identifier_tripple = identifier_tripples[<NUM_LIT:0>]<EOL>_s, _p, identifier = identifier_tripple<EOL>return identifier<EOL>

Return an a license identifier from an ExtractedLicense or None.


text_tripples = list(self.graph.triples((extr_lic, self.spdx_namespace['<STR_LIT>'], None)))<EOL>if not text_tripples:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL>return<EOL><DEDENT>if len(text_tripples) > <NUM_LIT:1>:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>return<EOL><DEDENT>text_tripple = text_tripples[<NUM_LIT:0>]<EOL>_s, _p, text = text_tripple<EOL>return text<EOL>

Return extracted text  from an ExtractedLicense or None.


extr_name_list = list(self.graph.triples((extr_lic, self.spdx_namespace['<STR_LIT>'], None)))<EOL>if len(extr_name_list) > <NUM_LIT:1>:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>return<EOL><DEDENT>elif len(extr_name_list) == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>return self.to_special_value(extr_name_list[<NUM_LIT:0>][<NUM_LIT:2>])<EOL>

Return the license name from an ExtractedLicense or None


xrefs = list(self.graph.triples((extr_lic, RDFS.seeAlso, None)))<EOL>return map(lambda xref_triple: xref_triple[<NUM_LIT:2>], xrefs)<EOL>


comment_list = list(self.graph.triples(<EOL>(extr_lics, RDFS.comment, None)))<EOL>if len(comment_list) > <NUM_LIT:1> :<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>return<EOL><DEDENT>elif len(comment_list) == <NUM_LIT:1>:<EOL><INDENT>return comment_list[<NUM_LIT:0>][<NUM_LIT:2>]<EOL><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT>


<EOL>ident = self.get_extr_license_ident(extr_lic)<EOL>text = self.get_extr_license_text(extr_lic)<EOL>comment = self.get_extr_lics_comment(extr_lic)<EOL>xrefs = self.get_extr_lics_xref(extr_lic)<EOL>name = self.get_extr_lic_name(extr_lic)<EOL>if not ident:<EOL><INDENT>return<EOL><DEDENT>lic = document.ExtractedLicense(ident)<EOL>if text is not None:<EOL><INDENT>lic.text = text<EOL><DEDENT>if name is not None:<EOL><INDENT>lic.full_name = name<EOL><DEDENT>if comment is not None:<EOL><INDENT>lic.comment = comment<EOL><DEDENT>lic.cross_ref = map(lambda x: six.text_type(x), xrefs)<EOL>return lic<EOL>

Return an ExtractedLicense object to represent a license object.
But does not add it to the SPDXDocument model.
Return None if failed.


lic = self.parse_only_extr_license(extr_lic)<EOL>if lic is not None:<EOL><INDENT>self.doc.add_extr_lic(lic)<EOL><DEDENT>return lic<EOL>

Build and return an ExtractedLicense or None.
Note that this function adds the license to the document.


def _handle_license_list(self, lics_set, cls=None):

licenses = []<EOL>for _, _, lics_member in self.graph.triples(<EOL>(lics_set, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>try:<EOL><INDENT>if (lics_member, RDF.type, self.spdx_namespace['<STR_LIT>']) in self.graph:<EOL><INDENT>lics = self.handle_extracted_license(lics_member)<EOL>if lics is not None:<EOL><INDENT>licenses.append(lics)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>licenses.append(self.handle_lics(lics_member))<EOL><DEDENT><DEDENT>except CardinalityError:<EOL><INDENT>self.value_error('<STR_LIT>', lics_member)<EOL>break<EOL><DEDENT><DEDENT>if len(licenses) > <NUM_LIT:1>:<EOL><INDENT>return reduce(lambda a, b: cls(a, b), licenses)<EOL><DEDENT>else:<EOL><INDENT>self.value_error('<STR_LIT>', '<STR_LIT>')<EOL>return<EOL><DEDENT>

Return a license representing a `cls` object (LicenseConjunction
or LicenseDisjunction) from a list of license resources or None.


return self._handle_license_list(lics_set, cls=document.LicenseConjunction)<EOL>

Return a license representing the conjunction from a list of
license resources or None.


return self._handle_license_list(lics_set, cls=document.LicenseDisjunction)<EOL>

Return a license representing the disjunction from a list of
license resources or None.


<EOL>if not (p_term, self.spdx_namespace['<STR_LIT:name>'], None) in self.graph:<EOL><INDENT>self.error = True<EOL>self.logger.log('<STR_LIT>')<EOL>self.builder.create_package(self.doc, '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>for _s, _p, o in self.graph.triples((p_term, self.spdx_namespace['<STR_LIT:name>'], None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.create_package(self.doc, six.text_type(o))<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>break<EOL><DEDENT><DEDENT><DEDENT>self.p_pkg_vinfo(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_fname(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_suppl(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_originator(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_down_loc(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_homepg(p_term, self.doap_namespace['<STR_LIT>'])<EOL>self.p_pkg_chk_sum(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_src_info(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_verif_code(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_lic_conc(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_lic_decl(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_lics_info_from_files(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_comments_on_lics(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_cr_text(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_summary(p_term, self.spdx_namespace['<STR_LIT>'])<EOL>self.p_pkg_descr(p_term, self.spdx_namespace['<STR_LIT:description>'])<EOL>


def handle_pkg_lic(self, p_term, predicate, builder_func):

try:<EOL><INDENT>for _, _, licenses in self.graph.triples((p_term, predicate, None)):<EOL><INDENT>if (licenses, RDF.type, self.spdx_namespace['<STR_LIT>']) in self.graph:<EOL><INDENT>lics = self.handle_conjunctive_list(licenses)<EOL>builder_func(self.doc, lics)<EOL><DEDENT>elif (licenses, RDF.type, self.spdx_namespace['<STR_LIT>']) in self.graph:<EOL><INDENT>lics = self.handle_disjunctive_list(licenses)<EOL>builder_func(self.doc, lics)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>lics = self.handle_lics(licenses)<EOL>builder_func(self.doc, lics)<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', licenses)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>'.format(predicate))<EOL><DEDENT>

Handles package lics concluded or declared.


for _, _, name in self.graph.triples((f_term, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>return name<EOL><DEDENT>return<EOL>

Returns first found fileName property or None if not found.


def p_file_depends(self, f_term, predicate):

for _, _, other_file in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>name = self.get_file_name(other_file)<EOL>if name is not None:<EOL><INDENT>self.builder.add_file_dep(six.text_type(name))<EOL><DEDENT>else:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL><DEDENT><DEDENT>


def p_file_contributor(self, f_term, predicate):

for _, _, contributor in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>self.builder.add_file_contribution(self.doc, six.text_type(contributor))<EOL><DEDENT>

Parse all file contributors and adds them to the model.


def p_file_notice(self, f_term, predicate):

try:<EOL><INDENT>for _, _, notice in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>self.builder.set_file_notice(self.doc, six.text_type(notice))<EOL><DEDENT><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL><DEDENT>


def p_file_comment(self, f_term, predicate):

try:<EOL><INDENT>for _, _, comment in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>self.builder.set_file_comment(self.doc, six.text_type(comment))<EOL><DEDENT><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL><DEDENT>


def p_file_artifact(self, f_term, predicate):

for _, _, project in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>if (project, RDF.type, self.doap_namespace['<STR_LIT>']):<EOL><INDENT>self.p_file_project(project)<EOL><DEDENT>else:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL><DEDENT><DEDENT>

Handles file artifactOf.
        Note: does not handle artifact of project URI.


for _, _, name in self.graph.triples((project, self.doap_namespace['<STR_LIT:name>'], None)):<EOL><INDENT>self.builder.set_file_atrificat_of_project(self.doc, '<STR_LIT:name>', six.text_type(name))<EOL><DEDENT>for _, _, homepage in self.graph.triples(<EOL>(project, self.doap_namespace['<STR_LIT>'], None)):<EOL><INDENT>self.builder.set_file_atrificat_of_project(self.doc, '<STR_LIT>', six.text_type(homepage))<EOL><DEDENT>

Helper function for parsing doap:project name and homepage.
        and setting them using the file builder.


def p_file_cr_text(self, f_term, predicate):

try:<EOL><INDENT>for _, _, cr_text in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>self.builder.set_file_copyright(self.doc, six.text_type(cr_text))<EOL><DEDENT><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL><DEDENT>


def p_file_comments_on_lics(self, f_term, predicate):

try:<EOL><INDENT>for _, _, comment in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>self.builder.set_file_license_comment(self.doc, six.text_type(comment))<EOL><DEDENT><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL><DEDENT>


def p_file_lic_info(self, f_term, predicate):

for _, _, info in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>lic = self.handle_lics(info)<EOL>if lic is not None:<EOL><INDENT>self.builder.set_file_license_in_file(self.doc, lic)<EOL><DEDENT><DEDENT>


def p_file_type(self, f_term, predicate):

try:<EOL><INDENT>for _, _, ftype in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>try:<EOL><INDENT>if ftype.endswith('<STR_LIT>'):<EOL><INDENT>ftype = '<STR_LIT>'<EOL><DEDENT>elif ftype.endswith('<STR_LIT:source>'):<EOL><INDENT>ftype = '<STR_LIT>'<EOL><DEDENT>elif ftype.endswith('<STR_LIT>'):<EOL><INDENT>ftype = '<STR_LIT>'<EOL><DEDENT>elif ftype.endswith('<STR_LIT>'):<EOL><INDENT>ftype = '<STR_LIT>'<EOL><DEDENT>self.builder.set_file_type(self.doc, ftype)<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', ftype)<EOL><DEDENT><DEDENT><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL><DEDENT>


def p_file_chk_sum(self, f_term, predicate):

try:<EOL><INDENT>for _s, _p, checksum in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>for _, _, value in self.graph.triples((checksum, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>self.builder.set_file_chksum(self.doc, six.text_type(value))<EOL><DEDENT><DEDENT><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL><DEDENT>

Sets file checksum. Assumes SHA1 algorithm without checking.


def p_file_lic_conc(self, f_term, predicate):

try:<EOL><INDENT>for _, _, licenses in self.graph.triples((f_term, predicate, None)):<EOL><INDENT>if (licenses, RDF.type, self.spdx_namespace['<STR_LIT>']) in self.graph:<EOL><INDENT>lics = self.handle_conjunctive_list(licenses)<EOL>self.builder.set_concluded_license(self.doc, lics)<EOL><DEDENT>elif (licenses, RDF.type, self.spdx_namespace['<STR_LIT>']) in self.graph:<EOL><INDENT>lics = self.handle_disjunctive_list(licenses)<EOL>self.builder.set_concluded_license(self.doc, lics)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>lics = self.handle_lics(licenses)<EOL>self.builder.set_concluded_license(self.doc, lics)<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', licenses)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>'.format(predicate))<EOL><DEDENT>


comment_list = list(self.graph.triples((r_term, RDFS.comment, None)))<EOL>if len(comment_list) > <NUM_LIT:1>:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL>return<EOL><DEDENT>else:<EOL><INDENT>return six.text_type(comment_list[<NUM_LIT:0>][<NUM_LIT:2>])<EOL><DEDENT>

Returns review comment or None if found none or more than one.
        Reports errors.


reviewed_list = list(self.graph.triples((r_term, self.spdx_namespace['<STR_LIT>'], None)))<EOL>if len(reviewed_list) != <NUM_LIT:1>:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL>return<EOL><DEDENT>return six.text_type(reviewed_list[<NUM_LIT:0>][<NUM_LIT:2>])<EOL>

Returns review date or None if not found.
        Reports error on failure.
        Note does not check value format.


reviewer_list = list(self.graph.triples((r_term, self.spdx_namespace['<STR_LIT>'], None)))<EOL>if len(reviewer_list) != <NUM_LIT:1>:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL>return<EOL><DEDENT>try:<EOL><INDENT>return self.builder.create_entity(self.doc, six.text_type(reviewer_list[<NUM_LIT:0>][<NUM_LIT:2>]))<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', reviewer_list[<NUM_LIT:0>][<NUM_LIT:2>])<EOL><DEDENT>

Returns reviewer as creator object or None if failed.
        Reports errors on failure.


for _, _, typ in self.graph.triples((<EOL>r_term, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>if typ is not None:<EOL><INDENT>return typ<EOL><DEDENT>else:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL>return<EOL><DEDENT><DEDENT>

Returns annotation type or None if found none or more than one.
        Reports errors on failure.


Returns annotation comment or None if found none or more than one.
        Reports errors.


annotation_date_list = list(self.graph.triples((r_term, self.spdx_namespace['<STR_LIT>'], None)))<EOL>if len(annotation_date_list) != <NUM_LIT:1>:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL>return<EOL><DEDENT>return six.text_type(annotation_date_list[<NUM_LIT:0>][<NUM_LIT:2>])<EOL>

Returns annotation date or None if not found.
        Reports error on failure.
        Note does not check value format.


annotator_list = list(self.graph.triples((r_term, self.spdx_namespace['<STR_LIT>'], None)))<EOL>if len(annotator_list) != <NUM_LIT:1>:<EOL><INDENT>self.error = True<EOL>msg = '<STR_LIT>'<EOL>self.logger.log(msg)<EOL>return<EOL><DEDENT>try:<EOL><INDENT>return self.builder.create_entity(self.doc, six.text_type(annotator_list[<NUM_LIT:0>][<NUM_LIT:2>]))<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', annotator_list[<NUM_LIT:0>][<NUM_LIT:2>])<EOL><DEDENT>

Returns annotator as creator object or None if failed.
        Reports errors on failure.


self.error = False<EOL>self.graph = Graph()<EOL>self.graph.parse(file=fil, format='<STR_LIT>')<EOL>self.doc = document.Document()<EOL>for s, _p, o in self.graph.triples((None, RDF.type, self.spdx_namespace['<STR_LIT>'])):<EOL><INDENT>self.parse_doc_fields(s)<EOL><DEDENT>for s, _p, o in self.graph.triples((None, RDF.type, self.spdx_namespace['<STR_LIT>'])):<EOL><INDENT>self.parse_ext_doc_ref(s)<EOL><DEDENT>for s, _p, o in self.graph.triples((None, RDF.type, self.spdx_namespace['<STR_LIT>'])):<EOL><INDENT>self.parse_creation_info(s)<EOL><DEDENT>for s, _p, o in self.graph.triples((None, RDF.type, self.spdx_namespace['<STR_LIT>'])):<EOL><INDENT>self.parse_package(s)<EOL><DEDENT>for s, _p, o in self.graph.triples((None, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>self.parse_file(o)<EOL><DEDENT>for s, _p, o in self.graph.triples((None, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>self.parse_review(o)<EOL><DEDENT>for s, _p, o in self.graph.triples((None, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>self.parse_annotation(o)<EOL><DEDENT>validation_messages = []<EOL>validation_messages = self.doc.validate(validation_messages)<EOL>if not self.error:<EOL><INDENT>if validation_messages:<EOL><INDENT>for msg in validation_messages:<EOL><INDENT>self.logger.log(msg)<EOL><DEDENT>self.error = True<EOL><DEDENT><DEDENT>return self.doc, self.error<EOL>

Parses a file and returns a document object.
        File, a file like object.


for _s, _p, o in self.graph.triples((ci_term, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>try:<EOL><INDENT>ent = self.builder.create_entity(self.doc, six.text_type(o))<EOL>self.builder.add_creator(self.doc, ent)<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', o)<EOL><DEDENT><DEDENT>for _s, _p, o in self.graph.triples((ci_term, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_created_date(self.doc, six.text_type(o))<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', o)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>break<EOL><DEDENT><DEDENT>for _s, _p, o in self.graph.triples((ci_term, RDFS.comment, None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_creation_comment(self.doc, six.text_type(o))<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>break<EOL><DEDENT><DEDENT>for _s, _p, o in self.graph.triples((ci_term, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_lics_list_ver(self.doc, six.text_type(o))<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>break<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', o)<EOL><DEDENT><DEDENT>


try:<EOL><INDENT>self.builder.set_doc_spdx_id(self.doc, doc_term)<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', doc_term)<EOL><DEDENT>try:<EOL><INDENT>if doc_term.count('<STR_LIT:#>', <NUM_LIT:0>, len(doc_term)) <= <NUM_LIT:1>:<EOL><INDENT>doc_namespace = doc_term.split('<STR_LIT:#>')[<NUM_LIT:0>]<EOL>self.builder.set_doc_namespace(self.doc, doc_namespace)<EOL><DEDENT>else:<EOL><INDENT>self.value_error('<STR_LIT>', doc_term)<EOL><DEDENT><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', doc_term)<EOL><DEDENT>for _s, _p, o in self.graph.triples((doc_term, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_doc_version(self.doc, six.text_type(o))<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', o)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>break<EOL><DEDENT><DEDENT>for _s, _p, o in self.graph.triples((doc_term, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_doc_data_lic(self.doc, six.text_type(o))<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', o)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>break<EOL><DEDENT><DEDENT>for _s, _p, o in self.graph.triples(<EOL>(doc_term, self.spdx_namespace['<STR_LIT:name>'], None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_doc_name(self.doc, six.text_type(o))<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT:name>')<EOL>break<EOL><DEDENT><DEDENT>for _s, _p, o in self.graph.triples((doc_term, RDFS.comment, None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_doc_comment(self.doc, six.text_type(o))<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>')<EOL>break<EOL><DEDENT><DEDENT>

Parses the version, data license, name, SPDX Identifier, namespace,
        and comment.


for _s, _p, o in self.graph.triples(<EOL>(ext_doc_ref_term,<EOL>self.spdx_namespace['<STR_LIT>'],<EOL>None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_ext_doc_id(self.doc, six.text_type(o))<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', '<STR_LIT>')<EOL>break<EOL><DEDENT><DEDENT>for _s, _p, o in self.graph.triples(<EOL>(ext_doc_ref_term,<EOL>self.spdx_namespace['<STR_LIT>'],<EOL>None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_spdx_doc_uri(self.doc, six.text_type(o))<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', '<STR_LIT>')<EOL>break<EOL><DEDENT><DEDENT>for _s, _p, checksum in self.graph.triples(<EOL>(ext_doc_ref_term, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>for _, _, value in self.graph.triples(<EOL>(checksum, self.spdx_namespace['<STR_LIT>'], None)):<EOL><INDENT>try:<EOL><INDENT>self.builder.set_chksum(self.doc, six.text_type(value))<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.value_error('<STR_LIT>', '<STR_LIT>')<EOL>break<EOL><DEDENT><DEDENT><DEDENT>

Parses the External Document ID, SPDX Document URI and Checksum.


pass<EOL>


pass<EOL>

attrib : spdx_version
                  | spdx_id
                  | data_lics
                  | doc_name
                  | ext_doc_ref
                  | doc_comment
                  | doc_namespace
                  | creator
                  | created
                  | creator_comment
                  | locs_list_ver
                  | reviewer
                  | review_date
                  | review_comment
                  | annotator
                  | annotation_date
                  | annotation_comment
                  | annotation_type
                  | annotation_spdx_id
                  | package_name
                  | package_version
                  | pkg_down_location
                  | pkg_home
                  | pkg_summary
                  | pkg_src_info
                  | pkg_file_name
                  | pkg_supplier
                  | pkg_orig
                  | pkg_chksum
                  | pkg_verif
                  | pkg_desc
                  | pkg_lic_decl
                  | pkg_lic_conc
                  | pkg_lic_ff
                  | pkg_lic_comment
                  | pkg_cr_text
                  | file_name
                  | file_type
                  | file_chksum
                  | file_conc
                  | file_lics_info
                  | file_cr_text
                  | file_lics_comment
                  | file_notice
                  | file_comment
                  | file_contrib
                  | file_dep
                  | file_artifact
                  | extr_lic_id
                  | extr_lic_text
                  | extr_lic_name
                  | lic_xref
                  | lic_comment
                  | unknown_tag


def order_error(self, first_tag, second_tag, line):

self.error = True<EOL>msg = ERROR_MESSAGES['<STR_LIT>'].format(first_tag, second_tag, line)<EOL>self.logger.log(msg)<EOL>

Reports an OrderError. Error message will state that
        first_tag came before second_tag.


try:<EOL><INDENT>if six.PY2:<EOL><INDENT>value = p[<NUM_LIT:2>].decode(encoding='<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>value = p[<NUM_LIT:2>]<EOL><DEDENT>self.builder.add_lic_xref(self.document, value)<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>


self.error = True<EOL>msg = ERROR_MESSAGES['<STR_LIT>'].format(p.lineno(<NUM_LIT:1>))<EOL>self.logger.log(msg)<EOL>


try:<EOL><INDENT>if six.PY2:<EOL><INDENT>value = p[<NUM_LIT:2>].decode(encoding='<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>value = p[<NUM_LIT:2>]<EOL><DEDENT>self.builder.set_lic_comment(self.document, value)<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>


try:<EOL><INDENT>self.builder.set_lic_name(self.document, p[<NUM_LIT:2>])<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>

extr_lic_name : LICS_NAME extr_lic_name_value