76 # in Python versions earlier than 3.3. |
76 # in Python versions earlier than 3.3. |
77 from pipes import quote as shlex_quote |
77 from pipes import quote as shlex_quote |
78 |
78 |
79 try: |
79 try: |
80 import reprlib |
80 import reprlib |
81 except ImportError: |
81 except ImportError: # pragma: not covered |
|
82 # We need this on Python 2, but in testing environments, a backport is |
|
83 # installed, so this import isn't used. |
82 import repr as reprlib |
84 import repr as reprlib |
83 |
85 |
84 # A function to iterate listlessly over a dict's items, and one to get the |
86 # A function to iterate listlessly over a dict's items, and one to get the |
85 # items as a list. |
87 # items as a list. |
86 try: |
88 try: |
212 |
214 |
213 def __repr__(self): |
215 def __repr__(self): |
214 keys = sorted(self.__dict__) |
216 keys = sorted(self.__dict__) |
215 items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys) |
217 items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys) |
216 return "{}({})".format(type(self).__name__, ", ".join(items)) |
218 return "{}({})".format(type(self).__name__, ", ".join(items)) |
217 |
|
218 def __eq__(self, other): |
|
219 return self.__dict__ == other.__dict__ |
|
220 |
219 |
221 |
220 |
222 def format_local_datetime(dt): |
221 def format_local_datetime(dt): |
223 """Return a string with local timezone representing the date. |
222 """Return a string with local timezone representing the date. |
224 If python version is lower than 3.6, the time zone is not included. |
223 If python version is lower than 3.6, the time zone is not included. |
243 as `modname`, and returns the module object. `modfile` is the file to |
242 as `modname`, and returns the module object. `modfile` is the file to |
244 import if it isn't in the current directory. |
243 import if it isn't in the current directory. |
245 |
244 |
246 """ |
245 """ |
247 try: |
246 try: |
248 from importlib.machinery import SourceFileLoader |
247 import importlib.util as importlib_util |
249 except ImportError: |
248 except ImportError: |
250 SourceFileLoader = None |
249 importlib_util = None |
251 |
250 |
252 if modfile is None: |
251 if modfile is None: |
253 modfile = modname + '.py' |
252 modfile = modname + '.py' |
254 if SourceFileLoader: |
253 if importlib_util: |
255 # pylint: disable=no-value-for-parameter, deprecated-method |
254 spec = importlib_util.spec_from_file_location(modname, modfile) |
256 mod = SourceFileLoader(modname, modfile).load_module() |
255 mod = importlib_util.module_from_spec(spec) |
|
256 sys.modules[modname] = mod |
|
257 spec.loader.exec_module(mod) |
257 else: |
258 else: |
258 for suff in imp.get_suffixes(): # pragma: part covered |
259 for suff in imp.get_suffixes(): # pragma: part covered |
259 if suff[0] == '.py': |
260 if suff[0] == '.py': |
260 break |
261 break |
261 |
262 |