aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/websocket-client/py3/websocket/_utils.py
diff options
context:
space:
mode:
authorAlexSm <alex@ydb.tech>2023-12-21 15:05:38 +0100
committerGitHub <noreply@github.com>2023-12-21 15:05:38 +0100
commite98bcbc74422492351c51646dba3849a138a8ffc (patch)
tree38ad7a09b1f9c201ce8a7e3d69f2017388769224 /contrib/python/websocket-client/py3/websocket/_utils.py
parent559d7083cd8378cb25b9e966dedcca21d413e338 (diff)
downloadydb-e98bcbc74422492351c51646dba3849a138a8ffc.tar.gz
Import libs 1 (#590)
* Import libs 1 * Add new file without extension * Add file missed in export config
Diffstat (limited to 'contrib/python/websocket-client/py3/websocket/_utils.py')
-rw-r--r--contrib/python/websocket-client/py3/websocket/_utils.py395
1 files changed, 374 insertions, 21 deletions
diff --git a/contrib/python/websocket-client/py3/websocket/_utils.py b/contrib/python/websocket-client/py3/websocket/_utils.py
index 62ba0b01b8..c63adfa593 100644
--- a/contrib/python/websocket-client/py3/websocket/_utils.py
+++ b/contrib/python/websocket-client/py3/websocket/_utils.py
@@ -22,7 +22,6 @@ __all__ = ["NoLock", "validate_utf8", "extract_err_message", "extract_error_code
class NoLock:
-
def __enter__(self) -> None:
pass
@@ -35,8 +34,9 @@ try:
# strings.
from wsaccel.utf8validator import Utf8Validator
- def _validate_utf8(utfbytes: bytes) -> bool:
- return Utf8Validator().validate(utfbytes)[0]
+ def _validate_utf8(utfbytes: Union[str, bytes]) -> bool:
+ result: bool = Utf8Validator().validate(utfbytes)[0]
+ return result
except ImportError:
# UTF-8 validator
@@ -48,28 +48,380 @@ except ImportError:
_UTF8D = [
# The first part of the table maps bytes to character classes that
# to reduce the size of the transition table and create bitmasks.
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,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,12, 12,24,12,12,12,12,12,24,12,24,12,12,
- 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
- 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
- 12,36,12,12,12,12,12,12,12,12,12,12, ]
+ 0,
+ 12,
+ 24,
+ 36,
+ 60,
+ 96,
+ 84,
+ 12,
+ 12,
+ 12,
+ 48,
+ 72,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 0,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 0,
+ 12,
+ 0,
+ 12,
+ 12,
+ 12,
+ 24,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 24,
+ 12,
+ 24,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 24,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 24,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 24,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 36,
+ 12,
+ 36,
+ 12,
+ 12,
+ 12,
+ 36,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 36,
+ 12,
+ 36,
+ 12,
+ 12,
+ 12,
+ 36,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ 12,
+ ]
def _decode(state: int, codep: int, ch: int) -> tuple:
tp = _UTF8D[ch]
- codep = (ch & 0x3f) | (codep << 6) if (
- state != _UTF8_ACCEPT) else (0xff >> tp) & ch
+ codep = (
+ (ch & 0x3F) | (codep << 6) if (state != _UTF8_ACCEPT) else (0xFF >> tp) & ch
+ )
state = _UTF8D[256 + state + tp]
return state, codep
@@ -78,7 +430,7 @@ except ImportError:
state = _UTF8_ACCEPT
codep = 0
for i in utfbytes:
- state, codep = _decode(state, codep, i)
+ state, codep = _decode(state, codep, int(i))
if state == _UTF8_REJECT:
return False
@@ -96,7 +448,8 @@ def validate_utf8(utfbytes: Union[str, bytes]) -> bool:
def extract_err_message(exception: Exception) -> Union[str, None]:
if exception.args:
- return exception.args[0]
+ exception_message: str = exception.args[0]
+ return exception_message
else:
return None