Skip to content

Commit 17392cd

Browse files
committed
Updated docstrings and some copyrights. Reformatting. Removed entry function because it is now redundant in production code.
1 parent 6d24cf1 commit 17392cd

File tree

6 files changed

+49
-54
lines changed

6 files changed

+49
-54
lines changed

domdf_python_tools/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
# Copyright © 2012 atzz
1515
# Licensed under CC-BY-SA
1616
#
17-
17+
# Parts of the docstrings based on the Python 3.8.2 Documentation
18+
# Licensed under the Python Software Foundation License Version 2.
19+
# Copyright © 2001-2020 Python Software Foundation. All rights reserved.
20+
# Copyright © 2000 BeOpen.com . All rights reserved.
21+
# Copyright © 1995-2000 Corporation for National Research Initiatives . All rights reserved.
22+
# Copyright © 1991-1995 Stichting Mathematisch Centrum . All rights reserved.
23+
#
1824

1925
from domdf_python_tools.utils import *
2026
from domdf_python_tools import paths, terminal, utils, doctools

domdf_python_tools/dates.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def current_tzinfo():
4242
"""
4343
Returns a tzinfo object for the current timezone
4444
45-
:rtype: :class:`~python:datetime.datetime.tzinfo`
45+
:rtype: :class:`~python:datetime.tzinfo`
4646
"""
4747

4848
return datetime.datetime.now().astimezone().tzinfo
@@ -56,7 +56,7 @@ def datetime_to_utc_timestamp(datetime, current_tzinfo=None):
5656
:type datetime: :class:`datetime.datetime`
5757
:param current_tzinfo: A tzinfo object representing the current timezone.
5858
If None it will be inferred.
59-
:type current_tzinfo: :class:`~python:datetime.datetime.tzinfo`
59+
:type current_tzinfo: :class:`~python:datetime.tzinfo`
6060
6161
:return: Timestamp in UTC timezone
6262
:rtype: float
@@ -72,15 +72,15 @@ def utc_timestamp_to_datetime(utc_timestamp, output_tz=None):
7272
If ``output_tz`` is None the timestamp is converted to the platform’s local date and time,
7373
and the local timezone is inferred and set for the object.
7474
75-
If ``output_tz`` is not None, it must be an instance of a :class:`~python:datetime.datetime.tzinfo` subclass,
76-
and the timestamp is converted to tz’s time zone.
75+
If ``output_tz`` is not None, it must be an instance of a :class:`~python:datetime.tzinfo` subclass,
76+
and the timestamp is converted to ``output_tz``’s time zone.
7777
7878
7979
:param utc_timestamp: The timestamp to convert to a datetime object
8080
:type utc_timestamp: float, int
8181
:param output_tz: The timezone to output the datetime object for.
8282
If None it will be inferred.
83-
:type output_tz: :class:`~python:datetime.datetime.tzinfo`
83+
:type output_tz: :class:`~python:datetime.tzinfo`
8484
8585
:return: The timestamp as a datetime object.
8686
:rtype: :class:`datetime.datetime`

