def test_fetch_addreses_none(self):
     xml = """
     <ROOT>
         <ADD>
             <HD>ADDRESSES:</HD>
         </ADD>
     </ROOT>"""
     self.assertEqual(None, address.fetch_addresses(etree.fromstring(xml)))
     xml = """
     <ROOT>
         <CHILD />
     </ROOT>"""
     self.assertEqual(None, address.fetch_addresses(etree.fromstring(xml)))
 def test_fetch_addreses_none(self):
     xml = """
     <ROOT>
         <ADD>
             <HD>ADDRESSES:</HD>
         </ADD>
     </ROOT>"""
     self.assertEqual(None, address.fetch_addresses(etree.fromstring(xml)))
     xml = """
     <ROOT>
         <CHILD />
     </ROOT>"""
     self.assertEqual(None, address.fetch_addresses(etree.fromstring(xml)))
def process_xml(notice, notice_xml):
    """Pull out relevant fields from the xml and add them to the notice"""

    xml_chunk = notice_xml.xpath('//FURINF/P')
    if xml_chunk:
        notice['contact'] = xml_chunk[0].text

    addresses = fetch_addresses(notice_xml)
    if addresses:
        notice['addresses'] = addresses

    sxs = find_section_by_section(notice_xml)
    sxs = build_section_by_section(sxs, notice['cfr_part'],
                                   notice['meta']['start_page'])
    notice['section_by_section'] = sxs

    context = []
    amends = []
    for par in notice_xml.xpath('//AMDPAR'):
        amend_set, context = parse_amdpar(par, context)
        amends.extend(amend_set)
    if amends:
        notice['amendments'] = amends

    return notice
Example #4
0
def process_xml(notice, notice_xml):
    """Pull out relevant fields from the xml and add them to the notice"""
    notice = dict(notice)   # defensive copy

    xml_chunk = notice_xml.xpath('//FURINF/P')
    if xml_chunk:
        notice['contact'] = xml_chunk[0].text

    addresses = fetch_addresses(notice_xml)
    if addresses:
        notice['addresses'] = addresses

    if not notice.get('effective_on'):
        dates = fetch_dates(notice_xml)
        if dates and 'effective' in dates:
            notice['effective_on'] = dates['effective'][0]

    if not notice.get('cfr_parts'):
        cfr_parts = fetch_cfr_parts(notice_xml)
        notice['cfr_parts'] = cfr_parts

    process_sxs(notice, notice_xml)
    process_amendments(notice, notice_xml)
    add_footnotes(notice, notice_xml)

    return notice
