Example #1
0
    def test_find_section(self):
        xml = u"""
        <REGTEXT>
        <AMDPAR>
            In 200.1 revise paragraph (b) as follows:
        </AMDPAR>
        <SECTION>
            <SECTNO>200.1</SECTNO>
            <SUBJECT>Authority and Purpose.</SUBJECT>
            <P> (b) This part is very important. </P>
        </SECTION>
        <AMDPAR>
            In 200.3 revise paragraph (b)(1) as follows:
        </AMDPAR>
        <SECTION>
            <SECTNO>200.3</SECTNO>
            <SUBJECT>Definitions</SUBJECT>
            <P> (b)(1) Define a term here. </P>
        </SECTION>
        </REGTEXT>"""

        notice_xml = etree.fromstring(xml)
        amdpar_xml = notice_xml.xpath('//AMDPAR')[0]
        section = diff.find_section(amdpar_xml)
        self.assertEqual(section.tag, 'SECTION')

        sectno_xml = section.xpath('//SECTNO')[0]
        self.assertEqual(sectno_xml.text, '200.1')
    def test_find_section(self):
        xml = u"""
        <REGTEXT>
        <AMDPAR>
            In 200.1 revise paragraph (b) as follows:
        </AMDPAR>
        <SECTION>
            <SECTNO>200.1</SECTNO>
            <SUBJECT>Authority and Purpose.</SUBJECT>
            <P> (b) This part is very important. </P>
        </SECTION>
        <AMDPAR>
            In 200.3 revise paragraph (b)(1) as follows:
        </AMDPAR>
        <SECTION>
            <SECTNO>200.3</SECTNO>
            <SUBJECT>Definitions</SUBJECT>
            <P> (b)(1) Define a term here. </P>
        </SECTION>
        </REGTEXT>"""

        notice_xml = etree.fromstring(xml)
        amdpar_xml = notice_xml.xpath("//AMDPAR")[0]
        section = diff.find_section(amdpar_xml)
        self.assertEqual(section.tag, "SECTION")

        sectno_xml = section.xpath("//SECTNO")[0]
        self.assertEqual(sectno_xml.text, "200.1")
Example #3
0
def process_amendments(notice, notice_xml):
    """ Process the changes to the regulation that are expressed in the notice.
    """
    amends = []
    notice_changes = changes.NoticeChanges()

    amdpars_by_parent = []
    for par in notice_xml.xpath('//AMDPAR'):
        parent = par.getparent()
        exists = filter(lambda aXp: aXp.parent == parent, amdpars_by_parent)
        if exists:
            exists[0].append(par)
        else:
            amdpars_by_parent.append(AmdparByParent(parent, par))

    for aXp in amdpars_by_parent:
        amended_labels = []
        designate_labels, other_labels = [], []
        context = [aXp.parent.get('PART') or notice['cfr_part']]
        for par in aXp.amdpars:
            als, context = parse_amdpar(par, context)
            amended_labels.extend(als)

        for al in amended_labels:
            if isinstance(al, DesignateAmendment):
                subpart_changes = process_designate_subpart(al)
                if subpart_changes:
                    notice_changes.update(subpart_changes)
                designate_labels.append(al)
            elif new_subpart_added(al, notice['cfr_part']):
                notice_changes.update(process_new_subpart(notice, al, par))
                designate_labels.append(al)
            else:
                other_labels.append(al)

        create_xmlless_changes(other_labels, notice_changes)

        section_xml = find_section(par)
        if section_xml is not None:
            for section in reg_text.build_from_section(
                    notice['cfr_part'], section_xml):
                create_xml_changes(other_labels, section, notice_changes)

        for appendix in parse_appendix_changes(other_labels,
                                               notice['cfr_part'], aXp.parent):
            create_xml_changes(other_labels, appendix, notice_changes)

        interp = parse_interp_changes(other_labels, notice['cfr_part'],
                                      aXp.parent)
        if interp:
            create_xml_changes(other_labels, interp, notice_changes)

        amends.extend(designate_labels)
        amends.extend(other_labels)
    if amends:
        notice['amendments'] = amends
        notice['changes'] = notice_changes.changes
 def test_find_section_lost(self):
     with self.tree.builder("PART") as part:
         with part.REGTEXT() as regtext:
             regtext.AMDPAR(u"3. In § 105.1, revise paragraph (b) to read "
                            "as follows:")
         with part.REGTEXT() as regtext:
             with regtext.SECTION() as section:
                 section.SECTNO(" 205.4 ")
                 section.SUBJECT("[Corrected]")
     amdpar = self.tree.render_xml().xpath('//AMDPAR')[0]
     section = diff.find_section(amdpar)
     self.assertNotEqual(None, section)
    def test_find_section_paragraphs(self):
        with self.tree.builder('REGTEXT') as regtext:
            with regtext.SECTION() as section:
                section.SECTNO(" 205.4 ")
                section.SUBJECT("[Corrected]")
            regtext.AMDPAR(u"3. In § 105.1, revise paragraph (b) to read as "
                           "follows:")
            regtext.P("(b) paragraph 1")

        amdpar = self.tree.render_xml().xpath('//AMDPAR')[0]
        section = diff.find_section(amdpar)
        self.assertNotEqual(None, section)
        paragraphs = [p for p in section if p.tag == 'P']
        self.assertEqual(paragraphs[0].text, '(b) paragraph 1')
