Navigation Menu

Skip to content

Commit

Permalink
- Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed May 17, 2014
1 parent 0100b0f commit 875db89
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 126 deletions.
30 changes: 15 additions & 15 deletions hex_checksum.py
Expand Up @@ -60,16 +60,16 @@ def algorithm(self, name, digest_size, arg):
self.update(arg)

def copy(self):
return None if self.__algorithm == None else self.__algorithm.copy()
return None if self.__algorithm is None else self.__algorithm.copy()

def digest(self):
return None if self.__algorithm == None else self.__algorithm.digest()
return None if self.__algorithm is None else self.__algorithm.digest()

def hexdigest(self):
return None if self.__algorithm == None else self.__algorithm.hexdigest()
return None if self.__algorithm is None else self.__algorithm.hexdigest()

def update(self, arg):
if self.__algorithm != None:
if self.__algorithm is not None:
self.__algorithm.update(arg)


Expand Down Expand Up @@ -98,13 +98,13 @@ def copy(self):
return self

def digest(self):
return None if self.__algorithm == None else self.__hash & 0xffffffff
return None if self.__algorithm is None else self.__hash & 0xffffffff

def hexdigest(self):
return None if self.__algorithm == None else '%08x' % (self.digest())
return None if self.__algorithm is None else '%08x' % (self.digest())

def update(self, arg):
if self.__algorithm != None:
if self.__algorithm is not None:
self.__hash = self.__algorithm(arg, self.__hash)


Expand Down Expand Up @@ -149,9 +149,9 @@ class checksum(object):
thread = None

def __init__(self, hash_algorithm=None, data=b""):
if hash_algorithm == None or not hash_algorithm in VALID_HASH:
if hash_algorithm is None or hash_algorithm not in VALID_HASH:
hash_algorithm = hv_settings("hash_algorithm", DEFAULT_CHECKSUM)
if not hash_algorithm in VALID_HASH:
if hash_algorithm not in VALID_HASH:
hash_algorithm = DEFAULT_CHECKSUM
self.hash = getattr(hashlib, hash_algorithm)(data)
self.name = hash_algorithm
Expand All @@ -175,7 +175,7 @@ def chunk_thread(self):
message = "[" + "-" * percent + ">" + "-" * leftover + ("] %3d%%" % int(ratio * 100)) + " chunks hashed"
sublime.status_message(message)
if not self.thread.is_alive():
if self.thread.abort == True:
if self.thread.abort is True:
sublime.status_message("Hash calculation aborted!")
sublime.set_timeout(lambda: self.reset_thread(), 500)
else:
Expand All @@ -187,7 +187,7 @@ def reset_thread(self):
self.thread = None

def display(self, window=None):
if window == None:
if window is None:
window = sublime.active_window()
window.show_input_panel(self.name + ":", str(self.hash.hexdigest()), None, None, None)

Expand Down Expand Up @@ -217,7 +217,7 @@ class HashSelectionCommand(sublime_plugin.WindowCommand):
def has_selections(self):
single = False
view = self.window.active_view()
if view != None:
if view is not None:
if len(view.sel()) > 0:
single = True
return single
Expand Down Expand Up @@ -274,7 +274,7 @@ def is_enabled(self):

def run(self, hash_algorithm=None, panel=False):
global active_thread
if active_thread != None and active_thread.thread != None and active_thread.thread.is_alive():
if active_thread is not None and active_thread.thread is not None and active_thread.thread.is_alive():
active_thread.thread.abort = True
else:
if not panel:
Expand All @@ -288,7 +288,7 @@ def select_checksum(self, value):

def get_checksum(self, hash_algorithm=None):
view = self.window.active_view()
if view != None:
if view is not None:
sublime.set_timeout(lambda: sublime.status_message("Checksumming..."), 0)
hex_hash = checksum(hash_algorithm)
r_buffer = view.split_by_newlines(sublime.Region(0, view.size()))
Expand All @@ -315,7 +315,7 @@ def get_checksum(self, hash_algorithm=None):
]
)

#Define extra hash classes as members of hashlib
# Define extra hash classes as members of hashlib
hashlib.md2 = md2
hashlib.mdc2 = mdc2
hashlib.md4 = md4
Expand Down
12 changes: 6 additions & 6 deletions hex_common.py
Expand Up @@ -14,17 +14,17 @@

def is_enabled(current_view=None):
window = sublime.active_window()
if window == None:
if window is None:
return False
view = window.active_view()
if view == None:
if view is None:
return False
# Check not only if active main view is hex,
# check if current view is the main active view
if current_view != None and current_view.id() != view.id():
if current_view is not None and current_view.id() != view.id():
return False
syntax = view.settings().get('syntax')
language = basename(syntax).replace('.tmLanguage', '').lower() if syntax != None else "plain text"
language = basename(syntax).replace('.tmLanguage', '').lower() if syntax is not None else "plain text"
return bool(language == "hex")