Example #5
0
def process_xml(notice, notice_xml):
    """Pull out relevant fields from the xml and add them to the notice"""

    xml_chunk = notice_xml.xpath('//FURINF/P')
    if xml_chunk:
        notice['contact'] = xml_chunk[0].text

    addresses = fetch_addresses(notice_xml)
    if addresses:
        notice['addresses'] = addresses

    if not notice.get('effective_on'):
        dates = fetch_dates(notice_xml)
        if dates and 'effective' in dates:
            notice['effective_on'] = dates['effective'][0]

    if not notice.get('cfr_parts'):
        cfr_parts = fetch_cfr_parts(notice_xml)
        notice['cfr_parts'] = cfr_parts

    process_sxs(notice, notice_xml)
    process_amendments(notice, notice_xml)
    add_footnotes(notice, notice_xml)

    return notice
 def test_fetch_addresses(self):
     xml = """
     <ROOT>
         <ADD>
             <HD>ADDRESSES:</HD>
             <P>Here is some initial instruction.</P>
             <P><E T="03">Electronic: http://www.example.com.</E> MSG</P>
             <P>Mail: Some address here</P>
             <P>Blah Blah: Final method description</P>
             <P>And then, we have some instructions</P>
             <P>Followed by more instructions.</P>
         </ADD>
     </ROOT>"""
     self.assertEqual(address.fetch_addresses(etree.fromstring(xml)), {
         'intro': 'Here is some initial instruction.',
         'methods': [
             ('Electronic', 'http://www.example.com. MSG'),
             ('Mail', 'Some address here'),
             ('Blah Blah', 'Final method description')
         ],
         'instructions': [
             'And then, we have some instructions',
             'Followed by more instructions.'
         ]
     })
 def test_fetch_addresses(self):
     xml = """
     <ROOT>
         <ADD>
             <HD>ADDRESSES:</HD>
             <P>Here is some initial instruction.</P>
             <P><E T="03">Electronic: http://www.example.com.</E> MSG</P>
             <P>Mail: Some address here</P>
             <P>Blah Blah: Final method description</P>
             <P>And then, we have some instructions</P>
             <P>Followed by more instructions.</P>
         </ADD>
     </ROOT>"""
     self.assertEqual(
         address.fetch_addresses(etree.fromstring(xml)), {
             'intro':
             'Here is some initial instruction.',
             'methods': [('Electronic', 'http://www.example.com. MSG'),
                         ('Mail', 'Some address here'),
                         ('Blah Blah', 'Final method description')],
             'instructions': [
                 'And then, we have some instructions',
                 'Followed by more instructions.'
             ]
         })
 def test_fetch_addresses_no_intro(self):
     xml = """
     <ROOT>
         <ADD>
             <P>Mail: Some address here</P>
             <P>Followed by more instructions.</P>
         </ADD>
     </ROOT>"""
     self.assertEqual(address.fetch_addresses(etree.fromstring(xml)), {
         'methods': [('Mail', 'Some address here')],
         'instructions': ['Followed by more instructions.']
     })
 def test_fetch_address_instructions(self):
     xml = """
     <ROOT>
         <ADD>
             <P>Mail: Something something</P>
             <P>Instructions: Do these things</P>
             <P>Then do those things</P>
         </ADD>
     </ROOT>"""
     self.assertEqual(address.fetch_addresses(etree.fromstring(xml)), {
         'methods': [('Mail', 'Something something')],
         'instructions': ['Do these things', 'Then do those things']
     })
 def test_fetch_addresses_no_intro(self):
     xml = """
     <ROOT>
         <ADD>
             <P>Mail: Some address here</P>
             <P>Followed by more instructions.</P>
         </ADD>
     </ROOT>"""
     self.assertEqual(
         address.fetch_addresses(etree.fromstring(xml)), {
             'methods': [('Mail', 'Some address here')],
             'instructions': ['Followed by more instructions.']
         })
 def test_fetch_address_instructions(self):
     xml = """
     <ROOT>
         <ADD>
             <P>Mail: Something something</P>
             <P>Instructions: Do these things</P>
             <P>Then do those things</P>
         </ADD>
     </ROOT>"""
     self.assertEqual(
         address.fetch_addresses(etree.fromstring(xml)), {
             'methods': [('Mail', 'Something something')],
             'instructions': ['Do these things', 'Then do those things']
         })
 def test_fetch_address_http(self):
     xml = """
     <ROOT>
         <ADD>
             <P>Mail:Something here</P>
             <P>Otherwise, visit http://example.com</P>
             <P>or https://example.com</P>
         </ADD>
     </ROOT>"""
     self.assertEqual(address.fetch_addresses(etree.fromstring(xml)), {
         'methods': [('Mail', 'Something here')],
         'instructions': [
             'Otherwise, visit http://example.com',
             'or https://example.com'
         ]
     })
 def test_fetch_address_http(self):
     xml = """
     <ROOT>
         <ADD>
             <P>Mail:Something here</P>
             <P>Otherwise, visit http://example.com</P>
             <P>or https://example.com</P>
         </ADD>
     </ROOT>"""
     self.assertEqual(
         address.fetch_addresses(etree.fromstring(xml)), {
             'methods': [('Mail', 'Something here')],
             'instructions': [
                 'Otherwise, visit http://example.com',
                 'or https://example.com'
             ]
         })