Skip to content

Commit 9fe1e16

Browse files
committed
move ValueError to sciter.value module
1 parent 942b9f0 commit 9fe1e16

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

sciter/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .window import Window
88
from .dom import Element
99
from .event import EventHandler
10-
from .error import SciterError, ScriptError, ScriptException, ValueError
10+
from .error import SciterError, ScriptError, ScriptException
1111

1212
sapi = api = SciterAPI()
1313
gapi = sapi.GetSciterGraphicsAPI if sapi else None

sciter/error.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,6 @@ class SciterError(Exception):
66
pass
77

88

9-
class ArgumentError(SciterError):
10-
"""."""
11-
def __init__(self, message, script=None):
12-
super().__init__(message)
13-
self.message = message
14-
self.script = script
15-
pass
16-
17-
18-
class ValueError(ArgumentError):
19-
"""."""
20-
def __init__(self, hv_code, script=None):
21-
msg = "Incompatible type" if hv_code == 2 else "Bad parameter"
22-
if script:
23-
msg = msg + " at " + script
24-
super().__init__(msg, script)
25-
pass
26-
27-
289
class ScriptError(SciterError):
2910
"""Raised by runtime from calling script when script error occured (e.g. bad syntax)."""
3011
def __init__(self, message, script=None):

sciter/value.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ctypes
55

66
import sciter
7+
import sciter.error
78
import sciter.capi.scdef
89
import sciter.capi.sctypes
910

@@ -37,6 +38,20 @@ def _subtype_name(subtype):
3738
}
3839

3940

41+
# TODO: Rename it.
42+
class ValueError(sciter.error.SciterError):
43+
"""Raised by sciter.Value operations."""
44+
45+
def __init__(self, hv_code, script=None):
46+
"""."""
47+
msg = "Incompatible type" if hv_code == 2 else "Bad parameter"
48+
if script:
49+
msg = msg + " at " + script
50+
super().__init__(msg)
51+
pass
52+
53+
54+
# sciter.value
4055
class value():
4156
"""sciter::value pythonic wrapper."""
4257

@@ -48,7 +63,7 @@ def parse(cls, json: str, how=VALUE_STRING_CVT_TYPE.CVT_JSON_LITERAL, throw=True
4863
rv = value()
4964
ok = _api.ValueFromString(rv, json, len(json), how)
5065
if ok != 0 and throw:
51-
raise sciter.ValueError(VALUE_RESULT.HV_BAD_PARAMETER, "value.parse")
66+
raise sciter.value.ValueError(VALUE_RESULT.HV_BAD_PARAMETER, "value.parse")
5267
return rv
5368

5469
@classmethod
@@ -538,7 +553,7 @@ def _throw_if(code):
538553
return
539554
import inspect
540555
context = inspect.stack()[1][3]
541-
raise sciter.ValueError(code, "value." + context)
556+
raise sciter.value.ValueError(code, "value." + context)
542557

543558
# utility methods
544559
@staticmethod

tests/test_value.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_13parse(self):
145145
self.assertTrue(xval)
146146
else:
147147
self.assertFalse(xval)
148-
with self.assertRaises(sciter.ValueError):
148+
with self.assertRaises(sciter.value.ValueError):
149149
item = '{item: '
150150
xval = value.parse(item)
151151
pass
@@ -246,7 +246,7 @@ def test_19explicit(self):
246246
self.assertEqual(xval.get_value(), 'secure')
247247

248248
# error
249-
xval = value(ValueError('error'))
249+
xval = value(TypeError('error'))
250250
self.assertTrue(xval.is_error_string())
251251
self.assertEqual(xval.get_value(), 'error') # doesn't raise exception.
252252

0 commit comments

Comments
 (0)