Example #6
0
def process_amendments(notice, notice_xml):
    """Process changes to the regulation that are expressed in the notice."""
    all_amends = []     # will be added to the notice
    cfr_part = notice['cfr_parts'][0]
    notice_changes = changes.NoticeChanges()

    # process amendments in batches, based on their parent XML
    for amdparent in notice_xml.xpath('//AMDPAR/..'):
        context = [amdparent.get('PART') or cfr_part]
        amendments_by_section = defaultdict(list)
        normal_amends = []  # amendments not moving or adding a subpart
        for amdpar in amdparent.xpath('.//AMDPAR'):
            amendments, context = parse_amdpar(amdpar, context)
            section_xml = find_section(amdpar)
            for amendment in amendments:
                all_amends.append(amendment)
                if isinstance(amendment, DesignateAmendment):
                    subpart_changes = process_designate_subpart(amendment)
                    if subpart_changes:
                        notice_changes.update(subpart_changes)
                elif new_subpart_added(amendment):
                    notice_changes.update(process_new_subpart(
                        notice, amendment, amdpar))
                elif section_xml is None:
                    normal_amends.append(amendment)
                else:
                    normal_amends.append(amendment)
                    amendments_by_section[section_xml].append(amendment)

        cfr_part = context[0]   # carry the part through to the next amdparent
        create_xmlless_changes(normal_amends, notice_changes)
        # Process amendments relating to a specific section in batches, too
        for section_xml, related_amends in amendments_by_section.items():
            for section in reg_text.build_from_section(cfr_part, section_xml):
                create_xml_changes(related_amends, section, notice_changes)

        for appendix in parse_appendix_changes(normal_amends, cfr_part,
                                               amdparent):
            create_xml_changes(normal_amends, appendix, notice_changes)

        interp = parse_interp_changes(normal_amends, cfr_part, amdparent)
        if interp:
            create_xml_changes(normal_amends, interp, notice_changes)

    if all_amends:
        notice['amendments'] = all_amends
        notice['changes'] = notice_changes.changes

    return notice
 def test_find_section_lost(self):
     amdpar_xml = u"""
         <PART>
         <REGTEXT>
             <AMDPAR>
                 3. In § 105.1, revise paragraph (b) to read as follows:
             </AMDPAR>
         </REGTEXT>
         <REGTEXT>
             <SECTION>
                 <SECTNO> 205.4 </SECTNO>
                 <SUBJECT>[Corrected]</SUBJECT>
             </SECTION>
         </REGTEXT></PART>"""
     amdpar = etree.fromstring(amdpar_xml).xpath("//AMDPAR")[0]
     section = diff.find_section(amdpar)
     self.assertNotEqual(None, section)
Example #8
0
 def test_find_section_lost(self):
     amdpar_xml = u"""
         <PART>
         <REGTEXT>
             <AMDPAR>
                 3. In § 105.1, revise paragraph (b) to read as follows:
             </AMDPAR>
         </REGTEXT>
         <REGTEXT>
             <SECTION>
                 <SECTNO> 205.4 </SECTNO>
                 <SUBJECT>[Corrected]</SUBJECT>
             </SECTION>
         </REGTEXT></PART>"""
     amdpar = etree.fromstring(amdpar_xml).xpath('//AMDPAR')[0]
     section = diff.find_section(amdpar)
     self.assertNotEqual(None, section)
    def test_find_section_paragraphs(self):
        amdpar_xml = u"""
            <REGTEXT>
                <SECTION>
                    <SECTNO> 205.4 </SECTNO>
                    <SUBJECT>[Corrected]</SUBJECT>
                </SECTION>
                <AMDPAR>
                    3. In § 105.1, revise paragraph (b) to read as follows:
                </AMDPAR>
                <P>(b) paragraph 1</P>
            </REGTEXT>"""

        amdpar = etree.fromstring(amdpar_xml).xpath("//AMDPAR")[0]
        section = diff.find_section(amdpar)
        self.assertNotEqual(None, section)
        paragraphs = [p for p in section if p.tag == "P"]
        self.assertEqual(paragraphs[0].text, "(b) paragraph 1")
