Raise exception instead of using assert
This commit is contained in:
parent
80bfccd9d3
commit
ff32f822ba
7 changed files with 27 additions and 12 deletions
|
@ -2,7 +2,9 @@ import array
|
|||
|
||||
|
||||
def packPiecefield(data):
|
||||
assert isinstance(data, bytes) or isinstance(data, bytearray)
|
||||
if not isinstance(data, bytes) and not isinstance(data, bytearray):
|
||||
raise Exception("Invalid data type: %s" % type(data))
|
||||
|
||||
res = []
|
||||
if not data:
|
||||
return array.array("H", b"")
|
||||
|
@ -46,7 +48,9 @@ def unpackPiecefield(data):
|
|||
|
||||
|
||||
def spliceBit(data, idx, bit):
|
||||
assert bit == b"\x00" or bit == b"\x01"
|
||||
if bit != b"\x00" and bit != b"\x01":
|
||||
raise Exception("Invalid bit: %s" % bit)
|
||||
|
||||
if len(data) < idx:
|
||||
data = data.ljust(idx + 1, b"\x00")
|
||||
return data[:idx] + bit + data[idx+ 1:]
|
||||
|
@ -63,7 +67,8 @@ class BigfilePiecefield(Piecefield):
|
|||
self.data = b""
|
||||
|
||||
def frombytes(self, s):
|
||||
assert isinstance(s, bytes) or isinstance(s, bytearray)
|
||||
if not isinstance(s, bytes) and not isinstance(s, bytearray):
|
||||
raise Exception("Invalid type: %s" % type(s))
|
||||
self.data = s
|
||||
|
||||
def tobytes(self):
|
||||
|
@ -91,7 +96,8 @@ class BigfilePiecefieldPacked(Piecefield):
|
|||
self.data = b""
|
||||
|
||||
def frombytes(self, data):
|
||||
assert isinstance(data, bytes) or isinstance(data, bytearray)
|
||||
if not isinstance(data, bytes) and not isinstance(data, bytearray):
|
||||
raise Exception("Invalid type: %s" % type(data))
|
||||
self.data = packPiecefield(data).tobytes()
|
||||
|
||||
def tobytes(self):
|
||||
|
|
|
@ -137,7 +137,9 @@ class UiWebsocketPlugin(object):
|
|||
@PluginManager.registerTo("User")
|
||||
class UserPlugin(object):
|
||||
def getEncryptPrivatekey(self, address, param_index=0):
|
||||
assert param_index >= 0 and param_index <= 1000
|
||||
if param_index < 0 or param_index > 1000:
|
||||
raise Exception("Param_index out of range")
|
||||
|
||||
site_data = self.getSiteData(address)
|
||||
|
||||
if site_data.get("cert"): # Different privatekey for different cert provider
|
||||
|
@ -153,7 +155,9 @@ class UserPlugin(object):
|
|||
return site_data["encrypt_privatekey_%s" % index]
|
||||
|
||||
def getEncryptPublickey(self, address, param_index=0):
|
||||
assert param_index >= 0 and param_index <= 1000
|
||||
if param_index < 0 or param_index > 1000:
|
||||
raise Exception("Param_index out of range")
|
||||
|
||||
site_data = self.getSiteData(address)
|
||||
|
||||
if site_data.get("cert"): # Different privatekey for different cert provider
|
||||
|
|
|
@ -13,7 +13,8 @@ class WsLogStreamer(logging.StreamHandler):
|
|||
self.ui_websocket = ui_websocket
|
||||
|
||||
if filter:
|
||||
assert SafeRe.isSafePattern(filter)
|
||||
if not SafeRe.isSafePattern(filter):
|
||||
raise Exception("Not a safe prex pattern")
|
||||
self.filter_re = re.compile(".*" + filter)
|
||||
else:
|
||||
self.filter_re = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue