Changes based on style and lint checks. (final_code_quality_2) #1357
No reviewers
Labels
No Label
bug
build
dependencies
developers
documentation
duplicate
enhancement
formatting
invalid
legal
mobile
obsolete
packaging
performance
protocol
question
refactoring
regression
security
test
translation
usability
wontfix
No Milestone
No project
No Assignees
1 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Bitmessage/PyBitmessage-2024-12-15#1357
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "final_code_quality_2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Changes based on style and lint checks. (final_code_quality_2)
@ -3,3 +8,4 @@
from PyQt4 import QtCore, QtGui
class SettingsMixin(object):
Mixin for adding geometry and state saving between restarts.
@ -5,2 +10,4 @@
class SettingsMixin(object):
"""Mixin for adding geometry and state saving between restarts."""
def warnIfNoObjectName(self):
Handle objects which don't have a name. Currently it ignores them. Objects without a name can't have their state/geometry saved as they don't have an identifier.
@ -11,2 +21,4 @@
def writeState(self, source):
"""Save object state (e.g. relative position of a splitter)"""
self.warnIfNoObjectName()
Save object state (e.g. relative position of a splitter)
@ -18,3 +30,4 @@
def writeGeometry(self, source):
"""Save object geometry (e.g. window size and position)"""
self.warnIfNoObjectName()
settings = QtCore.QSettings()
Save object geometry (e.g. window size and position)
@ -26,3 +39,4 @@
"""Load object geometry"""
self.warnIfNoObjectName()
settings = QtCore.QSettings()
try:
Load object geometry
@ -35,4 +50,4 @@
self.warnIfNoObjectName()
settings = QtCore.QSettings()
try:
state = settings.value("/".join([str(self.objectName()), "state"]))
Load object state
@ -47,3 +64,3 @@
self.readState(self)
def saveSettings(self):
Main window with Settings functionality.
@ -49,2 +65,4 @@
def saveSettings(self):
"""Save main window settings"""
self.writeState(self)
Load main window settings.
@ -53,2 +71,4 @@
class STableWidget(QtGui.QTableWidget, SettingsMixin):
"""Table widget with Settings functionality"""
# pylint: disable=too-many-ancestors
Save main window settings
@ -56,3 +77,4 @@
self.readState(self.horizontalHeader())
def saveSettings(self):
"""Save table settings."""
Table widget with Settings functionality
@ -59,3 +81,3 @@
self.writeState(self.horizontalHeader())
Load table settings.
@ -62,2 +84,4 @@
class SSplitter(QtGui.QSplitter, SettingsMixin):
"""Splitter with Settings functionality."""
def loadSettings(self):
"""Load splitter settings"""
Save table settings.
@ -67,2 +91,3 @@
"""Save splitter settings."""
self.writeState(self)
Splitter with Settings functionality.
@ -68,3 +93,3 @@
class STreeWidget(QtGui.QTreeWidget, SettingsMixin):
Load splitter settings
@ -71,3 +98,2 @@
def loadSettings(self):
#recurse children
#self.readState(self)
"""Load tree settings."""
Save splitter settings.
@ -76,3 +104,2 @@
def saveSettings(self):
#recurse children
#self.writeState(self)
"""Save tree settings"""
Tree widget with settings functionality.
@ -79,1 +105,4 @@
"""Save tree settings"""
# recurse children
# self.writeState(self)
pass
Load tree settings.
Save tree settings
@ -5,2 +12,4 @@
class Socks5AuthError(ProxyError):
"""Thrown when the socks5 protocol encounters an authentication error"""
Thrown when the socks5 protocol encounters an authentication error
@ -24,1 +26,3 @@
"Unknown error")
"General SOCKS server failure",
"Connection not allowed by ruleset",
"Network unreachable",
Thrown when socks5 protocol encounters an error
@ -42,3 +54,4 @@
"""Perform authentication if peer is requesting it."""
ret = struct.unpack('BB', self.read_buf[:2])
if ret[0] != 5:
# general error
Protocol initialisation (before connection is established)
@ -98,3 +113,4 @@
def state_proxy_addr_1(self):
"""Handle IPv4 address returned for peer"""
self.boundaddr = self.read_buf[0:4]
self.set_state("proxy_port", length=4, expectBytes=2)
Perform authentication if peer is requesting it.
@ -131,3 +158,4 @@
def state_auth_done(self):
"""Request connection to be made"""
# Now we can request the actual connection
self.append_write_buf(struct.pack('BBB', 0x05, 0x01, 0x00))
Handle response to authentication attempt
@ -151,6 +181,7 @@ class Socks5Connection(Socks5):
return True
Handle feedback from socks5 while it is connecting on our behalf.
Handle IPv4 address returned for peer
Handle other addresses than IPv4 returned for peer (e.g. IPv6, onion, ...). This is part 1 which retrieves the length of the data.
Handle other addresses than IPv4 returned for peer (e.g. IPv6, onion, ...). This is part 2 which retrieves the data.
Handle peer's port being returned.
Handle eturn value when using SOCKS5 for DNS resolving instead of connecting.
Child socks5 class used for making outbound connections.
@ -112,3 +136,4 @@
def state_proxy_port(self):
"""Handle peer's port being returned."""
self.boundport = struct.unpack(">H", self.read_buf[0:2])[0]
Init
Request connection to be made
Tell socks5 to initiate a connection
DNS resolver class using socks5
Init
Perform resolving
Resolving is done, process the return value. To use this within PyBitmessage, a callback needs to be implemented which hasn't been done yet.
Add docstrings, otherwise OK, however I would also test it against a SOCKS5 server (e.g. the one used by tor) to make sure nothing breaks
typo
typo
I found two typos in docstrings which can be ignored.
@ -112,3 +136,4 @@
def state_proxy_port(self):
"""Handle peer's port being returned."""
self.boundport = struct.unpack(">H", self.read_buf[0:2])[0]
Went for """Child socks5 class used for making outbound connections.""", assuming you were thinking about commenting the
__init__
method with your comment