You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""A dictionary mapping three letter month codes to 2 number month codes."""
297
+
"""A dictionary mapping uppercase month names to 2 number month codes."""
275
298
276
299
DEBUG_LEVEL=1
277
300
"""A global value that determines what debug information gets printed. This applies to the whole module, and you can modify it when you want to. Possible values:
"""This is the base class for every kind of curation. If you want a good tutorial on how to use this class, see :doc:`The Basics </basics>`. Extend this class to redefine it's methods."""
1417
+
"""This is the base class for every kind of curation. If you want a good tutorial on how to use this class, see :doc:`The Basics </basics>`. Extend this class to redefine it's methods. Constructor:
1418
+
1419
+
Accepts a single :class:`Curation` object as an argument or arguments in the same format as :func:`Curation.set_meta()`. The new curation will first have it's metadata, logo, screenshot, added args, and id deep-copied from :code:`curation`'s first if it's available, then have that data modified with :code:`kwargs` if available. This curation object will be linked to that curation object.
1420
+
1421
+
:raises TypeError: If :code:`curation` is not an instance of :class:`Curation`.
1422
+
"""
1395
1423
1396
1424
RESERVED_APPS= {'extras', 'message'}
1397
1425
"""A set containing all of the reserved headings that cannot be used in additional applications. The check is case-insensitive, hence they are lowercase."""
@@ -1476,10 +1504,6 @@ class Curation:
1476
1504
"""
1477
1505
1478
1506
def__init__(self, curation=None, **kwargs):
1479
-
"""Accepts a single :class:`Curation` object as an argument or arguments in the same format as :func:`Curation.set_meta()`. The new curation will first have it's metadata, logo, screenshot, added args, and id deep-copied from :code:`curation`'s first if it's available, then have that data modified with :code:`kwargs` if available. This curation object will be linked to that curation object.
1480
-
1481
-
:raises TypeError: If :code:`curation` is not an instance of :class:`Curation`.
"""Save the curation to a folder with the name of :attr:`Curation.id`. Consecutive calls to this method will not overwrite the previous folder, but will instead save it as "Curation (2)", "Curation (3)", etc.
1697
1721
1698
1722
:param str use_title: If True, the folder will be generated with the title of the curation instead of its id.
1699
1723
:param bool overwrite: If True, this method will mix and overwrite files in existing curation folders instead of making the folder "Curation (2)", "Curation (3)", etc.
1700
-
:param bool parse: *Added in 1.3*: If False, this function will not call :func:`Curation.parse()`.
1724
+
:param bool parse: *Added in 1.3*: If True, this function will call :func:`Curation.parse()` before saving metadata.
1701
1725
:param int validate: *Added in 1.3*: Mode to validate this curation's metadata with. 0 (default) means do not validate, 1 means flexibly validate, and 2 means rigidly validate.
1702
1726
:param int save_items: Flags determining what items to save as part of this curation. By default this is :data:`EVERYTHING`. If you wanted to save only the meta and logo, for example, use :code:`save_items=META|LOGO`.
"""Initialize a regex-powered date parser that gets initialized with a specific format and can parse any date into the proper iso format. It does not check that the date is a real date. The constructor takes a string :code:`format` specifying a regex to search for in future parsed strings. Note that the regex is case insensitive. Use these macros in the format string to specify parts of the date:
2023
+
2024
+
"<y>" for year number to match - replaced with the capture group "(?P<year>\d{4})",
2025
+
"<m>" for month to match - replaced with the capture group "(?P<month>\d{1,3}|[A-Za-z]+)", and
2026
+
"<d>" for day to match - replaced with the capture group "(?P<day>\d{1,3})"
2027
+
2028
+
Month and day are optional, though using day requires using month. Note that the year, month, and day are automatically padded to the right number of zeros (4, 2, 2) automatically.
2029
+
2030
+
If the macros don't quite work for you, feel free to use named capture groups and the callbacks "year", "month", and "day", which are called on the respective matched parts of a parsed string to turn it into the right number format to use in the returned string. If the "month" callback is not set, it defaults to :func:`DateParser.get_month`.
2031
+
2032
+
:param str format: A string containing a regex and macros specifying how to parse strings.
2033
+
:param func year: A function to turn the matched "year" part of a parsed date into the right number format.
2034
+
:param func month: A function to turn the matched "month" part of a parsed date into the right number format.
2035
+
:param func day: A function to turn the matched "day" part of a parsed date into the right number format.
2036
+
2037
+
:raises ValueError: if the given format does not contain a "year" named group/macro or contains a "day" named group/macro without the "month" named group/macro.
2038
+
2039
+
:since 1.6:
2040
+
"""
2041
+
2042
+
def__init__(self, format, year=None, month=None, day=None):
"""The default method called to turn the matched "month" part of a parsed date into the right number format. It tries to to find the first three characters of the string put into uppercase in :data:`fpclib.MONTHS`, then just returns :code:`s` if it fails."""
2058
+
iflen(s) <3: returns
2059
+
try:
2060
+
returnMONTHS[s[:3].upper()]
2061
+
exceptKeyError:
2062
+
returns
2063
+
2064
+
defparse(self, s):
2065
+
"""Uses this date format object to parse the given string :code:`s` into a proper iso date.
2066
+
2067
+
:param str s: A string to parse for a date.
2068
+
2069
+
:returns: An iso date parsed from string :code:`s`
2070
+
2071
+
:raises ValueError: if no date in :code:`s` could be found.
2072
+
"""
2073
+
match=self.format.search(s)
2074
+
ifnotmatch: raiseValueError(f'No date in "{s}"')
2075
+
2076
+
y=match["year"]
2077
+
ifnoty: raiseValueError(f'No year in "{s}"')
2078
+
try: m=match["month"]
2079
+
exceptIndexError: m=None
2080
+
try: d=match["day"]
2081
+
exceptIndexError: d=None
2082
+
2083
+
ifdandnotm: raiseValueError(f'Day but no month in "{s}"')
0 commit comments