Example #10
0
    def test_find_section_paragraphs(self):
        amdpar_xml = u"""
            <REGTEXT>
                <SECTION>
                    <SECTNO> 205.4 </SECTNO>
                    <SUBJECT>[Corrected]</SUBJECT>
                </SECTION>
                <AMDPAR>
                    3. In § 105.1, revise paragraph (b) to read as follows:
                </AMDPAR>
                <P>(b) paragraph 1</P>
            </REGTEXT>"""

        amdpar = etree.fromstring(amdpar_xml).xpath('//AMDPAR')[0]
        section = diff.find_section(amdpar)
        self.assertNotEqual(None, section)
        paragraphs = [p for p in section if p.tag == 'P']
        self.assertEqual(paragraphs[0].text, '(b) paragraph 1')
    def test_find_section(self):
        with self.tree.builder('REGTEXT') as regtext:
            regtext.AMDPAR("In 200.1 revise paragraph (b) as follows:")
            with regtext.SECTION() as section:
                section.SECTNO("200.1")
                section.SUBJECT("Authority and Purpose.")
                section.P(" (b) This part is very important. ")
            regtext.AMDPAR("In 200.3 revise paragraph (b)(1) as follows:")
            with regtext.SECTION() as section:
                section.SECTNO("200.3")
                section.SUBJECT("Definitions")
                section.P(" (b)(1) Define a term here. ")

        notice_xml = self.tree.render_xml()
        amdpar_xml = notice_xml.xpath('//AMDPAR')[0]
        section = diff.find_section(amdpar_xml)
        self.assertEqual(section.tag, 'SECTION')

        sectno_xml = section.xpath('./SECTNO')[0]
        self.assertEqual(sectno_xml.text, '200.1')
Example #12
0
def process_amendments(notice, notice_xml):
    """ Process the changes to the regulation that are expressed in the notice.
    """
    amends = []
    notice_changes = changes.NoticeChanges()

    amdpars_by_parent = []
    for par in notice_xml.xpath('//AMDPAR'):
        parent = par.getparent()
        exists = filter(lambda aXp: aXp.parent == parent, amdpars_by_parent)
        if exists:
            exists[0].append(par)
        else:
            amdpars_by_parent.append(AmdparByParent(parent, par))

    default_cfr_part = notice['cfr_parts'][0]
    for aXp in amdpars_by_parent:
        amended_labels = []
        designate_labels, other_labels = [], []
        context = [aXp.parent.get('PART') or default_cfr_part]
        for par in aXp.amdpars:
            als, context = parse_amdpar(par, context)
            amended_labels.extend(als)

            labels_by_part = defaultdict(list)
            for al in amended_labels:
                if isinstance(al, DesignateAmendment):
                    subpart_changes = process_designate_subpart(al)
                    if subpart_changes:
                        notice_changes.update(subpart_changes)
                    designate_labels.append(al)
                elif new_subpart_added(al):
                    notice_changes.update(process_new_subpart(notice, al, par))
                    designate_labels.append(al)
                else:
                    other_labels.append(al)
                    labels_by_part[al.label[0]].append(al)

            create_xmlless_changes(other_labels, notice_changes)

            for cfr_part, rel_labels in labels_by_part.iteritems():
                section_xml = find_section(par)
                if section_xml is not None:
                    subparts = aXp.parent.xpath('.//SUBPART/HD')
                    if subparts:
                        subpart_label = [cfr_part, 'Subpart',
                                         subparts[0].text[8:9]]
                    else:
                        subpart_label = None

                    for section in reg_text.build_from_section(cfr_part,
                                                               section_xml):
                        create_xml_changes(rel_labels, section, notice_changes,
                                           subpart_label)

                for appendix in parse_appendix_changes(rel_labels, cfr_part,
                                                       aXp.parent):
                    create_xml_changes(rel_labels, appendix, notice_changes)

                interp = parse_interp_changes(rel_labels, cfr_part, aXp.parent)
                if interp:
                    create_xml_changes(rel_labels, interp, notice_changes)

            amends.extend(designate_labels)
            amends.extend(other_labels)

            if other_labels:    # Carry cfr_part through amendments
                default_cfr_part = other_labels[-1].label[0]

    if amends:
        notice['amendments'] = amends
        notice['changes'] = notice_changes.changes
    elif notice['document_number'] in settings.REISSUANCES:
        notice['changes'] = {
            default_cfr_part: [{
                'action': 'PUT',
                'node': reg_text.build_tree(notice_xml)
            }]
        }