Expand Down Expand Up @@ -71,15 +71,15 @@ def adjust_hex_sel(view, start, end, group_size):
else:
start = None
# Adjust ending of selection to end of last selected byte
if size == 0 and start != None:
if size == 0 and start is not None:
end = start + 1
bytes = 1
elif view.score_selector(end, 'raw.nibble.lower') == 0:
if view.score_selector(end - 1, 'raw.nibble.lower'):
end -= 1
else:
end -= 2
if start != None and end != None:
if start is not None and end is not None:
bytes = get_byte_count(start, end, group_size)
return start, end, bytes

Expand Down
42 changes: 21 additions & 21 deletions hex_editor.py
Expand Up @@ -39,9 +39,9 @@ class HexEditorListenerCommand(sublime_plugin.EventListener):
def restore(self, value):
window = sublime.active_window()
view = None
if value.strip().lower() == "yes" and self.fail_safe_view != None:
if value.strip().lower() == "yes" and self.fail_safe_view is not None:
# Quit if cannot find window
if window == None:
if window is None:
self.reset()
return

Expand All @@ -52,11 +52,11 @@ def restore(self, value):
view = v
# Reset handshake so view won't be closed
self.handshake = -1
if view == None:
if view is None:
view = window.new_file()

# Restore view
if view != None:
if view is not None:
# Get highlight settings
highlight_scope = hv_settings("highlight_edit_scope", HIGHLIGHT_EDIT_SCOPE)
highlight_icon = hv_settings("highlight_edit_icon", HIGHLIGHT_EDIT_ICON)
Expand Down Expand Up @@ -104,7 +104,7 @@ def restore(self, value):

def reset(self):
window = sublime.active_window()
if window != None and self.handshake != -1:
if window is not None and self.handshake != -1:
for v in window.views():
if self.handshake == v.id():
window.focus_view(v)
Expand All @@ -117,11 +117,11 @@ def on_close(self, view):
window = sublime.active_window()
file_name = file_name = view.settings().get("hex_viewer_file_name")

