Skip to content

Commit c8a90d6

Browse files
committed
Removed unnecessary whitespace
1 parent 362fbab commit c8a90d6

File tree

17 files changed

+301
-312
lines changed

17 files changed

+301
-312
lines changed

domdf_python_tools/bases.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#
2626

2727

28-
2928
# stdlib
3029
from abc import ABC, abstractmethod
3130
from collections import UserList
@@ -39,38 +38,38 @@ class Dictable(ABC):
3938
"""
4039
The basic structure of a class than can be converted into a dictionary
4140
"""
42-
41+
4342
@abstractmethod
4443
def __init__(self, *args, **kwargs):
4544
pass
46-
45+
4746
def __str__(self):
4847
return self.__repr__()
49-
48+
5049
def __iter__(self):
5150
for key, value in self.__dict__().items():
5251
yield key, value
53-
52+
5453
def __getstate__(self):
5554
return self.__dict__()
56-
55+
5756
def __setstate__(self, state):
5857
self.__init__(**state)
59-
58+
6059
def __copy__(self):
6160
return self.__class__(**self.__dict__())
62-
61+
6362
def __deepcopy__(self, memodict={}):
6463
return self.__copy__()
65-
64+
6665
@abstractmethod
6766
def __dict__(self):
6867
return dict()
69-
68+
7069
def __eq__(self, other):
7170
if isinstance(other, self.__class__):
7271
return pydash.predicates.is_match(other.__dict__(), self.__dict__())
73-
72+
7473
return NotImplemented
7574

7675

@@ -83,18 +82,18 @@ def namedlist(name="NamedList"):
8382
:return:
8483
:rtype:
8584
"""
86-
85+
8786
class NamedList(UserList):
8887
"""
8988
A list with a name
9089
"""
91-
90+
9291
def __repr__(self):
9392
return f"{super().__repr__()}"
94-
93+
9594
def __str__(self):
9695
return f"{self.__class__.__name__}{pformat(list(self))}"
97-
96+
9897
NamedList.__name__ = name
99-
98+
10099
return NamedList

domdf_python_tools/dates.py

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,28 @@
3838
# 3rd party
3939
try:
4040
import pytz
41-
42-
41+
4342
def get_utc_offset(tz, date=None):
4443
"""
4544
Returns the offset between UTC and the requested timezone on the given date.
4645
If ``date`` is ``None`` then the current date is used.
47-
46+
4847
:param tz: :class:`pytz.timezone` or a string representing the timezone
4948
:type tz:
5049
:param date:
5150
:type date: :class:`python:datetime.datetime` or None, optional
5251
:return:
5352
:rtype: :class:`python:datetime.timedelta`
5453
"""
55-
54+
5655
if date is None:
5756
date = datetime.datetime.utcnow()
58-
57+
5958
if isinstance(tz, str):
6059
tz = get_timezone(tz, date)
61-
60+
6261
return date.replace(tzinfo=pytz.utc).astimezone(tz).utcoffset()
63-
64-
62+
6563
def get_timezone(tz, date=None):
6664
"""
6765
Returns a localized :class:`pytz.timezone` object for the given date.
@@ -74,24 +72,23 @@ def get_timezone(tz, date=None):
7472
:return:
7573
:rtype: :class:`python:datetime.timedelta`
7674
"""
77-
75+
7876
if date is None:
7977
date = datetime.datetime.utcnow()
80-
78+
8179
d = date.replace(tzinfo=None)
8280

8381
return pytz.timezone(tz).localize(d).tzinfo
84-
85-
82+
8683
def current_tzinfo():
8784
"""
8885
Returns a tzinfo object for the current timezone
89-
86+
9087
:rtype: :class:`python:datetime.tzinfo`
9188
"""
92-
89+
9390
return datetime.datetime.now().astimezone().tzinfo
94-
91+
9592
#
9693
# def datetime_to_utc_timestamp(datetime, current_tzinfo=None):
9794
# """
@@ -109,55 +106,53 @@ def current_tzinfo():
109106
#
110107
# return datetime.astimezone(current_tzinfo).timestamp()
111108
#
112-
109+
113110
def set_timezone(obj, tzinfo):
114111
"""
115112
Sets the timezone / tzinfo of the given :class:`datetime.datetime` object.
116113
This will not convert the time (i.e. the hours will stay the same).
117114
Use :meth:`python:datetime.datetime.astimezone` to accomplish that.
118-
115+
119116
:param obj:
120117
:type obj:
121-
:param tzinfo:
122-
:type tzinfo:
123-
118+
:param tzinfo:
119+
:type tzinfo:
120+
124121
:return:
125-
:rtype:
122+
:rtype:
126123
"""
127-
124+
128125
return obj.replace(tzinfo=tzinfo)
129-
130-
126+
131127
def utc_timestamp_to_datetime(utc_timestamp, output_tz=None):
132128
"""
133129
Convert UTC timestamp (seconds from UNIX epoch) to a :class:`datetime.datetime` object
134-
130+
135131
If ``output_tz`` is None the timestamp is converted to the platform’s local date and time,
136132
and the local timezone is inferred and set for the object.
137-
133+
138134
If ``output_tz`` is not None, it must be an instance of a :class:`~python:datetime.tzinfo` subclass,
139135
and the timestamp is converted to ``output_tz``’s time zone.
140-
141-
136+
137+
142138
:param utc_timestamp: The timestamp to convert to a datetime object
143139
:type utc_timestamp: float, int
144140
:param output_tz: The timezone to output the datetime object for.
145141
If None it will be inferred.
146142
:type output_tz: :class:`~python:datetime.tzinfo`
147-
143+
148144
:return: The timestamp as a datetime object.
149145
:rtype: :class:`datetime.datetime`
150-
146+
151147
:raises: :class:`~python:OverflowError` if the timestamp is out of the range
152148
of values supported by the platform C localtime() or gmtime() functions,
153149
and OSError on localtime() or gmtime() failure. It’s common for this to
154150
be restricted to years in 1970 through 2038.
155151
"""
156-
152+
157153
new_datetime = datetime.datetime.fromtimestamp(utc_timestamp, output_tz)
158154
return new_datetime.astimezone(output_tz)
159-
160-
155+
161156
# List of months and their 3-character shortcodes.
162157
months = OrderedDict(
163158
Jan="January",
@@ -173,8 +168,7 @@ def utc_timestamp_to_datetime(utc_timestamp, output_tz=None):
173168
Nov="November",
174169
Dec="December",
175170
)
176-
177-
171+
178172
def parse_month(month):
179173
"""
180174
Converts an integer or shorthand month into the full month name
@@ -185,22 +179,21 @@ def parse_month(month):
185179
:return: The full name of the month
186180
:rtype: str
187181
"""
188-
182+
189183
try:
190184
month = int(month)
191185
except ValueError:
192186
try:
193187
return months[month.capitalize()[:3]]
194188
except KeyError:
195189
raise ValueError("Unrecognised month value")
196-
190+
197191
# Only get here if first try succeeded
198192
if 0 < month <= 12:
199193
return list(months.values())[month - 1]
200194
else:
201195
raise ValueError("Unrecognised month value")
202-
203-
196+
204197
def get_month_number(month):
205198
"""
206199
Returns the number of the given month. If ``month`` is already a
@@ -212,7 +205,7 @@ def get_month_number(month):
212205
:return: The number of the month
213206
:rtype:
214207
"""
215-
208+
216209
if isinstance(month, int):
217210
if 0 < month <= 12:
218211
return month
@@ -221,8 +214,7 @@ def get_month_number(month):
221214
else:
222215
month = parse_month(month)
223216
return list(months.values()).index(month) + 1
224-
225-
217+
226218
def check_date(month, day, leap_year=True):
227219
"""
228220
Returns ``True`` if the day number is valid for the given month.
@@ -239,12 +231,12 @@ def check_date(month, day, leap_year=True):
239231
:return: ``True`` if the date is valid
240232
:rtype: bool
241233
"""
242-
234+
243235
# Ensure day is an integer
244236
day = int(day)
245237
month = get_month_number(month)
246238
year = 2020 if leap_year else 2019
247-
239+
248240
try:
249241
datetime.date(year, month, day)
250242
return True

