[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-python] 08/12: Replace spaghetti code by loops.
From: |
gnunet |
Subject: |
[gnunet-python] 08/12: Replace spaghetti code by loops. |
Date: |
Sun, 12 Apr 2020 23:22:26 +0200 |
This is an automated email from the git hooks/post-receive script.
htgoebel pushed a commit to branch master
in repository gnunet-python.
commit 5759c1f7ceff3d1ff6da06cf86d129623ce0512e
Author: Hartmut Goebel <address@hidden>
AuthorDate: Sat Jan 19 21:38:50 2019 +0100
Replace spaghetti code by loops.
---
gnunet/strings.py | 56 +++++++++++++++----------------------------------------
1 file changed, 15 insertions(+), 41 deletions(-)
diff --git a/gnunet/strings.py b/gnunet/strings.py
index c84e32c..1484495 100644
--- a/gnunet/strings.py
+++ b/gnunet/strings.py
@@ -53,48 +53,22 @@ def string_to_data(s):
def absolute_time_to_string(t):
return t.strftime("%a %b %d %H:%M:%S %Y")
-
def string_to_absolute_time(s):
if s == "end of time":
return None
- try:
- return datetime.datetime.strptime(s, "%a %b %d %H:%M:%S %Y")
- except ValueError:
- pass
- try:
- return datetime.datetime.strptime(s, "%c")
- except ValueError:
- pass
- try:
- return datetime.datetime.strptime(s, "%Ec")
- except ValueError:
- pass
- try:
- return datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S")
- except ValueError:
- pass
- try:
- return datetime.datetime.strptime(s, "%Y-%m-%d %H:%M")
- except ValueError:
- pass
- try:
- return datetime.datetime.strptime(s, "%x")
- except ValueError:
- pass
- try:
- return datetime.datetime.strptime(s, "%Ex")
- except ValueError:
- pass
- try:
- return datetime.datetime.strptime(s, "%Y-%m-%d")
- except ValueError:
- pass
- try:
- return datetime.datetime.strptime(s, "%Y-%m")
- except ValueError:
- pass
- try:
- return datetime.datetime.strptime(s, "%Y")
- except ValueError:
- pass
+ for fmt in (
+ "%a %b %d %H:%M:%S %Y",
+ "%c",
+ "%Ec",
+ "%Y-%m-%d %H:%M:%S",
+ "%Y-%m-%d %H:%M",
+ "%x",
+ "%Ex",
+ "%Y-%m-%d",
+ "%Y-%m",
+ "%Y"):
+ try:
+ return datetime.datetime.strptime(s, fmt)
+ except ValueError:
+ pass
raise ValueError("%s is not a properly formatted time string" % s)
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [gnunet-python] branch master updated (bda184f -> a3707a2), gnunet, 2020/04/12
- [gnunet-python] 01/12: Add a small test-suite., gnunet, 2020/04/12
- [gnunet-python] 04/12: Avoid "During handling of the above exception" when re-raising., gnunet, 2020/04/12
- [gnunet-python] 02/12: Extend .gitignore., gnunet, 2020/04/12
- [gnunet-python] 03/12: Simplify initiation of `_Key` and subclasses., gnunet, 2020/04/12
- [gnunet-python] 07/12: Add test-cases for strings.string_to_absolute_time., gnunet, 2020/04/12
- [gnunet-python] 06/12: Use relative imports., gnunet, 2020/04/12
- [gnunet-python] 05/12: Add '_Key.__repr__()' to eliminate redundant code in subclasses., gnunet, 2020/04/12
- [gnunet-python] 08/12: Replace spaghetti code by loops.,
gnunet <=
- [gnunet-python] 09/12: Add test-cases for strings.data_to_string and string_to_data., gnunet, 2020/04/12
- [gnunet-python] 10/12: Mark strings.encTable as private., gnunet, 2020/04/12
- [gnunet-python] 11/12: Use upper-case names for global constant values., gnunet, 2020/04/12
- [gnunet-python] 12/12: Break some very long lines and some other minor code-cleanup., gnunet, 2020/04/12