milestonexprotectrestpython.xprutils
Module: xputils.py
Revision History
Date | Version | Description |
---|---|---|
2023/07/07 | 1.0.0.0 | Initial Version. |
Define the decorator used to call an initializer for a class with all static methods. This allows static variables to be initialized one time for the class.
Define the decorator used to modify a module's "__all__" variable. This avoids us having to manually modify a module's "__all__" variable when adding new classes.
C# like event processing in Python3.
View Sample Code
# Define the class that will be raising events:
class MyFileWatcher:
def __init__(self):
self.fileChanged = Event() # define event
def watchFiles(self):
source_path = "foo"
self.fileChanged(source_path) # fire event
def log_file_change(source_path): # event handler 1
print "%r changed." % (source_path,)
def log_file_change2(source_path): # event handler 2
print "%r changed!" % (source_path,)
# Define the code that will be handling raised events.
watcher = MyFileWatcher()
watcher.fileChanged += log_file_change2
watcher.fileChanged += log_file_change
watcher.fileChanged -= log_file_change2
watcher.watchFiles()
Helper class used for processing different types of data.
Converts a boolean value to a "Yes" (true) or "No" (false) string.
Arguments:
- value (bool): Boolean value to convert.
Returns:
A "Yes" or "No" string value.
Converts a string to a boolean value.
Arguments:
- value (str): String value to convert.
Returns:
A bool value.
True is returned if the value argument contains "yes", "true", "t", or "1";
otherwise, False is returned.
Converts a string to a datetime value.
Arguments:
- value (str): String value to convert.
- argumentName (str): Argument Name the datetime string was loaded from - used in exception details if the string could not be converted successfully.
- raiseExceptionIfNull (bool): If True, and Exception will be raised if the string could not be converted to a date or if the value is null; otherwise, False to not raise an exception.
Returns:
A datetime value.
True is returned if the value argument contains "yes", "true", "t", or "1";
otherwise, False is returned.
Supported examples for datetime string are:
- "0001-01-01T00:00:00.0000000"
- "2023-07-24T17:12:31.0210000Z"
- "2023-07-24T17:12:31.0210Z"
- "2023-07-24T17:12:31Z"