domdf_python_tools/doctools.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def deindent_string(string):
4040
:return: The string without indentation
4141
:rtype: str
4242
"""
43-
43+
4444
split_string = string.split("\n")
4545
deindented_string = [line.lstrip("\t ") for line in split_string]
4646
return "\n".join(deindented_string)
@@ -58,7 +58,7 @@ def document_object_from_another(target, original):
5858
:param original: The object to copy the docstring from
5959
:type original: any
6060
"""
61-
61+
6262
target.__doc__ = original.__doc__
6363

6464

@@ -77,10 +77,10 @@ def append_doctring_from_another(target, original):
7777
:param original: The object to copy the docstring from
7878
:type original: any
7979
"""
80-
80+
8181
deindented_target_doc = deindent_string(target.__doc__)
8282
deindented_original_doc = deindent_string(original.__doc__)
83-
83+
8484
target.__doc__ = deindented_target_doc + "\n" + deindented_original_doc
8585

8686

@@ -102,15 +102,15 @@ def make_sphinx_links(input_string, builtins_list=None):
102102
:return: processed string with links
103103
:rtype: str
104104
"""
105-
105+
106106
if builtins_list is None:
107107
builtins_list = dir(builtins)
108-
108+
109109
working_string = f"{input_string}"
110-
110+
111111
for builtin in {x for x in builtins_list if not x.startswith("__") and x != "None"}:
112112
working_string = working_string.replace(f"``{builtin}``", f":class:`~python:{builtin}`")
113-
113+
114114
return working_string
115115

116116

@@ -121,11 +121,11 @@ def is_documented_by(original):
121121
122122
This may be useful for subclasses or wrappers that use the same arguments.
123123
"""
124-
124+
125125
def wrapper(target):
126126
document_object_from_another(target, original)
127127
return target
128-
128+
129129
return wrapper
130130

131131

@@ -139,11 +139,11 @@ def append_docstring_from(original):
139139
ensure consistent indentation between the two docstrings.
140140
Bear this in mind if additional indentation is used in the docstring.
141141
"""
142-
142+
143143
def wrapper(target):
144144
append_doctring_from_another(target, original)
145145
return target
146-
146+
147147
return wrapper
148148

149149

@@ -152,13 +152,13 @@ def sphinxify_docstring():
152152
Make proper sphinx links out of double-backticked strings in docstring.
153153
154154
i.e. \`\`str\`\` becomes \:class\:\`~python:str\`
155-
155+
156156
Make sure to have `'python': ('https://docs.python.org/3/', None),` in the
157157
`intersphinx_mapping` dict of your conf.py for sphinx.
158158
"""
159-
159+
160160
def wrapper(target):
161161
target.__doc__ = make_sphinx_links(target.__doc__)
162162
return target
163-
163+
164164
return wrapper

0 commit comments

Comments
 (0)