if window != None and file_name != None:
if window is not None and file_name is not None:
# Save hex view settings
self.fail_safe_view = {
"buffer": view.substr(sublime.Region(0, view.size())),
"bits": view.settings().get("hex_viewer_bits"),
"bits": view.settings().get("hex_viewer_bits"),
"bytes": view.settings().get("hex_viewer_bytes"),
"actual": view.settings().get("hex_viewer_actual_bytes"),
"name": file_name,
Expand All @@ -139,7 +139,7 @@ def on_close(self, view):
count += 1
if count == 1:
view = sublime.active_window().new_file()
if view != None:
if view is not None:
self.handshake = view.id()

# Alert user that they can restore
Expand Down Expand Up @@ -191,8 +191,8 @@ def init(self):
# Get Seetings from settings file
group_size = self.view.settings().get("hex_viewer_bits", None)
self.bytes_wide = self.view.settings().get("hex_viewer_actual_bytes", None)
#Process hex grouping
if group_size != None and self.bytes_wide != None:
# Process hex grouping
if group_size is not None and self.bytes_wide is not None:
self.group_size = group_size / BITS_PER_BYTE
init_status = True
return init_status
Expand All @@ -210,7 +210,7 @@ def apply_edit(self, value):
selection = self.line["selection"].replace(" ", "")

# Transform string if provided
if re.match("^s\:", value) != None:
if re.match("^s\:", value) is not None:
edits = hexlify(value[2:len(value)].encode("ascii")).decode("ascii")
else:
edits = value.replace(" ", "").lower()
Expand All @@ -219,7 +219,7 @@ def apply_edit(self, value):
if len(edits) != total_chars:
self.edit_panel(value, "Unexpected # of bytes!")
return
elif re.match("[\da-f]{" + str(total_chars) + "}", edits) == None:
elif re.match("[\da-f]{" + str(total_chars) + "}", edits) is None:
self.edit_panel(value, "Invalid data!")
return
elif selection != edits:
Expand Down Expand Up @@ -247,26 +247,26 @@ def apply_edit(self, value):

# Diff data and mark changed bytes
if value != original[start:byte_end]:
if change_start == None:
if change_start is None:
change_start = [hex_start_pos, ascii_start_pos]
# Check if group end
if count == self.group_size:
regions.append(sublime.Region(change_start[0], hex_start_pos + 2))
change_start[0] = None
else:
# Check if after group end
if change_start[0] == None:
if change_start[0] is None:
change_start[0] = hex_start_pos
# Check if group end
if count == self.group_size:
regions.append(sublime.Region(change_start[0], hex_start_pos + 2))
change_start[0] = None
elif change_start != None:
elif change_start is not None:
if self.view.score_selector(hex_start_pos - 1, 'raw.nibble.lower'):
if change_start[0] != None:
if change_start[0] is not None:
regions.append(sublime.Region(change_start[0], hex_start_pos))
else:
if change_start[0] != None:
if change_start[0] is not None:
regions.append(sublime.Region(change_start[0], hex_start_pos - 1))
regions.append(sublime.Region(change_start[1], ascii_start_pos))
change_start = None
Expand All @@ -287,8 +287,8 @@ def apply_edit(self, value):
ascii_start_pos += 1

# Check for end of line case for highlight
if change_start != None:
if change_start[0] != None:
if change_start is not None:
if change_start[0] is not None:
regions.append(sublime.Region(change_start[0], hex_start_pos))
regions.append(sublime.Region(change_start[1], ascii_start_pos))
change_start = None
Expand Down Expand Up @@ -351,7 +351,7 @@ def ascii_to_hex(self, start, end):
hex_pos = self.view.text_point(row, column)
start = hex_pos

# Traverse row finding the specified bytes
# Traverse row finding the specified bytes
byte_count = bytes
while byte_count:
# Byte rising edge
Expand All @@ -366,7 +366,7 @@ def ascii_to_hex(self, start, end):
return start, end, bytes

def edit_panel(self, value, error=None):
msg = "Edit:" if error == None else "Edit (" + error + "):"
msg = "Edit:" if error is None else "Edit (" + error + "):"
self.window.show_input_panel(
msg,
value,
Expand Down
6 changes: 3 additions & 3 deletions hex_finder.py
Expand Up @@ -13,14 +13,14 @@ class HexFinderCommand(sublime_plugin.WindowCommand):
handshake = -1

def go_to_address(self, address):
#init
# init
view = self.window.active_view()

if self.handshake != -1 and self.handshake == view.id():
# Adress offset for line
group_size = view.settings().get("hex_viewer_bits", None)
bytes_wide = view.settings().get("hex_viewer_actual_bytes", None)
if group_size == None and bytes_wide == None:
if group_size is None and bytes_wide is None:
return
group_size = group_size / BITS_PER_BYTE

Expand Down Expand Up @@ -60,7 +60,7 @@ def is_enabled(self):
return is_enabled()

def run(self):
# Identify view
# Identify view
view = self.window.active_view()
if self.handshake != -1 and self.handshake == view.id():
self.reset()
Expand Down
26 changes: 13 additions & 13 deletions hex_highlighter.py
Expand Up @@ -80,8 +80,8 @@ def init(self):
elif style == "underline":
self.highlight_style = sublime.DRAW_EMPTY_AS_OVERWRITE

#Process hex grouping
if group_size != None and self.bytes_wide != None:
# Process hex grouping
if group_size is not None and self.bytes_wide is not None:
self.group_size = group_size / BITS_PER_BYTE
self.hex_char_range = get_hex_char_range(self.group_size, self.bytes_wide)
init_status = True
Expand Down Expand Up @@ -144,7 +144,7 @@ def hex_selection(self, start, bytes, first_pos):
if self.first_all == -1:
self.first_all = hex_pos

# Traverse row finding the specified bytes
# Traverse row finding the specified bytes
highlight_start = -1
byte_count = bytes
while byte_count:
Expand Down Expand Up @@ -175,13 +175,13 @@ def ascii_to_hex(self, sel):

# Determine if selection is within ascii range
if (
start >= ascii_range.begin() and
(
# Single selection should ignore the end of line selection
(end == start and end < ascii_range.end() - 1) or
(end != start and end < ascii_range.end())
)
):
start >= ascii_range.begin() and
(
# Single selection should ignore the end of line selection
(end == start and end < ascii_range.end() - 1) or
(end != start and end < ascii_range.end())
)
):
# Single char selection
if sel.size() == 0:
bytes = 1
Expand Down Expand Up @@ -238,7 +238,7 @@ def get_highlights(self):
self.hex_to_ascii(sel)

def run(self, window):
if window == None:
if window is None:
return
self.window = window
view = self.window.active_view()
Expand Down Expand Up @@ -309,7 +309,7 @@ def hh_run():
# be ignored and then accounted for with one match by this thread
def hh_loop():
while not HhThreadMgr.restart:
if Pref.modified == True and time() - Pref.time > Pref.wait_time:
if Pref.modified is True and time() - Pref.time > Pref.wait_time:
sublime.set_timeout(lambda: hh_run(), 0)
sleep(0.5)

Expand All @@ -322,7 +322,7 @@ def plugin_loaded():
global hh_highlight
hh_highlight = HexHighlighter().run

if not 'running_hh_loop' in globals():
if 'running_hh_loop' not in globals():
global running_hh_loop
running_hh_loop = True
thread.start_new_thread(hh_loop, ())
Expand Down

0 comments on commit 875db89

Please sign in to comment.