- Options use a more robust int callback by default (handles hex and oct digits as well)
- over.misc.hexdump extended with initial_offset
This commit is contained in:
parent
e699be5c6d
commit
e9556c1fbe
4 changed files with 29 additions and 4 deletions
|
@ -126,6 +126,10 @@ class Option:
|
|||
else:
|
||||
self.is_boolean = is_boolean
|
||||
|
||||
# coerce a few Python types to our own
|
||||
if callback == int:
|
||||
self.callback = callback_module.integer
|
||||
|
||||
self.reset(True) # sets self.source and self._value_lists
|
||||
|
||||
def reset(self, default=False):
|
||||
|
|
|
@ -78,3 +78,24 @@ def directory(exists=False, writable=False, gio=False):
|
|||
return path
|
||||
|
||||
return cb
|
||||
|
||||
def integer(arg):
|
||||
"""
|
||||
Converts
|
||||
- "0x2a" ⇒ 42
|
||||
- "0o52" ⇒ 42
|
||||
- "42" ⇒ 42
|
||||
|
||||
@while converting argument to int
|
||||
"""
|
||||
|
||||
if type(arg) == int:
|
||||
return arg
|
||||
|
||||
if len(arg) > 2:
|
||||
if arg[1] == "x":
|
||||
return int(arg, 16)
|
||||
elif arg[1] == "o":
|
||||
return int(arg, 8)
|
||||
|
||||
return int(arg)
|
||||
|
|
|
@ -110,7 +110,7 @@ def debugger():
|
|||
|
||||
# --------------------------------------------------
|
||||
|
||||
def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show_ascii=True, use_colors=True, output=sys.stdout):
|
||||
def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show_ascii=True, use_colors=True, initial_offset=0, output=sys.stdout):
|
||||
"""
|
||||
Writes a hex dump of `data` to `output`.
|
||||
|
||||
|
@ -156,7 +156,7 @@ def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show
|
|||
output_io.write(" " * indent)
|
||||
|
||||
if show_offsets:
|
||||
output_io.write(format_str %(ptr))
|
||||
output_io.write(format_str %(initial_offset + ptr))
|
||||
|
||||
hex_bytes = []
|
||||
ascii_bytes = []
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
major = 1 # VERSION_MAJOR_IDENTIFIER
|
||||
minor = 101 # VERSION_MINOR_IDENTIFIER
|
||||
# VERSION_LAST_MM 1.101
|
||||
patch = 1 # VERSION_PATCH_IDENTIFIER
|
||||
str = "1.101.1" # VERSION_STRING_IDENTIFIER
|
||||
patch = 2 # VERSION_PATCH_IDENTIFIER
|
||||
str = "1.101.2" # VERSION_STRING_IDENTIFIER
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue