Skip to content

Commit

Permalink
fix: evaluate date.today() on class init, not import (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-richards authored May 10, 2022
1 parent 8e14069 commit 42568b3
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 70 deletions.
12 changes: 6 additions & 6 deletions tests/valid/indexes.pages.text
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


Network Working Group H. Person, Ed.
Internet-Draft May 6, 2022
Internet-Draft May 10, 2022
Intended status: Experimental
Expires: November 7, 2022
Expires: November 11, 2022


xml2rfc index tests
Expand All @@ -26,7 +26,7 @@ Status of This Memo
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."

This Internet-Draft will expire on November 7, 2022.
This Internet-Draft will expire on November 11, 2022.

Copyright Notice

Expand All @@ -53,7 +53,7 @@ Table of Contents



Person Expires November 7, 2022 [Page 1]
Person Expires November 11, 2022 [Page 1]

Internet-Draft xml2rfc index tests May 2022

Expand Down Expand Up @@ -109,7 +109,7 @@ Index



Person Expires November 7, 2022 [Page 2]
Person Expires November 11, 2022 [Page 2]

Internet-Draft xml2rfc index tests May 2022

Expand Down Expand Up @@ -165,4 +165,4 @@ Author's Address



Person Expires November 7, 2022 [Page 3]
Person Expires November 11, 2022 [Page 3]
6 changes: 3 additions & 3 deletions tests/valid/indexes.prepped.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" version="3" category="exp" docName="indexes-00" indexInclude="true" ipr="trust200902" prepTime="2022-05-06T00:20:27" scripts="Common,Latin" sortRefs="true" submissionType="independent" symRefs="true" tocDepth="3" tocInclude="true">
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" version="3" category="exp" docName="indexes-00" indexInclude="true" ipr="trust200902" prepTime="2022-05-10T16:21:25" scripts="Common,Latin" sortRefs="true" submissionType="independent" symRefs="true" tocDepth="3" tocInclude="true">
<!-- xml2rfc v2v3 conversion 3.12.5 -->


Expand All @@ -20,7 +20,7 @@
</postal>
</address>
</author>
<date day="06" month="05" year="2022"/>
<date day="10" month="05" year="2022"/>
<boilerplate>
<section anchor="status-of-memo" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.1">
<name slugifiedName="name-status-of-this-memo">Status of This Memo</name>
Expand All @@ -41,7 +41,7 @@
material or to cite them other than as "work in progress."
</t>
<t indent="0" pn="section-boilerplate.1-4">
This Internet-Draft will expire on 7 November 2022.
This Internet-Draft will expire on 11 November 2022.
</t>
</section>
<section anchor="copyright" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.2">
Expand Down
6 changes: 3 additions & 3 deletions tests/valid/indexes.text
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


Network Working Group H. Person, Ed.
Internet-Draft May 6, 2022
Internet-Draft May 10, 2022
Intended status: Experimental
Expires: November 7, 2022
Expires: November 11, 2022


xml2rfc index tests
Expand All @@ -26,7 +26,7 @@ Status of This Memo
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."

This Internet-Draft will expire on November 7, 2022.
This Internet-Draft will expire on November 11, 2022.

Copyright Notice

Expand Down
8 changes: 4 additions & 4 deletions tests/valid/indexes.v3.py37.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</tr></thead>
<tfoot><tr>
<td class="left">Person</td>
<td class="center">Expires November 7, 2022</td>
<td class="center">Expires November 11, 2022</td>
<td class="right">[Page]</td>
</tr></tfoot>
</table>
Expand All @@ -36,12 +36,12 @@
<dd class="internet-draft">indexes-00</dd>
<dt class="label-published">Published:</dt>
<dd class="published">
<time datetime="2022-05-06" class="published">May 6, 2022</time>
<time datetime="2022-05-10" class="published">May 10, 2022</time>
</dd>
<dt class="label-intended-status">Intended Status:</dt>
<dd class="intended-status">Experimental</dd>
<dt class="label-expires">Expires:</dt>
<dd class="expires"><time datetime="2022-11-07">November 7, 2022</time></dd>
<dd class="expires"><time datetime="2022-11-11">November 11, 2022</time></dd>
<dt class="label-authors">Author:</dt>
<dd class="authors">
<div class="author">
Expand Down Expand Up @@ -71,7 +71,7 @@ <h2 id="name-status-of-this-memo">
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."<a href="#section-boilerplate.1-3" class="pilcrow"></a></p>
<p id="section-boilerplate.1-4">
This Internet-Draft will expire on November 7, 2022.<a href="#section-boilerplate.1-4" class="pilcrow"></a></p>
This Internet-Draft will expire on November 11, 2022.<a href="#section-boilerplate.1-4" class="pilcrow"></a></p>
</section>
</div>
<div id="copyright">
Expand Down
2 changes: 1 addition & 1 deletion tests/valid/manpage.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
xml2rfc(1) xml2rfc(1)
6 May 2022
10 May 2022


Xml2rfc Vocabulary Version 3 Schema
Expand Down
6 changes: 3 additions & 3 deletions tests/valid/rfc6787.exp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11141,7 +11141,7 @@ identification-tag = token
<references title="Normative References">
<!--RTP-->

<reference anchor="RFC3550" target="https://www.rfc-editor.org/info/rfc3550" xml:base="https://www.rfc-editor.org/refs/bibxml/reference.RFC.3550.xml" quote-title="true">
<reference anchor="RFC3550" target="https://www.rfc-editor.org/info/rfc3550" xml:base="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.3550.xml" quote-title="true">
<front>
<title>RTP: A Transport Protocol for Real-Time Applications</title>
<author initials="H." surname="Schulzrinne" fullname="H. Schulzrinne"><organization/></author>
Expand Down Expand Up @@ -11338,7 +11338,7 @@ identification-tag = token

<!--Internet Message Format-->

<reference anchor="RFC5322" target="https://www.rfc-editor.org/info/rfc5322" xml:base="https://www.rfc-editor.org/refs/bibxml/reference.RFC.5322.xml" quote-title="true">
<reference anchor="RFC5322" target="https://www.rfc-editor.org/info/rfc5322" xml:base="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.5322.xml" quote-title="true">
<front>
<title>Internet Message Format</title>
<author initials="P." surname="Resnick" fullname="P. Resnick" role="editor"><organization/></author>
Expand Down Expand Up @@ -11420,7 +11420,7 @@ identification-tag = token

<!--Domain names - implementation and specification-->

<reference anchor="RFC1035" target="https://www.rfc-editor.org/info/rfc1035" xml:base="https://www.rfc-editor.org/refs/bibxml/reference.RFC.1035.xml" quote-title="true">
<reference anchor="RFC1035" target="https://www.rfc-editor.org/info/rfc1035" xml:base="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.1035.xml" quote-title="true">
<front>
<title>Domain names - implementation and specification</title>
<author initials="P.V." surname="Mockapetris" fullname="P.V. Mockapetris"><organization/></author>
Expand Down
14 changes: 7 additions & 7 deletions tests/valid/sourcecode.pages.text
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


Network Working Group H. Person, Ed.
Internet-Draft May 6, 2022
Internet-Draft May 10, 2022
Intended status: Experimental
Expires: November 7, 2022
Expires: November 11, 2022


xml2rfc sourcecode tests
Expand All @@ -26,7 +26,7 @@ Status of This Memo
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."

This Internet-Draft will expire on November 7, 2022.
This Internet-Draft will expire on November 11, 2022.

Copyright Notice

Expand All @@ -53,7 +53,7 @@ Table of Contents



Person Expires November 7, 2022 [Page 1]
Person Expires November 11, 2022 [Page 1]

Internet-Draft xml2rfc sourcecode tests May 2022

Expand Down Expand Up @@ -109,7 +109,7 @@ Internet-Draft xml2rfc sourcecode tests May 2022



Person Expires November 7, 2022 [Page 2]
Person Expires November 11, 2022 [Page 2]

Internet-Draft xml2rfc sourcecode tests May 2022

Expand Down Expand Up @@ -165,7 +165,7 @@ Internet-Draft xml2rfc sourcecode tests May 2022



Person Expires November 7, 2022 [Page 3]
Person Expires November 11, 2022 [Page 3]

Internet-Draft xml2rfc sourcecode tests May 2022

Expand Down Expand Up @@ -221,4 +221,4 @@ Author's Address



Person Expires November 7, 2022 [Page 4]
Person Expires November 11, 2022 [Page 4]
6 changes: 3 additions & 3 deletions tests/valid/sourcecode.prepped.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" version="3" category="exp" docName="sourcecode-00" indexInclude="true" ipr="trust200902" prepTime="2022-05-06T00:21:36" scripts="Common,Latin" sortRefs="true" submissionType="independent" symRefs="true" tocDepth="3" tocInclude="true">
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" version="3" category="exp" docName="sourcecode-00" indexInclude="true" ipr="trust200902" prepTime="2022-05-10T16:24:15" scripts="Common,Latin" sortRefs="true" submissionType="independent" symRefs="true" tocDepth="3" tocInclude="true">
<!-- xml2rfc v2v3 conversion 3.12.5 -->


Expand All @@ -20,7 +20,7 @@
</postal>
</address>
</author>
<date day="06" month="05" year="2022"/>
<date day="10" month="05" year="2022"/>
<boilerplate>
<section anchor="status-of-memo" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.1">
<name slugifiedName="name-status-of-this-memo">Status of This Memo</name>
Expand All @@ -41,7 +41,7 @@
material or to cite them other than as "work in progress."
</t>
<t indent="0" pn="section-boilerplate.1-4">
This Internet-Draft will expire on 7 November 2022.
This Internet-Draft will expire on 11 November 2022.
</t>
</section>
<section anchor="copyright" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.2">
Expand Down
6 changes: 3 additions & 3 deletions tests/valid/sourcecode.text
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


Network Working Group H. Person, Ed.
Internet-Draft May 6, 2022
Internet-Draft May 10, 2022
Intended status: Experimental
Expires: November 7, 2022
Expires: November 11, 2022


xml2rfc sourcecode tests
Expand All @@ -26,7 +26,7 @@ Status of This Memo
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."

This Internet-Draft will expire on November 7, 2022.
This Internet-Draft will expire on November 11, 2022.

Copyright Notice

Expand Down
8 changes: 4 additions & 4 deletions tests/valid/sourcecode.v3.py37.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</tr></thead>
<tfoot><tr>
<td class="left">Person</td>
<td class="center">Expires November 7, 2022</td>
<td class="center">Expires November 11, 2022</td>
<td class="right">[Page]</td>
</tr></tfoot>
</table>
Expand All @@ -36,12 +36,12 @@
<dd class="internet-draft">sourcecode-00</dd>
<dt class="label-published">Published:</dt>
<dd class="published">
<time datetime="2022-05-06" class="published">May 6, 2022</time>
<time datetime="2022-05-10" class="published">May 10, 2022</time>
</dd>
<dt class="label-intended-status">Intended Status:</dt>
<dd class="intended-status">Experimental</dd>
<dt class="label-expires">Expires:</dt>
<dd class="expires"><time datetime="2022-11-07">November 7, 2022</time></dd>
<dd class="expires"><time datetime="2022-11-11">November 11, 2022</time></dd>
<dt class="label-authors">Author:</dt>
<dd class="authors">
<div class="author">
Expand Down Expand Up @@ -71,7 +71,7 @@ <h2 id="name-status-of-this-memo">
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."<a href="#section-boilerplate.1-3" class="pilcrow"></a></p>
<p id="section-boilerplate.1-4">
This Internet-Draft will expire on November 7, 2022.<a href="#section-boilerplate.1-4" class="pilcrow"></a></p>
This Internet-Draft will expire on November 11, 2022.<a href="#section-boilerplate.1-4" class="pilcrow"></a></p>
</section>
</div>
<div id="copyright">
Expand Down
14 changes: 6 additions & 8 deletions xml2rfc/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def main():
value_options.add_argument( '--config-file', dest="config_file", metavar='FILE', is_config_file_arg=True,
help='specify a configuration file')
value_options.add_argument('-d', '--dtd', dest='dtd', metavar='DTDFILE', help='specify an alternate dtd file')
value_options.add_argument('-D', '--date', dest='datestring', metavar='DATE', default=datetime.date.today(),
value_options.add_argument('-D', '--date', dest='datestring', metavar='DATE', default=None,
help="run as if the date is DATE (format: yyyy-mm-dd). Default: Today's date")
value_options.add_argument('-f', '--filename', dest='filename', metavar='FILE',
help='Deprecated. The same as -o')
Expand Down Expand Up @@ -498,14 +498,12 @@ def main():
print('Cache directory is not writable: %s' % options.cache)
sys.exit(1)
#
if options.datestring:
if isinstance(options.datestring, str):
options.date = datetime.datetime.strptime(options.datestring, "%Y-%m-%d").date()
elif isinstance(options.datestring, datetime.date):
options.date = options.datestring
else:
xml2rfc.log.warn("Unexpected type for options.datestring: %s" % type(options.datestring))
if options.datestring is not None:
options.date = datetime.datetime.strptime(options.datestring, "%Y-%m-%d").date()
else:
# Use today by default. Even though date = None is later translated to today(), set it
# explicitly to ensure there's no date skew between instance inits if we happen to be run
# exactly at midnight.
options.date = datetime.date.today()

if options.omit_headers and not options.text:
Expand Down
10 changes: 5 additions & 5 deletions xml2rfc/writers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'css': None,
'config_file': None,
'country_help': False,
'date': datetime.date.today(),
'date': None,
'datestring': None,
'debug': False,
'docfile': False,
Expand Down Expand Up @@ -442,11 +442,11 @@ class BaseRfcWriter:

# -------------------------------------------------------------------------

def __init__(self, xmlrfc, quiet=None, options=default_options, date=datetime.date.today()):
def __init__(self, xmlrfc, quiet=None, options=default_options, date=None):
if not quiet is None:
options.quiet = quiet
self.options = options
self.date = date
self.date = date if date is not None else datetime.date.today()
self.expire_string = ''
self.ascii = False
self.nbws_cond = u'\u00A0'
Expand Down Expand Up @@ -1717,13 +1717,13 @@ def get_xref_tags():

class BaseV3Writer(object):

def __init__(self, xmlrfc, quiet=None, options=default_options, date=datetime.date.today()):
def __init__(self, xmlrfc, quiet=None, options=default_options, date=None):
global v3_rnc_file, v3_rng_file, v3_schema
self.xmlrfc = xmlrfc
self.tree = xmlrfc.tree if xmlrfc else None
self.root = self.tree.getroot() if xmlrfc else None
self.options = options
self.date = date
self.date = date if date is not None else datetime.date.today()
self.v3_rnc_file = v3_rnc_file
self.v3_rng_file = v3_rng_file
self.v3_rng = lxml.etree.RelaxNG(file=self.v3_rng_file)
Expand Down
3 changes: 1 addition & 2 deletions xml2rfc/writers/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import unicode_literals, print_function, division

import collections
import datetime
import io
import jinja2
import lxml
Expand All @@ -25,7 +24,7 @@ def capfirst(value):
return value and value[0].upper() + value[1:]

class DocWriter(base.BaseV3Writer):
def __init__(self, xmlrfc, quiet=None, options=base.default_options, date=datetime.date.today()):
def __init__(self, xmlrfc, quiet=None, options=base.default_options, date=None):
super(DocWriter, self).__init__(xmlrfc, quiet=quiet, options=options, date=date)
rfc7991_rng_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data', 'rfc7991.rng')
self.rfc7991_schema = lxml.etree.ElementTree(file=rfc7991_rng_file)
Expand Down
3 changes: 1 addition & 2 deletions xml2rfc/writers/expanded_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import lxml.etree
import xml2rfc
import datetime
from io import open
from xml2rfc.writers.base import default_options

Expand All @@ -14,7 +13,7 @@ class ExpandedXmlWriter:
# Note -- we don't need to subclass BaseRfcWriter because the behavior
# is so different and so trivial

def __init__(self, xmlrfc, quiet=None, options=default_options, date=datetime.date.today()):
def __init__(self, xmlrfc, quiet=None, options=default_options, date=None):
if not quiet is None:
options.quiet = quiet
self.root = xmlrfc.getroot()
Expand Down
Loading

0 comments on commit 42568b3

Please sign in to comment.