domdf_python_tools/doctools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def make_sphinx_links(input_string, builtins_list=None):
110110
111111
112112
Make sure to have `'python': ('https://docs.python.org/3/', None),` in the
113-
`intersphinx_mapping` dict of your conf.py for sphinx.
114-
113+
`intersphinx_mapping` dict of your conf.py for sphinx.
114+
115115
:param input_string: The string to process
116116
:type input_string: str
117117
:param builtins_list: A list of builtins to make links for
@@ -139,7 +139,7 @@ def sphinxify_docstring():
139139
i.e. \`\`str\`\` becomes \:class\:\`~python:str\`
140140
141141
Make sure to have `'python': ('https://docs.python.org/3/', None),` in the
142-
`intersphinx_mapping` dict of your conf.py for sphinx.
142+
`intersphinx_mapping` dict of your conf.py for sphinx.
143143
"""
144144

145145
def wrapper(target):

domdf_python_tools/paths.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
# Copytight © 2008 Ned Batchelder
2121
# Licensed under CC-BY-SA
2222
#
23+
# Parts of the docstrings based on the Python 3.8.2 Documentation
24+
# Licensed under the Python Software Foundation License Version 2.
25+
# Copyright © 2001-2020 Python Software Foundation. All rights reserved.
26+
# Copyright © 2000 BeOpen.com . All rights reserved.
27+
# Copyright © 1995-2000 Corporation for National Research Initiatives . All rights reserved.
28+
# Copyright © 1991-1995 Stichting Mathematisch Centrum . All rights reserved.
29+
#
2330
# This program is free software; you can redistribute it and/or modify
2431
# it under the terms of the GNU Lesser General Public License as published by
2532
# the Free Software Foundation; either version 3 of the License, or

domdf_python_tools/terminal.py

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# from https://gist.github.com/jtriley/1108174
1313
# Copyright © 2011 jtriley
1414
#
15+
# Parts of the docstrings based on the Python 3.8.2 Documentation
16+
# Licensed under the Python Software Foundation License Version 2.
17+
# Copyright © 2001-2020 Python Software Foundation. All rights reserved.
18+
# Copyright © 2000 BeOpen.com . All rights reserved.
19+
# Copyright © 1995-2000 Corporation for National Research Initiatives . All rights reserved.
20+
# Copyright © 1991-1995 Stichting Mathematisch Centrum . All rights reserved.
21+
#
1522
# This program is free software; you can redistribute it and/or modify
1623
# it under the terms of the GNU Lesser General Public License as published by
1724
# the Free Software Foundation; either version 3 of the License, or
@@ -27,25 +34,21 @@
2734
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
2835
# MA 02110-1301, USA.
2936
#
30-
#
3137

3238
# stdlib
3339
import os
34-
import sys
40+
import platform
3541
import shlex
3642
import struct
37-
import platform
3843
import subprocess
39-
40-
# this package
41-
from domdf_python_tools import pyversion
44+
import sys
4245

4346

4447
def clear():
4548
"""
4649
Clear the display
4750
48-
works for Windows and UNIX, but does not clear Python Shell
51+
works for Windows and UNIX, but does not clear Python Interpreter
4952
5053
:return:
5154
"""
@@ -61,32 +64,14 @@ def br():
6164
print("")
6265

6366

64-
def entry(text_to_print):
65-
"""
66-
Version-agnostic input function
67-
68-
# TODO: Deprecation warning
69-
70-
:param text_to_print: Text to print before the input field
71-
:type text_to_print: str
72-
73-
:return: Text entered
74-
:rtype: str
75-
"""
76-
77-
if pyversion == 3:
78-
return input(text_to_print)
79-
elif pyversion == 2:
80-
return raw_input(text_to_print)
81-
8267

8368
def interrupt():
8469
"""
8570
Print what to do to abort the script; dynamic depending on OS
8671
Useful when you have a long-running script that you might want t interrupt part way through
8772
"""
8873

89-
print('(Press Ctrl-%s to quit at any time.)' % 'C' if os.name == 'nt' else 'D')
74+
print(f"(Press Ctrl-{'C' if os.name == 'nt' else 'D'} to quit at any time.)")
9075

9176

9277
def overtype(*objects, sep=' ', end='', file=sys.stdout, flush=False):
@@ -97,11 +82,9 @@ def overtype(*objects, sep=' ', end='', file=sys.stdout, flush=False):
9782
All non-keyword arguments are converted to strings like ``str()`` does and written to the stream,
9883
separated by `sep` and followed by `end`.
9984
100-
If no objects are given, ``overwrite()` will just write "\r".
101-
102-
Based on the Python print() docs: https://docs.python.org/3/library/functions.html#print
85+
If no objects are given, ``overtype()`` will just write "\r".
10386
104-
# This does not currently work in the PyCharm console, at least on Windows
87+
TODO: This does not currently work in the PyCharm console, at least on Windows
10588
10689
:param objects:
10790
:param sep: String to separate the objects with, by default " "
@@ -155,12 +138,12 @@ def _get_terminal_size_windows():
155138
csbi = create_string_buffer(22)
156139
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
157140
if res:
158-
(bufx, bufy, curx, cury, wattr,
141+
(buf_x, buf_y, cur_x, cur_y, wattr,
159142
left, top, right, bottom,
160143
maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
161-
sizex = right - left + 1
162-
sizey = bottom - top + 1
163-
return sizex, sizey
144+
size_x = right - left + 1
145+
size_y = bottom - top + 1
146+
return size_x, size_y
164147
except:
165148
pass
166149

@@ -171,7 +154,7 @@ def _get_terminal_size_tput():
171154
try:
172155
cols = int(subprocess.check_call(shlex.split('tput cols')))
173156
rows = int(subprocess.check_call(shlex.split('tput lines')))
174-
return (cols, rows)
157+
return cols, rows
175158
except:
176159
pass
177160

@@ -181,8 +164,7 @@ def ioctl_GWINSZ(fd):
181164
try:
182165
import fcntl
183166
import termios
184-
cr = struct.unpack('hh',
185-
fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
167+
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
186168
return cr
187169
except:
188170
pass
@@ -203,5 +185,5 @@ def ioctl_GWINSZ(fd):
203185

204186

205187
if __name__ == "__main__":
206-
sizex, sizey = get_terminal_size()
207-
print('width =', sizex, 'height =', sizey)
188+
size_x, size_y = get_terminal_size()
189+
print('width =', size_x, 'height =', size_y)

domdf_python_tools/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def check_dependencies(dependencies, prt=True):
107107
if len(missing_modules) == 0:
108108
print("All modules installed")
109109
else:
110-
print("""\rThe following modules are missing.
111-
Please check the documentation.""")
110+
print("The following modules are missing.")
112111
print(missing_modules)
112+
print("Please check the documentation.")
113113
print("")
114114

115115
else:
@@ -148,7 +148,7 @@ def list2str(the_list, sep=","):
148148
return sep.join([str(x) for x in the_list])
149149

150150

151-
def splitLen(string,n):
151+
def splitLen(string, n):
152152
"""
153153
Split a string every x characters
154154
@@ -158,7 +158,7 @@ def splitLen(string,n):
158158
:return:
159159
"""
160160

161-
return [string[i:i+n] for i in range(0,len(string),n)]
161+
return [string[i:i + n] for i in range(0, len(string), n)]
162162

163163

164164
def permutations(data, n=2):
@@ -216,7 +216,7 @@ def __init__(self, *args, **kwargs):
216216
if len(args) == 0:
217217
for key, value in kwargs.items():
218218
self.__setitem__(key, value)
219-
219+
220220
def __setitem__(self, key, val):
221221
if key in self or val in self:
222222
if key in self and self[key] != val:
@@ -259,7 +259,7 @@ def __getitem__(self, key):
259259
key = "_False"
260260

261261
val = dict.__getitem__(self, key)
262-
262+
263263
if val == "_None":
264264
return None
265265
elif val == "_True":

0 commit comments

Comments
 (0)