Ejemplo n.º 1
0
 def test_fetch_dates_no_xml_el(self):
     xml = """
     <ROOT>
         <CHILD />
         <PREAMB />
     </ROOT>"""
     self.assertEqual(None, dates.fetch_dates(etree.fromstring(xml)))
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def test_fetch_dates_no_xml_el(self):
     xml = """
     <ROOT>
         <CHILD />
         <PREAMB />
     </ROOT>"""
     self.assertEqual(None, dates.fetch_dates(etree.fromstring(xml)))
Ejemplo n.º 5
0
 def _derive_date_type(self, date_type):
     """Attempt to parse comment closing date from DATES tags. Returns a
     datetime.date and sets the corresponding field"""
     dates = fetch_dates(self.xml) or {}
     if date_type in dates:
         comments = datetime.strptime(dates[date_type][0], "%Y-%m-%d").date()
         return comments
 def test_fetch_dates_no_date_text(self):
     with XMLBuilder("ROOT") as ctx:
         ctx.CHILD()
         with ctx.PREAMB():
             with ctx.EFFDATE():
                 ctx.HD("DATES: ")
                 ctx.P("There are no dates for this.")
     self.assertEqual(None, dates.fetch_dates(ctx.xml))
Ejemplo n.º 7
0
 def _derive_date_type(self, date_type):
     """Attempt to parse comment closing date from DATES tags. Returns a
     datetime.date and sets the corresponding field"""
     dates = fetch_dates(self.xml) or {}
     if date_type in dates:
         comments = datetime.strptime(dates[date_type][0],
                                      "%Y-%m-%d").date()
         return comments
Ejemplo n.º 8
0
 def derive_effective_date(self):
     """Attempt to parse effective date from DATES tags. Returns a
     datetime.date and sets the corresponding field"""
     dates = fetch_dates(self.xml) or {}
     if 'effective' in dates:
         effective = datetime.strptime(dates['effective'][0],
                                       "%Y-%m-%d").date()
         return effective
Ejemplo n.º 9
0
 def derive_effective_date(self):
     """Attempt to parse effective date from DATES tags. Returns a
     datetime.date and sets the corresponding field"""
     dates = fetch_dates(self.xml) or {}
     if 'effective' in dates:
         effective = datetime.strptime(
             dates['effective'][0], "%Y-%m-%d").date()
         return effective
 def test_fetch_dates_no_date_text(self):
     with self.tree.builder("ROOT") as root:
         root.CHILD()
         with root.PREAMB() as preamb:
             with preamb.EFFDATE() as effdate:
                 effdate.HD("DATES: ")
                 effdate.P("There are no dates for this.")
     self.assertEqual(None, dates.fetch_dates(self.tree.render_xml()))
Ejemplo n.º 11
0
 def derive_closing_date(self):
     """Attempt to parse comment closing date from DATES tags. Returns a
     datetime.date and sets the corresponding field"""
     dates = fetch_dates(self.xml) or {}
     if 'comments' in dates:
         comments = datetime.strptime(
             dates['comments'][0], "%Y-%m-%d").date()
         self.comments_close_on = comments
         return comments
Ejemplo n.º 12
0
 def derive_effective_date(self):
     """Attempt to parse effective date from DATES tags. Raises exception
     if it cannot. Also sets the field. Returns a datetime.date"""
     dates = fetch_dates(self.xml) or {}
     if "effective" not in dates:
         raise Exception("Could not derive effective date for notice {}".format(self.version_id))
     effective = datetime.strptime(dates["effective"][0], "%Y-%m-%d").date()
     self.effective = effective
     return effective
 def test_fetch_dates_emphasis(self):
     with self.tree.builder("ROOT") as root:
         with root.DATES() as dates_xml:
             dates_xml.HD("DATES:", SOURCE="HED")
             dates_xml.P(_xml=("<E T='03'>Effective date:</E>"
                               "The rule is effective June 1, 2077"))
             dates_xml.P(_xml=(
                 "<E T='03'>Applicability date:</E>"
                 "Its requirements apply to things after that date."))
     self.assertEqual(dates.fetch_dates(self.tree.render_xml()),
                      {'effective': ['2077-06-01']})
 def test_fetch_dates_emphasis(self):
     with XMLBuilder("ROOT") as ctx:
         with ctx.DATES():
             ctx.HD("DATES:", SOURCE="HED")
             ctx.child_from_string(
                 "<P><E T='03'>Effective date:</E>The rule is effective "
                 "June 1, 2077</P>")
             ctx.child_from_string(
                 "<P><E T='03'>Applicability date:</E>Its requirements "
                 "apply to things after that date.</P>")
     self.assertEqual(dates.fetch_dates(ctx.xml),
                      {'effective': ['2077-06-01']})
Ejemplo n.º 15
0
 def test_fetch_dates_no_date_text(self):
     xml = """
     <ROOT>
         <CHILD />
         <PREAMB>
             <EFFDATE>
                 <HD>DATES: </HD>
                 <P>There are no dates for this.</P>
             </EFFDATE>
         </PREAMB>
     </ROOT>"""
     self.assertEqual(None, dates.fetch_dates(etree.fromstring(xml)))
