<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.


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.


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>

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


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_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.


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>


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>


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.


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_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>


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_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.


<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.


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.


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_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>


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.


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.


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


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>


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


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.


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.


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.


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>


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.


try:<EOL><INDENT>if six.PY2:<EOL><INDENT>value = p[<NUM_LIT:1>].decode(encoding='<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>value = p[<NUM_LIT:1>]<EOL><DEDENT>p[<NUM_LIT:0>] = self.builder.build_person(self.document, value)<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>msg = ERROR_MESSAGES['<STR_LIT>'].format(p[<NUM_LIT:1>], p.lineno(<NUM_LIT:1>))<EOL>self.logger.log(msg)<EOL>self.error = True<EOL>p[<NUM_LIT:0>] = None<EOL><DEDENT>


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_review_comment(self.document, value)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>', p.lineno(<NUM_LIT:1>))<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>


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


try:<EOL><INDENT>self.builder.set_file_atrificat_of_project(self.document,<EOL>'<STR_LIT>', utils.UnKnown())<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>


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_text(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>


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


p[<NUM_LIT:0>] = utils.NoAssert()<EOL>


pass<EOL>

file_artifact : prj_name_art file_art_rest
                         | prj_name_art


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_annotation_date(self.document, value)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>


try:<EOL><INDENT>if six.PY2:<EOL><INDENT>doc_ref_id = p[<NUM_LIT:2>].decode(encoding='<STR_LIT:utf-8>')<EOL>doc_uri = p[<NUM_LIT:3>].decode(encoding='<STR_LIT:utf-8>')<EOL>ext_doc_chksum = p[<NUM_LIT:4>].decode(encoding='<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>doc_ref_id = p[<NUM_LIT:2>]<EOL>doc_uri = p[<NUM_LIT:3>]<EOL>ext_doc_chksum = p[<NUM_LIT:4>]<EOL><DEDENT>self.builder.add_ext_doc_refs(self.document, doc_ref_id, doc_uri,<EOL>ext_doc_chksum)<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.error = True<EOL>msg = ERROR_MESSAGES['<STR_LIT>'].format(p.lineno(<NUM_LIT:2>))<EOL>self.logger.log(msg)<EOL><DEDENT>

ext_doc_ref : EXT_DOC_REF DOC_REF_ID DOC_URI EXT_DOC_REF_CHKSUM


try:<EOL><INDENT>if six.PY2:<EOL><INDENT>value = p[<NUM_LIT:1>].decode(encoding='<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>value = p[<NUM_LIT:1>]<EOL><DEDENT>p[<NUM_LIT:0>] = self.builder.build_org(self.document, value)<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>msg = ERROR_MESSAGES['<STR_LIT>'].format(p[<NUM_LIT:1>], p.lineno(<NUM_LIT:1>))<EOL>self.logger.log(msg)<EOL>self.error = True<EOL>p[<NUM_LIT:0>] = None<EOL><DEDENT>


try:<EOL><INDENT>self.builder.set_pkg_cr_text(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>

pkg_cr_text : PKG_CPY_TEXT pkg_cr_text_value


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_creation_comment(self.document, value)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>


p[<NUM_LIT:0>] = utils.SPDXNone()<EOL>


try:<EOL><INDENT>self.builder.set_pkg_down_location(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>

pkg_down_location : PKG_DOWN pkg_down_value


annotation_spdx_id : ANNOTATION_SPDX_ID error


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


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_file_dep(self.document, value)<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>


if six.PY2:<EOL><INDENT>value = p[<NUM_LIT:1>].decode(encoding='<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>value = p[<NUM_LIT:1>]<EOL><DEDENT>p[<NUM_LIT:0>] = document.License.from_identifier(value)<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_pkg_source_info(self.document, value)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>


try:<EOL><INDENT>self.builder.set_file_copyright(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>

file_cr_text : FILE_CR_TEXT file_cr_value


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_lics_list_ver(self.document, value)<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.error = True<EOL>msg = ERROR_MESSAGES['<STR_LIT>'].format(<EOL>p[<NUM_LIT:2>], p.lineno(<NUM_LIT:2>))<EOL>self.logger.log(msg)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>


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_doc_name(self.document, value)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<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>


if six.PY2:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>].decode(encoding='<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL><DEDENT>


try:<EOL><INDENT>self.builder.set_concluded_license(self.document, p[<NUM_LIT:2>])<EOL><DEDENT>except SPDXValueError:<EOL><INDENT>self.error = True<EOL>msg = ERROR_MESSAGES['<STR_LIT>'].format(p.lineno(<NUM_LIT:1>))<EOL>self.logger.log(msg)<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>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.create_package(self.document, value)<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_pkg_license_from_file(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 SPDXValueError:<EOL><INDENT>self.error = True<EOL>msg = ERROR_MESSAGES['<STR_LIT>'].format(p.lineno(<NUM_LIT:1>))<EOL>self.logger.log(msg)<EOL><DEDENT>

pkg_lic_ff : PKG_LICS_FFILE pkg_lic_ff_value


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_file_license_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>

file_lics_comment : FILE_LICS_COMMENT TEXT


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_annotation_comment(self.document, value)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>

annotation_comment : ANNOTATION_COMMENT TEXT


p[<NUM_LIT:0>] = utils.NoAssert()<EOL>


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


p[<NUM_LIT:0>] = utils.SPDXNone()<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_annotation_spdx_id(self.document, value)<EOL><DEDENT>except CardinalityError:<EOL><INDENT>self.more_than_one_error('<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>

annotation_spdx_id : ANNOTATION_SPDX_ID LINE


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_file_chksum(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>


self.builder.add_reviewer(self.document, p[<NUM_LIT:2>])<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_file_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>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_file_contribution(self.document, value)<EOL><DEDENT>except OrderError:<EOL><INDENT>self.order_error('<STR_LIT>', '<STR_LIT>', p.lineno(<NUM_LIT:1>))<EOL><DEDENT>


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_pkg_chk_sum(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>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_pkg_verif_code(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>except SPDXValueError:<EOL><INDENT>self.error = True<EOL>msg = ERROR_MESSAGES['<STR_LIT>'].format(p.lineno(<NUM_LIT:1>))<EOL>self.logger.log(msg)<EOL><DEDENT>


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>if not self.builder.doc_spdx_id_set:<EOL><INDENT>self.builder.set_doc_spdx_id(self.document, value)<EOL><DEDENT>else:<EOL><INDENT>self.builder.set_file_spdx_id(self.document, value)<EOL><DEDENT>


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_pkg_file_name(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>


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


return doc.package is not None<EOL>

Returns true if the document has a package.


if not self.doc_data_lics_set:<EOL><INDENT>self.doc_data_lics_set = True<EOL>if validations.validate_data_lics(lics):<EOL><INDENT>doc.data_license = document.License.from_identifier(lics)<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 data license.
        Raises value error if malformed value, CardinalityError
        if already defined.


if self.has_extr_lic(doc):<EOL><INDENT>self.extr_lic(doc).add_xref(ref)<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Adds a license cross reference.
        Raises OrderError if no License ID defined.


def add_review_date(self, doc, reviewed):

if len(doc.reviews) != <NUM_LIT:0>:<EOL><INDENT>if not self.review_date_set:<EOL><INDENT>self.review_date_set = True<EOL>date = utils.datetime_from_iso_format(reviewed)<EOL>if date is not None:<EOL><INDENT>doc.reviews[-<NUM_LIT:1>].review_date = date<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 review date. Raises CardinalityError if
        already set. OrderError if no reviewer defined before.
        Raises SPDXValueError if invalid reviewed value.


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

Sets the package file name, if not already set.
        name - Any string.
        Raises CardinalityError if already has a file_name.
        Raises OrderError if no pacakge previously defined.


def set_file_spdx_id(self, doc, spdx_id):

if self.has_package(doc) and self.has_file(doc):<EOL><INDENT>if not self.file_spdx_id_set:<EOL><INDENT>self.file_spdx_id_set = True<EOL>if validations.validate_file_spdx_id(spdx_id):<EOL><INDENT>self.file(doc).spdx_id = spdx_id<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 file SPDX Identifier.
Raises OrderError if no package or no file defined.
Raises SPDXValueError if malformed value.
Raises CardinalityError if more than one spdx_id set.


match = self.org_re.match(entity)<EOL>if match and validations.validate_org_name(match.group(self.ORG_NAME_GROUP)):<EOL><INDENT>name = match.group(self.ORG_NAME_GROUP).strip()<EOL>email = match.group(self.ORG_EMAIL_GROUP)<EOL>if (email is not None) and (len(email) != <NUM_LIT:0>):<EOL><INDENT>return creationinfo.Organization(name=name, email=email.strip())<EOL><DEDENT>else:<EOL><INDENT>return creationinfo.Organization(name=name, email=None)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT>

Builds an organization object of of a string representation.
        Returns built organization. Raises SPDXValueError if failed to extract
        name.


if self.has_extr_lic(doc):<EOL><INDENT>if not self.extr_lic_name_set:<EOL><INDENT>self.extr_lic_name_set = True<EOL>if validations.validate_extr_lic_name(name):<EOL><INDENT>self.extr_lic(doc).full_name = name<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 license name.
        Raises SPDXValueError if name is not str or utils.NoAssert
        Raises OrderError if no license id defined.


<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>self.reset_extr_lics()<EOL>

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


doc.ext_document_references[-<NUM_LIT:1>].check_sum = checksum_from_sha1(<EOL>chksum)<EOL>

Sets the `check_sum` attribute of the `ExternalDocumentRef`
object.


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.


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>if validations.validate_pkg_src_info(text):<EOL><INDENT>doc.package.source_info = str_from_text(text)<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 package's source information, if not already set.
        text - Free form text.
        Raises CardinalityError if already defined.
        Raises OrderError if no package previously defined.
        SPDXValueError if text is not free form text.


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>if validations.validate_file_cpyright(text):<EOL><INDENT>if isinstance(text, string_types):<EOL><INDENT>self.file(doc).copyright = str_from_text(text)<EOL><DEDENT>else:<EOL><INDENT>self.file(doc).copyright = text  <EOL><DEDENT>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>

Raises OrderError if no package or file defined.
        Raises SPDXValueError if not free form text or NONE or NO_ASSERT.
        Raises CardinalityError if more than one.


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

Set's the package summary.
        Raises SPDXValueError if text is not free form text.
        Raises CardinalityError if summary already set.
        Raises OrderError if no package previously defined.


Adds a reviewer to the SPDX Document.
        Reviwer is an entity created by an EntityBuilder.
        Raises SPDXValueError if not a valid reviewer type.


def set_annotation_spdx_id(self, doc, spdx_id):

if len(doc.annotations) != <NUM_LIT:0>:<EOL><INDENT>if not self.annotation_spdx_id_set:<EOL><INDENT>self.annotation_spdx_id_set = True<EOL>doc.annotations[-<NUM_LIT:1>].spdx_id = spdx_id<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 SPDX Identifier.
        Raises CardinalityError if already set. OrderError if no annotator
        defined before.


<EOL>CHECKSUM_RE = re.compile('<STR_LIT>', re.UNICODE)<EOL>match = CHECKSUM_RE.match(value)<EOL>if match:<EOL><INDENT>return checksum.Algorithm(identifier='<STR_LIT>', value=match.group(<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Return an spdx.checksum.Algorithm instance representing the SHA1
checksum or None if does not match CHECKSUM_RE.


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>if validations.validate_file_comment(text):<EOL><INDENT>self.file(doc).comment = str_from_text(text)<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>

Raises OrderError if no package or no file defined.
Raises CardinalityError if more than one comment set.
Raises SPDXValueError if text is not free form text.


<EOL>self.review_date_set = False<EOL>self.review_comment_set = False<EOL>

Resets the builder's state to allow building new reviews.


return doc.extracted_licenses[-<NUM_LIT:1>]<EOL>

Retrieves last license in extracted license list


def set_created_date(self, doc, created):

if not self.created_date_set:<EOL><INDENT>self.created_date_set = True<EOL>date = utils.datetime_from_iso_format(created)<EOL>if date is not None:<EOL><INDENT>doc.creation_info.created = date<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 created date, Raises CardinalityError if
        created date already set.
        Raises SPDXValueError if created is not a date.


def set_file_license_in_file(self, doc, lic):

if self.has_package(doc) and self.has_file(doc):<EOL><INDENT>if validations.validate_file_lics_in_file(lic):<EOL><INDENT>self.file(doc).add_lics(lic)<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Raises OrderError if no package or file defined.
Raises SPDXValueError if malformed value.


if self.has_package(doc) and self.has_file(doc):<EOL><INDENT>self.file(doc).add_depend(value)<EOL><DEDENT>else:<EOL><INDENT>raise OrderError('<STR_LIT>')<EOL><DEDENT>

Raises OrderError if no package or file defined.


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>self.annotation_type_set = True<EOL>if validations.validate_annotation_type(annotation_type):<EOL><INDENT>doc.annotations[-<NUM_LIT:1>].annotation_type = annotation_type<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.
        Raises SPDXValueError if invalid value.


match = self.person_re.match(entity)<EOL>if match and validations.validate_person_name(match.group(self.PERSON_NAME_GROUP)):<EOL><INDENT>name = match.group(self.PERSON_NAME_GROUP).strip()<EOL>email = match.group(self.PERSON_EMAIL_GROUP)<EOL>if (email is not None) and (len(email) != <NUM_LIT:0>):<EOL><INDENT>return creationinfo.Person(name=name, email=email.strip())<EOL><DEDENT>else:<EOL><INDENT>return creationinfo.Person(name=name, email=None)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise SPDXValueError('<STR_LIT>')<EOL><DEDENT>

Builds an organization object of of a string representation.
        Returns built organization. Raises SPDXValueError if failed to extract
        name.


def set_doc_comment(self, doc, comment):

if not self.doc_comment_set:<EOL><INDENT>self.doc_comment_set = True<EOL>if validations.validate_doc_comment(comment):<EOL><INDENT>doc.comment = str_from_text(comment)<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 document comment, Raises CardinalityError if
        comment already set.
        Raises SPDXValueError if comment is not free form text.


<EOL>self.annotation_date_set = False<EOL>self.annotation_comment_set = False<EOL>self.annotation_type_set = False<EOL>self.annotation_spdx_id_set = False<EOL>

Resets the builder's state to allow building new annotations.


def set_pkg_license_declared(self, doc, lic):

self.assert_package_exists()<EOL>if not self.package_license_declared_set:<EOL><INDENT>self.package_license_declared_set = True<EOL>if validations.validate_lics_conc(lic):<EOL><INDENT>doc.package.license_declared = lic<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 package's declared license.
        Raises SPDXValueError if data malformed.
        Raises OrderError if no package previously defined.
        Raises CardinalityError if already set.


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_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_from_sha1(chk_sum)<EOL>return True<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 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>if validations.validate_review_comment(comment):<EOL><INDENT>doc.reviews[-<NUM_LIT:1>].comment = str_from_text(comment)<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 review comment. Raises CardinalityError if
        already set. OrderError if no reviewer defined before.
        Raises SPDXValueError if comment is not free form text.


t.lexer.text_start = t.lexer.lexpos - len('<STR_LIT>')<EOL>t.lexer.begin('<STR_LIT:text>')<EOL>


t.lexer.lineno += len(t.value)<EOL>


t.value = t.value[<NUM_LIT:1>:].strip()<EOL>return t<EOL>


t.value = t.value.strip()<EOL>return t<EOL>


pass<EOL>


t.value = t.value[<NUM_LIT:1>:].strip()<EOL>if t.value in self.reserved.keys():<EOL><INDENT>t.type = self.reserved[t.value]<EOL><DEDENT>else:<EOL><INDENT>t.type = '<STR_LIT>'<EOL><DEDENT>return t<EOL>


self.yacc = yacc.yacc(module=self, **kwargs)<EOL>


return t<EOL>


try:<EOL><INDENT>return self.yacc.parse(data, lexer=self.lex)<EOL><DEDENT>except:<EOL><INDENT>return None<EOL><DEDENT>

Parses a license list and returns a License or None if it failed.


p[<NUM_LIT:0>] = document.LicenseConjunction(p[<NUM_LIT:1>], p[<NUM_LIT:3>])<EOL>

conjunction : conjunction AND license_atom


p[<NUM_LIT:0>] = document.LicenseDisjunction(p[<NUM_LIT:1>], p[<NUM_LIT:3>])<EOL>

disjunction : disjunction OR conjunction


p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>


Return a datetime object from an iso 8601 representation.
Return None if string is non conforming.


return self.lexer.token()<EOL>

Get the next token or None if exhausted input.


p[<NUM_LIT:0>] = document.License.from_identifier(p[<NUM_LIT:1>])<EOL>


messages = self.validate_annotator(messages)<EOL>messages = self.validate_annotation_date(messages)<EOL>messages = self.validate_annotation_type(messages)<EOL>messages = self.validate_spdx_id(messages)<EOL>return messages<EOL>

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


if extension and not extension.startswith('<STR_LIT:.>'):<EOL><INDENT>extension = '<STR_LIT:.>' + extension<EOL><DEDENT>file_name = '<STR_LIT>' + extension<EOL>temp_dir = tempfile.mkdtemp()<EOL>return os.path.join(temp_dir, file_name)<EOL>

Return a unique new temporary file location to a non-existing
temporary file that can safely be created without a risk of name
collision.


if isinstance(data, dict):<EOL><INDENT>new_data = {}<EOL>for k, v in data.items():<EOL><INDENT>if isinstance(v, list):<EOL><INDENT>v = sorted(v)<EOL><DEDENT>if isinstance(v, dict):<EOL><INDENT>v = sort_nested(v)<EOL><DEDENT>new_data[k] = v<EOL><DEDENT>return new_data<EOL><DEDENT>elif isinstance(data, list):<EOL><INDENT>new_data = []<EOL>for v in sorted(data):<EOL><INDENT>if isinstance(v, list):<EOL><INDENT>v = sort_nested(v)<EOL><DEDENT>if isinstance(v, dict):<EOL><INDENT>v = sort_nested(v)<EOL><DEDENT>new_data.append(v)<EOL><DEDENT>return new_data<EOL><DEDENT>

Return a new dict with any nested list sorted recursively.


def check_rdf_scan(expected_file, result_file, regen=False):

import json<EOL>result = load_and_clean_rdf(result_file)<EOL>if regen:<EOL><INDENT>expected = result<EOL>with codecs.open(expected_file, '<STR_LIT:w>', encoding='<STR_LIT:utf-8>') as o:<EOL><INDENT>json.dump(expected, o, indent=<NUM_LIT:2>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>with codecs.open(expected_file, '<STR_LIT:r>', encoding='<STR_LIT:utf-8>') as i:<EOL><INDENT>expected = sort_nested(json.load(i))<EOL><DEDENT><DEDENT>assert expected == result<EOL>

Check that expected and result_file are equal.
Both are paths to SPDX RDF XML files, UTF-8 encoded.


content = codecs.open(location, encoding='<STR_LIT:utf-8>').read()<EOL>content = [l for l in content.splitlines(False)<EOL>if l and l.strip() and not l.startswith(('<STR_LIT>', '<STR_LIT>',))]<EOL>return '<STR_LIT:\n>'.join(content)<EOL>

Return a mapping for the SPDX TV file at location suitable for
comparison. The file content is cleaned from variable parts such as
dates, generated UUIDs and versions


replace_nid = re.compile('<STR_LIT>').sub<EOL>rdf_text = replace_nid('<STR_LIT>', rdf_text)<EOL>replace_creation = re.compile('<STR_LIT>', re.DOTALL).sub<EOL>rdf_text = replace_creation('<STR_LIT>', rdf_text)<EOL>replace_pcc = re.compile('<STR_LIT>', re.DOTALL).sub<EOL>rdf_text = replace_pcc('<STR_LIT>', rdf_text)<EOL>return rdf_text<EOL>

Return rdf_text stripped from variable parts such as rdf nodeids


content = codecs.open(location, encoding='<STR_LIT:utf-8>').read()<EOL>content = strip_variable_text(content)<EOL>data = xmltodict.parse(content, dict_constructor=dict)<EOL>return sort_nested(data)<EOL>

Return plain Python nested data for the SPDX RDF file at location
suitable for comparison. The file content is cleaned from variable
parts such as dates, generated UUIDs and versions

NOTE: we use plain dicts to avoid ordering issues in XML. the SPDX
tool and lxml do not seem to return a consistent ordering that is
needed for tests.


self._default_args = default_args<EOL>

:param default_args: default arguments
:type default_args: string or list of string


return self._timeout<EOL>

:return: seconds to wait I/O.
:rtype: float


self._process.stdin.write(bytearray(keys, self._encoding))<EOL>self._process.stdin.flush()<EOL>if wait:<EOL><INDENT>self.wait()<EOL><DEDENT>

Send a raw key sequence to *Vim*.

.. note:: *Vim* style key sequence notation (like ``<Esc>``)
          is not recognized.
          Use escaped characters (like ``'\033'``) instead.

Example:

>>> import headlessvim
>>> with headlessvim.open() as vim:
...     vim.send_keys('ispam\033')
...     str(vim.display_lines()[0].strip())
...
'spam'

:param strgin keys: key sequence to send
:param boolean wait: whether if wait a response


self._tempfile.close()<EOL>self._process.terminate()<EOL>if self._process.is_alive():<EOL><INDENT>self._process.kill()<EOL><DEDENT>


def install_plugin(self, dir, entry_script=None):

self.runtimepath.append(dir)<EOL>if entry_script is not None:<EOL><INDENT>self.command('<STR_LIT>'.format(entry_script), False)<EOL><DEDENT>

Install *Vim* plugin.

:param string dir: the root directory contains *Vim* script
:param string entry_script: path to the initializing script


if timeout is None:<EOL><INDENT>timeout = self._timeout<EOL><DEDENT>while self._process.check_readable(timeout):<EOL><INDENT>self._flush()<EOL><DEDENT>

Wait for response until timeout.
If timeout is specified to None, ``self.timeout`` is used.

:param float timeout: seconds to wait I/O


return self._screen.display<EOL>

Shows the terminal screen splitted by newlines.

Almost equals to ``self.display().splitlines()``

:return: screen as a list of strings
:rtype: list of string


return self._encoding<EOL>

:return: internal encoding of *Vim*.
:rtype: string


return self._process.executable<EOL>

:return: the absolute path to the process.
:rtype: string


return self._stdin<EOL>

:return: file-like object representing the standard input
         of the process
:rtype: flie-like object


return self._executable<EOL>

:return: the absolute path to the process.
:rtype: strIng


with self._close():<EOL><INDENT>self._process.terminate()<EOL><DEDENT>

Terminate this process.
Use this method rather than ``self.kill``.


return self._process.poll() is None<EOL>

Check if the process is alive.

:return: True if the process is alive, else False
:rtype: boolean


return self._args<EOL>

:return: launch arguments of the process.
:rtype: string or list of string


return self._stdout<EOL>

:return: non blocking file-like object
         representing the standard output of the process
:rtype: file-like object


def __init__(self, executable, args, env):

self._executable = distutils.spawn.find_executable(executable)<EOL>self._args = args<EOL>self._env = env<EOL>self._open_process()<EOL>

:param str executable: command name to execute *Vim*
:param args: arguments to execute *Vim*
:type args: None or string or list of string
:param env: environment variables to execute *Vim*
:type env: None or dict of (string, string)


run_once = True<EOL>while (run_once or self._threaded) and self.end is False:<EOL><INDENT>self.service_tx_queue()<EOL>self.parse_messages()<EOL>run_once = False<EOL>if self._threaded:<EOL><INDENT>time.sleep(self._timeout)<EOL><DEDENT><DEDENT>if self._threaded:<EOL><INDENT>logger.info('<STR_LIT>')<EOL><DEDENT>

Receives the serial data into the self._raw buffer
:return:


message = []<EOL>escape_next = False<EOL>for c in raw_message:<EOL><INDENT>if escape_next:<EOL><INDENT>message.append(c ^ self._ESC_XOR)<EOL>escape_next = False<EOL><DEDENT>else:<EOL><INDENT>if c == self._ESC:<EOL><INDENT>escape_next = True<EOL><DEDENT>else:<EOL><INDENT>message.append(c)<EOL><DEDENT><DEDENT><DEDENT>return message<EOL>

Removes any escape characters from the message
:param raw_message: a list of bytes containing the un-processed data
:return: a message that has the escaped characters appropriately un-escaped


if not self._threaded:<EOL><INDENT>self.run()<EOL><DEDENT>try:<EOL><INDENT>return tuple(self._messages.pop(<NUM_LIT:0>))<EOL><DEDENT>except IndexError:<EOL><INDENT>return None<EOL><DEDENT>

Receive a series of bytes that have been verified
:return: a series of bytes as a tuple or None if empty


run_once = True<EOL>while run_once or self._threaded:<EOL><INDENT>waiting = self._port.in_waiting<EOL>if waiting > <NUM_LIT:0>:<EOL><INDENT>temp = [int(c) for c in self._port.read(waiting)]<EOL>self._raw += temp<EOL><DEDENT>self._parse_raw_data()<EOL>run_once = False<EOL>if self._threaded:<EOL><INDENT>time.sleep(self._timeout)<EOL><DEDENT><DEDENT>


if self._START_OF_FRAME in self._raw and self._END_OF_FRAME in self._raw:<EOL><INDENT>while self._raw[<NUM_LIT:0>] != self._START_OF_FRAME and len(self._raw) > <NUM_LIT:0>:<EOL><INDENT>self._raw.pop(<NUM_LIT:0>)<EOL><DEDENT>if self._raw[<NUM_LIT:0>] == self._START_OF_FRAME:<EOL><INDENT>self._raw.pop(<NUM_LIT:0>)<EOL><DEDENT>eof_index = self._raw.index(self._END_OF_FRAME)<EOL>raw_message = self._raw[:eof_index]<EOL>self._raw = self._raw[eof_index:]<EOL>logger.debug('<STR_LIT>'.format(raw_message))<EOL>message = self._remove_esc_chars(raw_message)<EOL>logger.debug('<STR_LIT>'.format(message))<EOL>expected_checksum = (message[-<NUM_LIT:1>] << <NUM_LIT:8>) | message[-<NUM_LIT:2>]<EOL>logger.debug('<STR_LIT>'.format(expected_checksum))<EOL>message = message[:-<NUM_LIT:2>]  <EOL>logger.debug('<STR_LIT>'.format(message))<EOL>sum1, sum2 = self._fletcher16_checksum(message)<EOL>calculated_checksum = (sum2 << <NUM_LIT:8>) | sum1<EOL>if expected_checksum == calculated_checksum:<EOL><INDENT>message = message[<NUM_LIT:2>:]  <EOL>logger.debug('<STR_LIT>'.format(message))<EOL>self._messages.append(message)<EOL><DEDENT>else:<EOL><INDENT>logger.warning('<STR_LIT>'.format(message))<EOL>logger.debug('<STR_LIT>'.format(expected_checksum, calculated_checksum))<EOL><DEDENT><DEDENT>try:<EOL><INDENT>while self._raw[<NUM_LIT:0>] != self._START_OF_FRAME and len(self._raw) > <NUM_LIT:0>:<EOL><INDENT>self._raw.pop(<NUM_LIT:0>)<EOL><DEDENT><DEDENT>except IndexError:<EOL><INDENT>pass<EOL><DEDENT>

Parses the incoming data and determines if it is valid.  Valid
data gets placed into self._messages
:return: None


try:<EOL><INDENT>ret_val = float(value)<EOL>return ret_val, True<EOL><DEDENT>except ValueError:<EOL><INDENT>return <NUM_LIT:0.0>, False<EOL><DEDENT>


try:<EOL><INDENT>low_num = int(low_word)<EOL>if low_num < <NUM_LIT:0>:<EOL><INDENT>low_num = abs(low_num) + <NUM_LIT:2>**<NUM_LIT:15><EOL><DEDENT>number = (int(high_word) << <NUM_LIT:16>) | low_num<EOL>return number, True<EOL><DEDENT>except:<EOL><INDENT>return <NUM_LIT:0>, False<EOL><DEDENT>


try:<EOL><INDENT>os.kill(pid, <NUM_LIT:0>)<EOL>if debug > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>return True<EOL><DEDENT>except OSError:<EOL><INDENT>if debug > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>return False<EOL><DEDENT>

This function will check whether a PID is currently running


return convert_words_to_uint(high_word, low_word)<EOL>

Convert two words to a 32 bit unsigned integer


<EOL>if os.path.isfile(pidfile):<EOL><INDENT>pidfile_handle = open(pidfile, '<STR_LIT:r>')<EOL>try:<EOL><INDENT>pid = int(pidfile_handle.read())<EOL>pidfile_handle.close()<EOL>if check_pid(pid, debug):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>os.unlink(pidfile)<EOL><DEDENT>pid = str(os.getpid())<EOL>open(pidfile, '<STR_LIT:w>').write(pid)<EOL>return False<EOL>

Check that a process is not running more than once, using PIDFILE


def run_program(prog_list, debug, shell):

try:<EOL><INDENT>if not shell:<EOL><INDENT>process = Popen(prog_list, stdout=PIPE, stderr=PIPE)<EOL>stdout, stderr = process.communicate()<EOL>retcode = process.returncode<EOL>if debug >= <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>", "<STR_LIT:U+0020>".join(prog_list))<EOL>print("<STR_LIT>", retcode)<EOL>print("<STR_LIT>", stdout)<EOL>print("<STR_LIT>", stderr)<EOL><DEDENT>return bool(retcode)<EOL><DEDENT>else:<EOL><INDENT>command = "<STR_LIT:U+0020>".join(prog_list)<EOL>os.system(command)<EOL>return True<EOL><DEDENT><DEDENT>except:<EOL><INDENT>return False<EOL><DEDENT>

Run a  program and check program return code Note that some commands don't work
    well with Popen.  So if this function is specifically called with 'shell=True',
    then it will run the old 'os.system'. In which case, there is no program output


def contains(self, logger, level, message, is_regex=False):

for record in self.records:<EOL><INDENT>if record.name != logger or record.levelno != level:<EOL><INDENT>continue<EOL><DEDENT>if is_regex:<EOL><INDENT>if re.search(message, (record.msg % record.args)):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if message in (record.msg % record.args):<EOL><INDENT>return True<EOL><DEDENT><DEDENT><DEDENT>return False<EOL>

Checks whether a message has been logged to a specific logger with a
specific level.

:param logger: The logger.
:param level: The log level.
:param messgae: The message contents.
:param is_regex: Whether the expected message is a regex or not.
    Non-regex messages are simply tested for inclusion.


self.records.append(record)<EOL>


old_values = {}<EOL>nonexistent = set()<EOL>for key in kwargs:<EOL><INDENT>if key not in os.environ:<EOL><INDENT>nonexistent.add(key)<EOL><DEDENT>else:<EOL><INDENT>old_values[key] = os.environ[key]<EOL><DEDENT>os.environ[key] = kwargs[key]<EOL><DEDENT>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>for key in old_values:<EOL><INDENT>os.environ[key] = old_values[key]<EOL><DEDENT>for key in nonexistent:<EOL><INDENT>os.environ.pop(key)<EOL><DEDENT><DEDENT>

Context manager to tempolrarily change environment variables. On exit all
variables are set to their original value.


can_read = super(SecuredConfig, self).check_file(filename)<EOL>if not can_read:<EOL><INDENT>return False<EOL><DEDENT>mode = get_stat(filename).st_mode<EOL>if (mode & stat.S_IRGRP) or (mode & stat.S_IROTH):<EOL><INDENT>msg = "<STR_LIT>"<EOL>self._log.warning(msg, filename)<EOL>return False<EOL><DEDENT>return True<EOL>


def load(self, reload=False, require_load=False):<EOL>

if reload:  <EOL><INDENT>self.config = None<EOL><DEDENT>if self.config:  <EOL><INDENT>self._log.debug('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>return<EOL><DEDENT>path = self._effective_path()<EOL>config_filename = self._effective_filename()<EOL>self._active_path = [join(_, config_filename) for _ in path]<EOL>for dirname in path:<EOL><INDENT>conf_name = join(dirname, config_filename)<EOL>readable = self.check_file(conf_name)<EOL>if readable:<EOL><INDENT>action = '<STR_LIT>' if self._loaded_files else '<STR_LIT>'<EOL>self._log.info('<STR_LIT>', action, conf_name)<EOL>self.read(conf_name)<EOL>if conf_name == expanduser("<STR_LIT>" % (<EOL>self.group_name, self.app_name, self.filename)):<EOL><INDENT>self._log.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>", expanduser("<STR_LIT>"), self.group_name,<EOL>self.app_name, expanduser("<STR_LIT>"), self.group_name,<EOL>self.app_name)<EOL><DEDENT>self._loaded_files.append(conf_name)<EOL><DEDENT><DEDENT>if not self._loaded_files and not require_load:<EOL><INDENT>self._log.warning(<EOL>"<STR_LIT>",<EOL>config_filename,<EOL>path)<EOL><DEDENT>elif not self._loaded_files and require_load:<EOL><INDENT>raise IOError("<STR_LIT>"<EOL>"<STR_LIT>" % (config_filename, path))<EOL><DEDENT>

Searches for an appropriate config file. If found, loads the file into
the current instance. This method can also be used to reload a
configuration. Note that you may want to set ``reload`` to ``True`` to
clear the configuration before loading in that case.  Without doing
that, values will remain available even if they have been removed from
the config files.

:param reload: if set to ``True``, the existing values are cleared
               before reloading.
:param require_load: If set to ``True`` this will raise a
                     :py:exc:`IOError` if no config file has been found
                     to load.


config_dirs = getenv('<STR_LIT>', '<STR_LIT>')<EOL>if config_dirs:<EOL><INDENT>self._log.debug('<STR_LIT>', config_dirs)<EOL>output = []<EOL>for path in reversed(config_dirs.split('<STR_LIT::>')):<EOL><INDENT>output.append(join(path, self.group_name, self.app_name))<EOL><DEDENT>return output<EOL><DEDENT>return ['<STR_LIT>' % (self.group_name, self.app_name)]<EOL>

Returns a list of paths specified by the XDG_CONFIG_DIRS environment
variable or the appropriate default.

The list is sorted by precedence, with the most important item coming
*last* (required by the existing config_resolver logic).


config_home = getenv('<STR_LIT>', '<STR_LIT>')<EOL>if config_home:<EOL><INDENT>self._log.debug('<STR_LIT>', config_home)<EOL>return expanduser(join(config_home, self.group_name, self.app_name))<EOL><DEDENT>return expanduser('<STR_LIT>' % (self.group_name, self.app_name))<EOL>

Returns the value specified in the XDG_CONFIG_HOME environment variable
or the appropriate default.


<EOL>path = (['<STR_LIT>' % (self.group_name, self.app_name)] +<EOL>self.get_xdg_dirs() +<EOL>[expanduser('<STR_LIT>' % (self.group_name, self.app_name)),<EOL>self.get_xdg_home(),<EOL>join(getcwd(), '<STR_LIT>'.format(self.group_name), self.app_name)])<EOL>if self.search_path:<EOL><INDENT>path = self.search_path.split(pathsep)<EOL><DEDENT>env_path = getenv(self.env_path_name)<EOL>if env_path and env_path.startswith('<STR_LIT:+>'):<EOL><INDENT>additional_paths = env_path[<NUM_LIT:1>:].split(pathsep)<EOL>self._log.info('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>additional_paths,<EOL>self.env_path_name)<EOL>path.extend(additional_paths)<EOL><DEDENT>elif env_path:<EOL><INDENT>self._log.info("<STR_LIT>"<EOL>"<STR_LIT>",<EOL>env_path,<EOL>self.env_path_name)<EOL>path = env_path.split(pathsep)<EOL><DEDENT>return path<EOL>

Returns a list of paths to search for config files in reverse order of
precedence.  In other words: the last path element will override the
settings from the first one.


channels = [<EOL>file_info.channels(f) for f in input_filepath_list<EOL>]<EOL>if not core.all_equal(channels):<EOL><INDENT>raise IOError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>.format(combine_type)<EOL>)<EOL><DEDENT>

Check if files in input file list have the same number of channels


def set_input_format(self, file_type=None, rate=None, bits=None,<EOL>channels=None, encoding=None, ignore_length=None):

if file_type is not None and not isinstance(file_type, list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if file_type is not None:<EOL><INDENT>if not all([f in VALID_FORMATS for f in file_type]):<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(VALID_FORMATS)<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>file_type = []<EOL><DEDENT>if rate is not None and not isinstance(rate, list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if rate is not None:<EOL><INDENT>if not all([is_number(r) and r > <NUM_LIT:0> for r in rate]):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rate = []<EOL><DEDENT>if bits is not None and not isinstance(bits, list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if bits is not None:<EOL><INDENT>if not all([isinstance(b, int) and b > <NUM_LIT:0> for b in bits]):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>bits = []<EOL><DEDENT>if channels is not None and not isinstance(channels, list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if channels is not None:<EOL><INDENT>if not all([isinstance(c, int) and c > <NUM_LIT:0> for c in channels]):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>channels = []<EOL><DEDENT>if encoding is not None and not isinstance(encoding, list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if encoding is not None:<EOL><INDENT>if not all([e in ENCODING_VALS for e in encoding]):<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(ENCODING_VALS)<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>encoding = []<EOL><DEDENT>if ignore_length is not None and not isinstance(ignore_length, list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if ignore_length is not None:<EOL><INDENT>if not all([isinstance(l, bool) for l in ignore_length]):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>ignore_length = []<EOL><DEDENT>max_input_arg_len = max([<EOL>len(file_type), len(rate), len(bits), len(channels),<EOL>len(encoding), len(ignore_length)<EOL>])<EOL>input_format = []<EOL>for _ in range(max_input_arg_len):<EOL><INDENT>input_format.append([])<EOL><DEDENT>for i, f in enumerate(file_type):<EOL><INDENT>input_format[i].extend(['<STR_LIT>', '<STR_LIT:{}>'.format(f)])<EOL><DEDENT>for i, r in enumerate(rate):<EOL><INDENT>input_format[i].extend(['<STR_LIT>', '<STR_LIT:{}>'.format(r)])<EOL><DEDENT>for i, b in enumerate(bits):<EOL><INDENT>input_format[i].extend(['<STR_LIT>', '<STR_LIT:{}>'.format(b)])<EOL><DEDENT>for i, c in enumerate(channels):<EOL><INDENT>input_format[i].extend(['<STR_LIT:-c>', '<STR_LIT:{}>'.format(c)])<EOL><DEDENT>for i, e in enumerate(encoding):<EOL><INDENT>input_format[i].extend(['<STR_LIT>', '<STR_LIT:{}>'.format(e)])<EOL><DEDENT>for i, l in enumerate(ignore_length):<EOL><INDENT>if l is True:<EOL><INDENT>input_format[i].append('<STR_LIT>')<EOL><DEDENT><DEDENT>self.input_format = input_format<EOL>return self<EOL>

Sets input file format arguments. This is primarily useful when
        dealing with audio files without a file extension. Overwrites any
        previously set input file arguments.

        If this function is not explicity called the input format is inferred
        from the file extension or the file's header.

        Parameters
        ----------
        file_type : list of str or None, default=None
            The file type of the input audio file. Should be the same as what
            the file extension would be, for ex. 'mp3' or 'wav'.
        rate : list of float or None, default=None
            The sample rate of the input audio file. If None the sample rate
            is inferred.
        bits : list of int or None, default=None
            The number of bits per sample. If None, the number of bits per
            sample is inferred.
        channels : list of int or None, default=None
            The number of channels in the audio file. If None the number of
            channels is inferred.
        encoding : list of str or None, default=None
            The audio encoding type. Sometimes needed with file-types that
            support more than one encoding type. One of:
                * signed-integer : PCM data stored as signed (‘two’s
                    complement’) integers. Commonly used with a 16 or 24−bit
                    encoding size. A value of 0 represents minimum signal
                    power.
                * unsigned-integer : PCM data stored as unsigned integers.
                    Commonly used with an 8-bit encoding size. A value of 0
                    represents maximum signal power.
                * floating-point : PCM data stored as IEEE 753 single precision
                    (32-bit) or double precision (64-bit) floating-point
                    (‘real’) numbers. A value of 0 represents minimum signal
                    power.
                * a-law : International telephony standard for logarithmic
                    encoding to 8 bits per sample. It has a precision
                    equivalent to roughly 13-bit PCM and is sometimes encoded
                    with reversed bit-ordering.
                * u-law : North American telephony standard for logarithmic
                    encoding to 8 bits per sample. A.k.a. μ-law. It has a
                    precision equivalent to roughly 14-bit PCM and is sometimes
                    encoded with reversed bit-ordering.
                * oki-adpcm : OKI (a.k.a. VOX, Dialogic, or Intel) 4-bit ADPCM;
                    it has a precision equivalent to roughly 12-bit PCM. ADPCM
                    is a form of audio compression that has a good compromise
                    between audio quality and encoding/decoding speed.
                * ima-adpcm : IMA (a.k.a. DVI) 4-bit ADPCM; it has a precision
                    equivalent to roughly 13-bit PCM.
                * ms-adpcm : Microsoft 4-bit ADPCM; it has a precision
                    equivalent to roughly 14-bit PCM.
                * gsm-full-rate : GSM is currently used for the vast majority
                    of the world’s digital wireless telephone calls. It
                    utilises several audio formats with different bit-rates and
                    associated speech quality. SoX has support for GSM’s
                    original 13kbps ‘Full Rate’ audio format. It is usually
                    CPU-intensive to work with GSM audio.
        ignore_length : list of bool or None, default=None
            If True, overrides an (incorrect) audio length given in an audio
            file’s header. If this option is given then SoX will keep reading
            audio until it reaches the end of the input file.


def rate(self, samplerate, quality='<STR_LIT:h>'):

quality_vals = ['<STR_LIT:q>', '<STR_LIT:l>', '<STR_LIT:m>', '<STR_LIT:h>', '<STR_LIT:v>']<EOL>if not is_number(samplerate) or samplerate <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if quality not in quality_vals:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>".format('<STR_LIT:U+0020>'.join(quality_vals))<EOL>)<EOL><DEDENT>effect_args = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'.format(quality),<EOL>'<STR_LIT>'.format(samplerate)<EOL>]<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Change the audio sampling rate (i.e. resample the audio) to any
        given `samplerate`. Better the resampling quality = slower runtime.

        Parameters
        ----------
        samplerate : float
            Desired sample rate.
        quality : str
            Resampling quality. One of:
             * q : Quick - very low quality,
             * l : Low,
             * m : Medium,
             * h : High (default),
             * v : Very high

        See Also
        --------
        upsample, downsample, convert


if not isinstance(positions, list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not all((is_number(p) and p >= <NUM_LIT:0>) for p in positions):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>effect_args = ['<STR_LIT>']<EOL>effect_args.extend(['<STR_LIT>'.format(p) for p in positions])<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Delay one or more audio channels such that they start at the given
        positions.

        Parameters
        ----------
        positions: list of floats
            List of times (in seconds) to delay each audio channel.
            If fewer positions are given than the number of channels, the
            remaining channels will be unaffected.


def noisered(self, profile_path, amount=<NUM_LIT:0.5>):

if not os.path.exists(profile_path):<EOL><INDENT>raise IOError(<EOL>"<STR_LIT>".format(profile_path))<EOL><DEDENT>if not is_number(amount) or amount < <NUM_LIT:0> or amount > <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>effect_args = [<EOL>'<STR_LIT>',<EOL>profile_path,<EOL>'<STR_LIT>'.format(amount)<EOL>]<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Reduce noise in the audio signal by profiling and filtering.
        This effect is moderately effective at removing consistent
        background noise such as hiss or hum.

        Parameters
        ----------
        profile_path : str
            Path to a noise profile file.
            This file can be generated using the `noiseprof` effect.
        amount : float, default=0.5
            How much noise should be removed is specified by amount. Should
            be between 0 and 1.  Higher numbers will remove more noise but
            present a greater likelihood  of  removing wanted  components  of
            the  audio  signal.

        See Also
        --------
        noiseprof


def vad(self, location=<NUM_LIT:1>, normalize=True, activity_threshold=<NUM_LIT>,<EOL>min_activity_duration=<NUM_LIT>, initial_search_buffer=<NUM_LIT:1.0>,<EOL>max_gap=<NUM_LIT>, initial_pad=<NUM_LIT:0.0>):

if location not in [-<NUM_LIT:1>, <NUM_LIT:1>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(normalize, bool):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_number(activity_threshold):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_number(min_activity_duration) or min_activity_duration < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_number(initial_search_buffer) or initial_search_buffer < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_number(max_gap) or max_gap < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_number(initial_pad) or initial_pad < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>effect_args = []<EOL>if normalize:<EOL><INDENT>effect_args.append('<STR_LIT>')<EOL><DEDENT>if location == -<NUM_LIT:1>:<EOL><INDENT>effect_args.append('<STR_LIT>')<EOL><DEDENT>effect_args.extend([<EOL>'<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>'.format(activity_threshold),<EOL>'<STR_LIT>', '<STR_LIT>'.format(min_activity_duration),<EOL>'<STR_LIT>', '<STR_LIT>'.format(initial_search_buffer),<EOL>'<STR_LIT>', '<STR_LIT>'.format(max_gap),<EOL>'<STR_LIT>', '<STR_LIT>'.format(initial_pad)<EOL>])<EOL>if location == -<NUM_LIT:1>:<EOL><INDENT>effect_args.append('<STR_LIT>')<EOL><DEDENT>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Voice Activity Detector. Attempts to trim silence and quiet
        background sounds from the ends of recordings of speech. The algorithm
        currently uses a simple cepstral power measurement to detect voice, so
        may be fooled by other things, especially music.

        The effect can trim only from the front of the audio, so in order to
        trim from the back, the reverse effect must also be used.

        Parameters
        ----------
        location : 1 or -1, default=1
            If 1, trims silence from the beginning
            If -1, trims silence from the end
        normalize : bool, default=True
            If true, normalizes audio before processing.
        activity_threshold : float, default=7.0
            The measurement level used to trigger activity detection. This may
            need to be cahnged depending on the noise level, signal level, and
            other characteristics of the input audio.
        min_activity_duration : float, default=0.25
            The time constant (in seconds) used to help ignore short bursts of
            sound.
        initial_search_buffer : float, default=1.0
            The amount of audio (in seconds) to search for quieter/shorter
            bursts of audio to include prior to the detected trigger point.
        max_gap : float, default=0.25
            The allowed gap (in seconds) between quiteter/shorter bursts of
            audio to include prior to the detected trigger point
        initial_pad : float, default=0.0
            The amount of audio (in seconds) to preserve before the trigger
            point and any found quieter/shorter bursts.

        See Also
        --------
        silence

        Examples
        --------
        >>> tfm = sox.Transformer()

        Remove silence from the beginning of speech

        >>> tfm.vad(initial_pad=0.3)

        Remove silence from the end of speech

        >>> tfm.vad(location=-1, initial_pad=0.2)


def set_input_format(self, file_type=None, rate=None, bits=None,<EOL>channels=None, encoding=None, ignore_length=False):

if file_type not in VALID_FORMATS + [None]:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(VALID_FORMATS)<EOL>)<EOL><DEDENT>if not is_number(rate) and rate is not None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if rate is not None and rate <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if not isinstance(bits, int) and bits is not None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if bits is not None and bits <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if not isinstance(channels, int) and channels is not None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if channels is not None and channels <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if encoding not in ENCODING_VALS + [None]:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'.format(ENCODING_VALS)<EOL>)<EOL><DEDENT>if not isinstance(ignore_length, bool):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>input_format = []<EOL>if file_type is not None:<EOL><INDENT>input_format.extend(['<STR_LIT>', '<STR_LIT:{}>'.format(file_type)])<EOL><DEDENT>if rate is not None:<EOL><INDENT>input_format.extend(['<STR_LIT>', '<STR_LIT>'.format(rate)])<EOL><DEDENT>if bits is not None:<EOL><INDENT>input_format.extend(['<STR_LIT>', '<STR_LIT:{}>'.format(bits)])<EOL><DEDENT>if channels is not None:<EOL><INDENT>input_format.extend(['<STR_LIT:-c>', '<STR_LIT:{}>'.format(channels)])<EOL><DEDENT>if encoding is not None:<EOL><INDENT>input_format.extend(['<STR_LIT>', '<STR_LIT:{}>'.format(encoding)])<EOL><DEDENT>if ignore_length:<EOL><INDENT>input_format.append('<STR_LIT>')<EOL><DEDENT>self.input_format = input_format<EOL>return self<EOL>

Sets input file format arguments. This is primarily useful when
        dealing with audio files without a file extension. Overwrites any
        previously set input file arguments.

        If this function is not explicity called the input format is inferred
        from the file extension or the file's header.

        Parameters
        ----------
        file_type : str or None, default=None
            The file type of the input audio file. Should be the same as what
            the file extension would be, for ex. 'mp3' or 'wav'.
        rate : float or None, default=None
            The sample rate of the input audio file. If None the sample rate
            is inferred.
        bits : int or None, default=None
            The number of bits per sample. If None, the number of bits per
            sample is inferred.
        channels : int or None, default=None
            The number of channels in the audio file. If None the number of
            channels is inferred.
        encoding : str or None, default=None
            The audio encoding type. Sometimes needed with file-types that
            support more than one encoding type. One of:
                * signed-integer : PCM data stored as signed (‘two’s
                    complement’) integers. Commonly used with a 16 or 24−bit
                    encoding size. A value of 0 represents minimum signal
                    power.
                * unsigned-integer : PCM data stored as unsigned integers.
                    Commonly used with an 8-bit encoding size. A value of 0
                    represents maximum signal power.
                * floating-point : PCM data stored as IEEE 753 single precision
                    (32-bit) or double precision (64-bit) floating-point
                    (‘real’) numbers. A value of 0 represents minimum signal
                    power.
                * a-law : International telephony standard for logarithmic
                    encoding to 8 bits per sample. It has a precision
                    equivalent to roughly 13-bit PCM and is sometimes encoded
                    with reversed bit-ordering.
                * u-law : North American telephony standard for logarithmic
                    encoding to 8 bits per sample. A.k.a. μ-law. It has a
                    precision equivalent to roughly 14-bit PCM and is sometimes
                    encoded with reversed bit-ordering.
                * oki-adpcm : OKI (a.k.a. VOX, Dialogic, or Intel) 4-bit ADPCM;
                    it has a precision equivalent to roughly 12-bit PCM. ADPCM
                    is a form of audio compression that has a good compromise
                    between audio quality and encoding/decoding speed.
                * ima-adpcm : IMA (a.k.a. DVI) 4-bit ADPCM; it has a precision
                    equivalent to roughly 13-bit PCM.
                * ms-adpcm : Microsoft 4-bit ADPCM; it has a precision
                    equivalent to roughly 14-bit PCM.
                * gsm-full-rate : GSM is currently used for the vast majority
                    of the world’s digital wireless telephone calls. It
                    utilises several audio formats with different bit-rates and
                    associated speech quality. SoX has support for GSM’s
                    original 13kbps ‘Full Rate’ audio format. It is usually
                    CPU-intensive to work with GSM audio.
        ignore_length : bool, default=False
            If True, overrides an (incorrect) audio length given in an audio
            file’s header. If this option is given then SoX will keep reading
            audio until it reaches the end of the input file.


if not is_number(shift) or shift < -<NUM_LIT:2> or shift > <NUM_LIT:2>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>effect_args = ['<STR_LIT>', '<STR_LIT>'.format(shift)]<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Apply a DC shift to the audio.

        Parameters
        ----------
        shift : float
            Amount to shift audio between -2 and 2. (Audio is between -1 and 1)

        See Also
        --------
        highpass


if not is_number(amount) or amount < <NUM_LIT:0> or amount > <NUM_LIT:100>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>effect_args = ['<STR_LIT>', '<STR_LIT>'.format(amount)]<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Comparable with compression, this effect modifies an audio signal to
        make it sound louder.

        Parameters
        ----------
        amount : float
            Amount of enhancement between 0 and 100.

        See Also
        --------
        compand, mcompand


def gain(self, gain_db=<NUM_LIT:0.0>, normalize=True, limiter=False, balance=None):

if not is_number(gain_db):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(normalize, bool):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(limiter, bool):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if balance not in [None, '<STR_LIT:e>', '<STR_LIT:B>', '<STR_LIT:b>']:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>effect_args = ['<STR_LIT>']<EOL>if balance is not None:<EOL><INDENT>effect_args.append('<STR_LIT>'.format(balance))<EOL><DEDENT>if normalize:<EOL><INDENT>effect_args.append('<STR_LIT>')<EOL><DEDENT>if limiter:<EOL><INDENT>effect_args.append('<STR_LIT>')<EOL><DEDENT>effect_args.append('<STR_LIT>'.format(gain_db))<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Apply amplification or attenuation to the audio signal.

        Parameters
        ----------
        gain_db : float, default=0.0
            Gain adjustment in decibels (dB).
        normalize : bool, default=True
            If True, audio is normalized to gain_db relative to full scale.
            If False, simply adjusts the audio power level by gain_db.
        limiter : bool, default=False
            If True, a simple limiter is invoked to prevent clipping.
        balance : str or None, default=None
            Balance gain across channels. Can be one of:
             * None applies no balancing (default)
             * 'e' applies gain to all channels other than that with the
                highest peak level, such that all channels attain the same
                peak level
             * 'B' applies gain to all channels other than that with the
                highest RMS level, such that all channels attain the same
                RMS level
             * 'b' applies gain with clipping protection to all channels other
                than that with the highest RMS level, such that all channels
                attain the same RMS level
            If normalize=True, 'B' and 'b' are equivalent.

        See Also
        --------
        loudness


def pitch(self, n_semitones, quick=False):

if not is_number(n_semitones):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n_semitones < -<NUM_LIT:12> or n_semitones > <NUM_LIT:12>:<EOL><INDENT>logger.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if not isinstance(quick, bool):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>effect_args = ['<STR_LIT>']<EOL>if quick:<EOL><INDENT>effect_args.append('<STR_LIT>')<EOL><DEDENT>effect_args.append('<STR_LIT>'.format(n_semitones * <NUM_LIT>))<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Pitch shift the audio without changing the tempo.

        This effect uses the WSOLA algorithm. The audio is chopped up into
        segments which are then shifted in the time domain and overlapped
        (cross-faded) at points where their waveforms are most similar as
        determined by measurement of least squares.

        Parameters
        ----------
        n_semitones : float
            The number of semitones to shift. Can be positive or negative.
        quick : bool, default=False
            If True, this effect will run faster but with lower sound quality.

        See Also
        --------
        bend, speed, tempo


def stat(self, input_filepath, scale=None, rms=False):

effect_args = ['<STR_LIT>', '<STR_LIT:1>', '<STR_LIT>']<EOL>if scale is not None:<EOL><INDENT>if not is_number(scale) or scale <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>effect_args.extend(['<STR_LIT>', '<STR_LIT>'.format(scale)])<EOL><DEDENT>if rms:<EOL><INDENT>effect_args.append('<STR_LIT>')<EOL><DEDENT>_, _, stat_output = self.build(<EOL>input_filepath, None, extra_args=effect_args, return_output=True<EOL>)<EOL>stat_dict = {}<EOL>lines = stat_output.split('<STR_LIT:\n>')<EOL>for line in lines:<EOL><INDENT>split_line = line.split()<EOL>if len(split_line) == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>value = split_line[-<NUM_LIT:1>]<EOL>key = '<STR_LIT:U+0020>'.join(split_line[:-<NUM_LIT:1>])<EOL>stat_dict[key.strip('<STR_LIT::>')] = value<EOL><DEDENT>return stat_dict<EOL>

Display time and frequency domain statistical information about the
        audio. Audio is passed unmodified through the SoX processing chain.

        Unlike other Transformer methods, this does not modify the transformer
        effects chain. Instead it computes statistics on the output file that
        would be created if the build command were invoked.

        Note: The file is downmixed to mono prior to computation.

        Parameters
        ----------
        input_filepath : str
            Path to input file to compute stats on.
        scale : float or None, default=None
            If not None, scales the input by the given scale factor.
        rms : bool, default=False
            If True, scales all values by the average rms amplitude.

        Returns
        -------
        stat_dict : dict
            Dictionary of statistics.

        See Also
        --------
        stats, power_spectrum, sox.file_info


def bandreject(self, frequency, width_q=<NUM_LIT>):

if not is_number(frequency) or frequency <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_number(width_q) or width_q <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>effect_args = [<EOL>'<STR_LIT>', '<STR_LIT>'.format(frequency), '<STR_LIT>'.format(width_q)<EOL>]<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Apply a two-pole Butterworth band-reject filter with the given
        central frequency, and (3dB-point) band-width. The filter rolls off at
        6dB per octave (20dB per decade) and is described in detail in
        http://musicdsp.org/files/Audio-EQ-Cookbook.txt

        Parameters
        ----------
        frequency : float
            The filter's center frequency in Hz.
        width_q : float, default=2.0
            The filter's width as a Q-factor.
        constant_skirt : bool, default=False
            If True, selects constant skirt gain (peak gain = width_q).
            If False, selects constant 0dB peak gain.

        See Also
        --------
        bandreject, sinc


def echos(self, gain_in=<NUM_LIT>, gain_out=<NUM_LIT>, n_echos=<NUM_LIT:1>, delays=[<NUM_LIT>],<EOL>decays=[<NUM_LIT>]):

if not is_number(gain_in) or gain_in <= <NUM_LIT:0> or gain_in > <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_number(gain_out) or gain_out <= <NUM_LIT:0> or gain_out > <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(n_echos, int) or n_echos <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(delays, list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(delays) != n_echos:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if any((not is_number(p) or p <= <NUM_LIT:0>) for p in delays):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(decays, list):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(decays) != n_echos:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if any((not is_number(p) or p <= <NUM_LIT:0> or p > <NUM_LIT:1>) for p in decays):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>effect_args = [<EOL>'<STR_LIT>', '<STR_LIT>'.format(gain_in), '<STR_LIT>'.format(gain_out)<EOL>]<EOL>for i in range(n_echos):<EOL><INDENT>effect_args.extend([<EOL>'<STR_LIT>'.format(delays[i]),<EOL>'<STR_LIT>'.format(decays[i])<EOL>])<EOL><DEDENT>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Add a sequence of echoes to the audio.

        Like the echo effect, echos stand for ‘ECHO in Sequel’, that is the
        first echos takes the input, the second the input and the first echos,
        the third the input and the first and the second echos, ... and so on.
        Care should be taken using many echos; a single echos has the same
        effect as a single echo.

        Parameters
        ----------
        gain_in : float, default=0.8
            Input volume, between 0 and 1
        gain_out : float, default=0.9
            Output volume, between 0 and 1
        n_echos : int, default=1
            Number of reflections
        delays : list, default=[60]
            List of delays in miliseconds
        decays : list, default=[0.4]
            List of decays, relative to gain in between 0 and 1

        See Also
        --------
        echo, reverb, chorus


def reverb(self, reverberance=<NUM_LIT:50>, high_freq_damping=<NUM_LIT:50>, room_scale=<NUM_LIT:100>,<EOL>stereo_depth=<NUM_LIT:100>, pre_delay=<NUM_LIT:0>, wet_gain=<NUM_LIT:0>, wet_only=False):

if (not is_number(reverberance) or reverberance < <NUM_LIT:0> or<EOL>reverberance > <NUM_LIT:100>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (not is_number(high_freq_damping) or high_freq_damping < <NUM_LIT:0> or<EOL>high_freq_damping > <NUM_LIT:100>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (not is_number(room_scale) or room_scale < <NUM_LIT:0> or<EOL>room_scale > <NUM_LIT:100>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (not is_number(stereo_depth) or stereo_depth < <NUM_LIT:0> or<EOL>stereo_depth > <NUM_LIT:100>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_number(pre_delay) or pre_delay < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not is_number(wet_gain):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(wet_only, bool):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>effect_args = ['<STR_LIT>']<EOL>if wet_only:<EOL><INDENT>effect_args.append('<STR_LIT>')<EOL><DEDENT>effect_args.extend([<EOL>'<STR_LIT>'.format(reverberance),<EOL>'<STR_LIT>'.format(high_freq_damping),<EOL>'<STR_LIT>'.format(room_scale),<EOL>'<STR_LIT>'.format(stereo_depth),<EOL>'<STR_LIT>'.format(pre_delay),<EOL>'<STR_LIT>'.format(wet_gain)<EOL>])<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Add reverberation to the audio using the ‘freeverb’ algorithm.
        A reverberation effect is sometimes desirable for concert halls that
        are too small or contain so many people that the hall’s natural
        reverberance is diminished. Applying a small amount of stereo reverb
        to a (dry) mono signal will usually make it sound more natural.

        Parameters
        ----------
        reverberance : float, default=50
            Percentage of reverberance
        high_freq_damping : float, default=50
            Percentage of high-frequency damping.
        room_scale : float, default=100
            Scale of the room as a percentage.
        stereo_depth : float, default=100
            Stereo depth as a percentage.
        pre_delay : float, default=0
            Pre-delay in milliseconds.
        wet_gain : float, default=0
            Amount of wet gain in dB
        wet_only : bool, default=False
            If True, only outputs the wet signal.

        See Also
        --------
        echo


if not isinstance(n_channels, int) or n_channels <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>effect_args = ['<STR_LIT>', '<STR_LIT:{}>'.format(n_channels)]<EOL>self.effects.extend(effect_args)<EOL>self.effects_log.append('<STR_LIT>')<EOL>return self<EOL>

Change the number of channels in the audio signal. If decreasing the
        number of channels it mixes channels together, if increasing the number
        of channels it duplicates.

        Note: This overrides arguments used in the convert effect!

        Parameters
        ----------
        n_channels : int
            Desired number of channels.

        See Also
        --------
        convert


effect_args = ['<STR_LIT>', '<STR_LIT:1>', '<STR_LIT>']<EOL>_, _, stats_output = self.build(<EOL>input_filepath, None, extra_args=effect_args, return_output=True<EOL>)<EOL>stats_dict = {}<EOL>lines = stats_output.split('<STR_LIT:\n>')<EOL>for line in lines:<EOL><INDENT>split_line = line.split()<EOL>if len(split_line) == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>value = split_line[-<NUM_LIT:1>]<EOL>key = '<STR_LIT:U+0020>'.join(split_line[:-<NUM_LIT:1>])<EOL>stats_dict[key] = value<EOL><DEDENT>return stats_dict<EOL>

Display time domain statistical information about the audio
        channels. Audio is passed unmodified through the SoX processing chain.
        Statistics are calculated and displayed for each audio channel

        Unlike other Transformer methods, this does not modify the transformer
        effects chain. Instead it computes statistics on the output file that
        would be created if the build command were invoked.

        Note: The file is downmixed to mono prior to computation.

        Parameters
        ----------
        input_filepath : str
            Path to input file to compute stats on.

        Returns
        -------
        stats_dict : dict
            List of frequency (Hz), amplitude pairs.

        See Also
        --------
        stat, sox.file_info


effect_args = ['<STR_LIT>', '<STR_LIT:1>', '<STR_LIT>', '<STR_LIT>']<EOL>_, _, stat_output = self.build(<EOL>input_filepath, None, extra_args=effect_args, return_output=True<EOL>)<EOL>power_spectrum = []<EOL>lines = stat_output.split('<STR_LIT:\n>')<EOL>for line in lines:<EOL><INDENT>split_line = line.split()<EOL>if len(split_line) != <NUM_LIT:2>:<EOL><INDENT>continue<EOL><DEDENT>freq, amp = split_line<EOL>power_spectrum.append([float(freq), float(amp)])<EOL><DEDENT>return power_spectrum<EOL>

Calculates the power spectrum (4096 point DFT). This method
        internally invokes the stat command with the -freq option.

        Note: The file is downmixed to mono prior to computation.

        Parameters
        ----------
        input_filepath : str
            Path to input file to compute stats on.

        Returns
        -------
        power_spectrum : list
            List of frequency (Hz), amplitude pairs.

        See Also
        --------
        stat, stats, sox.file_info