示例#1
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
示例#2
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'):
            instructions = amdpar.xpath('./EREGS_INSTRUCTIONS')
            if not instructions:
                logger.warning('No <EREGS_INSTRUCTIONS>. Was this notice '
                               'preprocessed?')
                continue
            instructions = instructions[0]
            amendments = [amendment_from_xml(el) for el in instructions]
            context = [None if l is '?' else l
                       for l in instructions.get('final_context').split('-')]
            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
示例#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))

    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)
            }]
        }
示例#4
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)
            }]
        }
示例#5
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