Ejemplo n.º 16
0
 def test_fetch_dates_no_date_text(self):
     xml = """
     <ROOT>
         <CHILD />
         <PREAMB>
             <EFFDATE>
                 <HD>DATES: </HD>
                 <P>There are no dates for this.</P>
             </EFFDATE>
         </PREAMB>
     </ROOT>"""
     self.assertEqual(None, dates.fetch_dates(etree.fromstring(xml)))
 def test_fetch_dates(self):
     with XMLBuilder("ROOT") as ctx:
         ctx.CHILD()
         with ctx.PREAMB():
             with ctx.EFFDATE():
                 ctx.HD("DATES: ")
                 ctx.P("We said stuff that's effective on May 9, 2005. "
                       "If you'd like to add comments, please do so by "
                       "June 3, 1987. Wait, that doesn't make sense. "
                       "I mean, the comment period ends on July 9, 2004. "
                       "Whew. It would have been more confusing if I said "
                       "August 15, 2005. Right?")
     self.assertEqual(dates.fetch_dates(ctx.xml), {
         'effective': ['2005-05-09'],
         'comments': ['1987-06-03', '2004-07-09'],
         'other': ['2005-08-15']
     })
Ejemplo n.º 18
0
 def test_fetch_dates_emphasis(self):
     xml = """
     <ROOT>
         <DATES>
             <HD SOURCE="HED">DATES:</HD>
             <P>
                 <E T="03">Effective date:</E>
                 The rule is effective June 1, 2077.
             </P>
             <P>
                 <E T="03">Applicability date:</E>
                 Its requirements apply to things after that date.
             </P>
         </DATES>
     </ROOT>"""
     self.assertEqual(dates.fetch_dates(etree.fromstring(xml)), {
         'effective': ['2077-06-01']})
Ejemplo n.º 19
0
 def test_fetch_dates_emphasis(self):
     xml = """
     <ROOT>
         <DATES>
             <HD SOURCE="HED">DATES:</HD>
             <P>
                 <E T="03">Effective date:</E>
                 The rule is effective June 1, 2077.
             </P>
             <P>
                 <E T="03">Applicability date:</E>
                 Its requirements apply to things after that date.
             </P>
         </DATES>
     </ROOT>"""
     self.assertEqual(dates.fetch_dates(etree.fromstring(xml)),
                      {'effective': ['2077-06-01']})
 def test_fetch_dates(self):
     with self.tree.builder("ROOT") as root:
         root.CHILD()
         with root.PREAMB() as preamb:
             with preamb.EFFDATE() as effdate:
                 effdate.HD("DATES: ")
                 effdate.P("We said stuff that's effective on May 9, "
                           "2005. If you'd like to add comments, please "
                           "do so by June 3, 1987.  Wait, that doesn't "
                           "make sense. I mean, the comment period ends "
                           "on July 9, 2004. Whew. It would have been "
                           "more confusing if I said August 15, 2005. "
                           "Right?")
     self.assertEqual(dates.fetch_dates(self.tree.render_xml()), {
         'effective': ['2005-05-09'],
         'comments': ['1987-06-03', '2004-07-09'],
         'other': ['2005-08-15']
     })
Ejemplo n.º 21
0
 def test_fetch_dates(self):
     xml = """
     <ROOT>
         <CHILD />
         <PREAMB>
             <EFFDATE>
                 <HD>DATES: </HD>
                 <P>We said stuff that's effective on May 9, 2005. If
                 you'd like to add comments, please do so by June 3, 1987.
                 Wait, that doesn't make sense. I mean, the comment
                 period ends on July 9, 2004. Whew. It would have been
                 more confusing if I said August 15, 2005. Right?</P>
             </EFFDATE>
         </PREAMB>
     </ROOT>"""
     self.assertEqual(dates.fetch_dates(etree.fromstring(xml)), {
         'effective': ['2005-05-09'],
         'comments': ['1987-06-03', '2004-07-09'],
         'other': ['2005-08-15']
     })
Ejemplo n.º 22
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

    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)
    amds = fetch_amendments(notice_xml)
    if amds:
        notice['amendments'] = amds
    add_footnotes(notice, notice_xml)

    return notice
Ejemplo n.º 23
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

    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)
    amds = fetch_amendments(notice_xml)
    if amds:
        notice['amendments'] = amds
    add_footnotes(notice, notice_xml)

    return notice
Ejemplo n.º 24
0
 def test_fetch_dates(self):
     xml = """
     <ROOT>
         <CHILD />
         <PREAMB>
             <EFFDATE>
                 <HD>DATES: </HD>
                 <P>We said stuff that's effective on May 9, 2005. If
                 you'd like to add comments, please do so by June 3, 1987.
                 Wait, that doesn't make sense. I mean, the comment
                 period ends on July 9, 2004. Whew. It would have been
                 more confusing if I said August 15, 2005. Right?</P>
             </EFFDATE>
         </PREAMB>
     </ROOT>"""
     self.assertEqual(
         dates.fetch_dates(etree.fromstring(xml)), {
             'effective': ['2005-05-09'],
             'comments': ['1987-06-03', '2004-07-09'],
             'other': ['2005-08-15']
         })
 def test_fetch_dates_no_xml_el(self):
     with XMLBuilder("ROOT") as ctx:
         ctx.CHILD()
         ctx.PREAMB()
     self.assertEqual(None, dates.fetch_dates(ctx.xml))
 def test_fetch_dates_no_xml_el(self):
     with self.tree.builder("ROOT") as root:
         root.CHILD()
         root.PREAMB()
     self.assertEqual(None, dates.fetch_dates(self.tree.render_xml()))