Kill old stuff
parent
a9ac3ca89e
commit
f1c2721fd2
|
@ -38,7 +38,6 @@ def wrapped_main(stdscr):
|
|||
decimal.getcontext().prec = 50
|
||||
|
||||
# Register exit handler
|
||||
# pylint: disable=unused-argument
|
||||
def exit_handler(signum, frame):
|
||||
"""Call the lerpn cleanup/exit function, to be used as a signal handler"""
|
||||
tui.do_exit(stack)
|
||||
|
|
|
@ -20,8 +20,6 @@ commands are in the SINGLE_KEY_COMMANDS OrderedDict, and full-name
|
|||
commands are in the COMMANDS OrderedDict.
|
||||
"""
|
||||
|
||||
# pylint: disable=missing-docstring,unused-argument
|
||||
|
||||
import cmath
|
||||
import collections
|
||||
import curses
|
||||
|
@ -88,7 +86,7 @@ def CONST(val, descr):
|
|||
except NameError:
|
||||
unicode = str
|
||||
|
||||
if type(val) in [float, str, unicode, int, long, Decimal]:
|
||||
if type(val) in [float, str, unicode, int, Decimal]:
|
||||
val = Decimal(val)
|
||||
elif callable(val):
|
||||
val = val
|
||||
|
@ -208,15 +206,15 @@ def _log2(stack, arg):
|
|||
@BINARY
|
||||
def _unsigned(x, y):
|
||||
"""Y to unsigned in X-bit"""
|
||||
x = long(x)
|
||||
y = long(y)
|
||||
x = int(x)
|
||||
y = int(y)
|
||||
return Decimal((2 ** y + x) % (2 ** y))
|
||||
|
||||
@BINARY
|
||||
def _signed(x, y):
|
||||
"""Y to signed in X-bit"""
|
||||
x = long(x)
|
||||
y = long(y)
|
||||
x = int(x)
|
||||
y = int(y)
|
||||
return Decimal(((x - 2**y) + 2**y//2) % 2**y - 2**y//2)
|
||||
|
||||
@UNARY
|
||||
|
@ -574,10 +572,10 @@ SINGLE_KEY_COMMANDS = collections.OrderedDict([
|
|||
|
||||
("<", BINARY(lambda x, y: x * 2 ** y, "shift left")),
|
||||
(">", BINARY(lambda x, y: x // 2 ** y, "shift right")),
|
||||
("&", BINARY(lambda x, y: Decimal(long(x) & long(y)), "bitwise AND")),
|
||||
("|", BINARY(lambda x, y: Decimal(long(x) | long(y)), "bitwise OR")),
|
||||
("X", BINARY(lambda x, y: Decimal(long(x) ^ long(y)), "bitwise XOR")),
|
||||
("~", UNARY(lambda x: Decimal(~long(x)), "invert bits")),
|
||||
("&", BINARY(lambda x, y: Decimal(int(x) & int(y)), "bitwise AND")),
|
||||
("|", BINARY(lambda x, y: Decimal(int(x) | int(y)), "bitwise OR")),
|
||||
("X", BINARY(lambda x, y: Decimal(int(x) ^ int(y)), "bitwise XOR")),
|
||||
("~", UNARY(lambda x: Decimal(~int(x)), "invert bits")),
|
||||
|
||||
("u", _undo),
|
||||
("R", _redo),
|
||||
|
|
|
@ -19,12 +19,7 @@ from decimal import Decimal
|
|||
from fractions import Fraction
|
||||
import math
|
||||
|
||||
try:
|
||||
long
|
||||
except NameError:
|
||||
long = int
|
||||
|
||||
class ComplexDec(object):
|
||||
class ComplexDec():
|
||||
def __init__(self, real, imag=None):
|
||||
if hasattr(real, "to_decimal"):
|
||||
real = real.to_decimal()
|
||||
|
@ -32,7 +27,7 @@ class ComplexDec(object):
|
|||
imag = imag.to_decimal()
|
||||
|
||||
if imag is None:
|
||||
if isinstance(real, (float, Decimal, int, long)):
|
||||
if isinstance(real, (float, Decimal, int)):
|
||||
self._real = Decimal(real)
|
||||
self._imag = Decimal("0")
|
||||
elif hasattr(real, "fraction"):
|
||||
|
@ -94,12 +89,6 @@ class ComplexDec(object):
|
|||
|
||||
__rmul__ = __mul__
|
||||
|
||||
# For Python 2
|
||||
def __div__(self, other):
|
||||
return self.__truediv__(other)
|
||||
def __rdiv__(self, other):
|
||||
return self.__rtruediv__(other)
|
||||
|
||||
def __truediv__(self, other):
|
||||
# (a+jb)/(c+jd) = ((ac+bd)+(bc-ad)j)/(c^2+d^2)
|
||||
other = ComplexDec(other)
|
||||
|
|
|
@ -36,8 +36,7 @@ KEY_TO_NAME = {
|
|||
curses.KEY_END: "[end]",
|
||||
}
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
class CursesScrollBox(object):
|
||||
class CursesScrollBox():
|
||||
"""Displays some text in a scroll box."""
|
||||
|
||||
def __init__(self, parent, width, height):
|
||||
|
@ -259,7 +258,6 @@ def draw_vline(window, xpos, ystart, height):
|
|||
if ystart < 0:
|
||||
ystart = w_height - height + ystart
|
||||
|
||||
# pylint: disable=no-member
|
||||
# ACS_VLINE is populated at load
|
||||
window.vline(ystart, xpos, curses.ACS_VLINE, height)
|
||||
|
||||
|
|
|
@ -23,13 +23,6 @@ from fractions import Fraction
|
|||
from .complexdec import ComplexDec
|
||||
from .smartfrac import SmartFrac
|
||||
|
||||
# Python 3 has automatic bigints; Python 2 calls them 'long'. Provide a
|
||||
# compat type here so we can use them predictably
|
||||
try:
|
||||
long
|
||||
except NameError:
|
||||
long = int
|
||||
|
||||
def dec_divmod(a, b):
|
||||
result = a % b
|
||||
if result < Decimal(0):
|
||||
|
|
|
@ -272,7 +272,7 @@ class UndoStack(list):
|
|||
"""replace the redo stack directly after undopush has cleared it."""
|
||||
self.__redo = self.__redo_held
|
||||
|
||||
class Tagged(object):
|
||||
class Tagged():
|
||||
"""Tagged number object.
|
||||
This behaves like a number, but also contains a string tag. The values
|
||||
are accessible at .num and .tag
|
||||
|
@ -465,7 +465,7 @@ def natfix(num, nfrac, padded=False):
|
|||
s = s.rstrip("0")
|
||||
return s
|
||||
|
||||
class DisplayMode(object):
|
||||
class DisplayMode():
|
||||
"""Class with methods to implement a display mode"""
|
||||
|
||||
def format_real(self, num):
|
||||
|
@ -639,16 +639,6 @@ class HexMode(DisplayMode):
|
|||
def format_real(self, num):
|
||||
"""Format a Decimal, rounded to integer, in hexadecimal"""
|
||||
|
||||
def hex_h(v):
|
||||
"""same as hex(), but use 0h as the prefix instead of 0x, and drop
|
||||
L suffix in Py2"""
|
||||
|
||||
return re.sub(
|
||||
r"(-?)0x([0-9A-Fa-f]*)L?",
|
||||
r"\g<1>0h\2",
|
||||
hex(v)
|
||||
)
|
||||
|
||||
return format_int(num, hex)
|
||||
|
||||
def name(self):
|
||||
|
@ -658,8 +648,7 @@ class DecMode(DisplayMode):
|
|||
"""Display integers in decimal, non-integers in natural mode."""
|
||||
def format_real(self, num):
|
||||
"""Format a Decimal, rounded to integer, in decimal"""
|
||||
# Strip L suffix in Py2 from using long()
|
||||
return format_int(num, lambda x: str(long(x)).rstrip("L"))
|
||||
return format_int(num, str)
|
||||
|
||||
@classmethod
|
||||
def name(self):
|
||||
|
@ -670,17 +659,7 @@ class OctMode(DisplayMode):
|
|||
def format_real(self, num):
|
||||
"""Format a Decimal, rounded to integer, in octal"""
|
||||
|
||||
def consistent_oct(n):
|
||||
"""Format octal consistently, always 0o123 rather than
|
||||
0123 regardless of Python version."""
|
||||
|
||||
return re.sub(
|
||||
r"(-?)0o?([0-7]*)L?",
|
||||
r"\g<1>0o\2",
|
||||
oct(n)
|
||||
)
|
||||
|
||||
return format_int(num, consistent_oct)
|
||||
return format_int(num, oct)
|
||||
|
||||
def name(self):
|
||||
return "'oct"
|
||||
|
@ -689,7 +668,7 @@ class BinMode(DisplayMode):
|
|||
"""Display integers in binary, non-integers in natural mode."""
|
||||
def format_real(self, num):
|
||||
"""Format a Decimal, rounded to integer, in binary"""
|
||||
return format_int(num, lambda x: bin(x).rstrip("L"))
|
||||
return format_int(num, bin)
|
||||
|
||||
def name(self):
|
||||
return "'bin"
|
||||
|
@ -742,7 +721,7 @@ def format_int(value, fxn):
|
|||
fxn(int(value)), otherwise as "%g" % value."""
|
||||
|
||||
if value.to_integral_value() == value:
|
||||
return fxn(long(value))
|
||||
return fxn(int(value))
|
||||
else:
|
||||
return NaturalMode().format_real(value)
|
||||
|
||||
|
|
|
@ -105,7 +105,6 @@ def do_command(stack, cmd, arg):
|
|||
Returns None if no exception, or sys.exc_info() if there was one.
|
||||
"""
|
||||
|
||||
# pylint: disable=broad-except
|
||||
try:
|
||||
stack.undopush()
|
||||
rtn = cmd(stack, arg)
|
||||
|
@ -261,7 +260,6 @@ class Prompt(object):
|
|||
"""Execute any actions accumulated over a machine cycle."""
|
||||
for cmd, arg in self.actions:
|
||||
if cmd == "parse":
|
||||
# pylint: disable=broad-except
|
||||
try:
|
||||
parsed = nums.num_parser(arg, set_auto=True)
|
||||
except Exception:
|
||||
|
@ -278,7 +276,8 @@ class Prompt(object):
|
|||
|
||||
|
||||
def state_firstchar(self):
|
||||
"""State 'firstchar': look at the first character typed and determine the kind of input."""
|
||||
"""State 'firstchar': look at the first character typed and determine
|
||||
the kind of input."""
|
||||
# Try single-key commands first
|
||||
cmd = get_single_key_command(self.key)
|
||||
if cmd is not None:
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
# lerpn - Linux Engineering RPN calculator
|
||||
|
||||
It's a curses RPN calculator written in straight Python. Not actually Linux-dependent,
|
||||
despite the (old) name. Should work on both Python 2 and 3, though I only regularly
|
||||
use/test it in Py3.
|
||||
despite the (old) name. Requires Python 3.6 at least.
|
||||
|
||||
To install, clone this repository and run `python3 setup.py install --user`.
|
||||
To test-drive, call `python3 -m LerpnApp` from the root of the source tree.
|
||||
|
|
Loading…
Reference in New Issue