Example #13
0
def process_amendments(notice, notice_xml):
    """ Process the changes to the regulation that are expressed in the notice.
    """
    amends = []
    notice_changes = changes.NoticeChanges()

    amdpars_by_parent = []
    for par in notice_xml.xpath('//AMDPAR'):
        parent = par.getparent()
        exists = filter(lambda aXp: aXp.parent == parent, amdpars_by_parent)
        if exists:
            exists[0].append(par)
        else:
            amdpars_by_parent.append(AmdparByParent(parent, par))

    default_cfr_part = notice['cfr_part']
    for aXp in amdpars_by_parent:
        amended_labels = []
        designate_labels, other_labels = [], []
        context = [default_cfr_part]
        for par in aXp.amdpars:
            als, context = parse_amdpar(par, context)
            amended_labels.extend(als)

            labels_by_part = defaultdict(list)
            for al in amended_labels:
                if isinstance(al, DesignateAmendment):
                    subpart_changes = process_designate_subpart(al)
                    if subpart_changes:
                        notice_changes.update(subpart_changes)
                    designate_labels.append(al)
                elif new_subpart_added(al):
                    notice_changes.update(process_new_subpart(notice, al, par))
                    designate_labels.append(al)
                else:
                    other_labels.append(al)
                    labels_by_part[al.label[0]].append(al)

            create_xmlless_changes(other_labels, notice_changes)

            # for cfr_part, rel_labels in labels_by_part.iteritems():
            labels_for_part = {
                part: labels
                for part, labels in labels_by_part.iteritems()
                if part == default_cfr_part
            }
            print(labels_for_part)
            for cfr_part, rel_labels in labels_for_part.iteritems():
                section_xml = find_section(par)
                if section_xml is not None:
                    subparts = aXp.parent.xpath('.//SUBPART/HD')
                    if subparts:
                        subpart_label = [
                            cfr_part, 'Subpart', subparts[0].text[8:9]
                        ]
                    else:
                        subpart_label = None

                    for section in reg_text.build_from_section(
                            cfr_part, section_xml):
                        create_xml_changes(rel_labels, section, notice_changes,
                                           subpart_label)

                for appendix in parse_appendix_changes(rel_labels, cfr_part,
                                                       aXp.parent):
                    create_xml_changes(rel_labels, appendix, notice_changes)

                interp = parse_interp_changes(rel_labels, cfr_part, aXp.parent)
                if interp:
                    create_xml_changes(rel_labels, interp, notice_changes)

            amends.extend(designate_labels)
            amends.extend(other_labels)

            # if other_labels:    # Carry cfr_part through amendments
            #    default_cfr_part = other_labels[-1].label[0]

    if amends:
        notice['amendments'] = amends
        notice['changes'] = notice_changes.changes
    elif notice['document_number'] in settings.REISSUANCES:
        notice['changes'] = {
            default_cfr_part: [{
                'action': 'PUT',
                'node': reg_text.build_tree(notice_xml)
            }]
        }
Example #14
0
def process_amendments(notice, notice_xml):
    """ Process the changes to the regulation that are expressed in the notice.
    """
    amends = []
    notice_changes = changes.NoticeChanges()

    amdpars_by_parent = []
    for par in notice_xml.xpath('//AMDPAR'):
        parent = par.getparent()
        exists = filter(lambda aXp: aXp.parent == parent, amdpars_by_parent)
        if exists:
            exists[0].append(par)
        else:
            amdpars_by_parent.append(AmdparByParent(parent, par))

    default_cfr_part = notice['cfr_parts'][0]
    for aXp in amdpars_by_parent:
        amended_labels = []
        designate_labels, other_labels = [], []
        context = [aXp.parent.get('PART') or default_cfr_part]
        for par in aXp.amdpars:
            als, context = parse_amdpar(par, context)
            amended_labels.extend(als)

        labels_by_part = defaultdict(list)
        for al in amended_labels:
            if isinstance(al, DesignateAmendment):
                subpart_changes = process_designate_subpart(al)
                if subpart_changes:
                    notice_changes.update(subpart_changes)
                designate_labels.append(al)
            elif new_subpart_added(al):
                notice_changes.update(process_new_subpart(notice, al, par))
                designate_labels.append(al)
            else:
                other_labels.append(al)
                labels_by_part[al.label[0]].append(al)

        create_xmlless_changes(other_labels, notice_changes)

        for cfr_part, rel_labels in labels_by_part.iteritems():
            section_xml = find_section(par)
            if section_xml is not None:
                for section in reg_text.build_from_section(
                        cfr_part, section_xml):
                    create_xml_changes(rel_labels, section, notice_changes)

            for appendix in parse_appendix_changes(rel_labels, cfr_part,
                                                   aXp.parent):
                create_xml_changes(rel_labels, appendix, notice_changes)

            interp = parse_interp_changes(rel_labels, cfr_part, aXp.parent)
            if interp:
                create_xml_changes(rel_labels, interp, notice_changes)

        amends.extend(designate_labels)
        amends.extend(other_labels)

        if other_labels:  # Carry cfr_part through amendments
            default_cfr_part = other_labels[-1].label[0]

    if amends:
        notice['amendments'] = amends
        notice['changes'] = notice_changes.changes