Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[[None, NullNameError], ["", NullNameError], [1, TypeError], [True, TypeError]],
)
def test_exception_type(self, value, expected):
with pytest.raises(expected):
validate_sqlite_table_name(value)
[None, NullNameError],
["", NullNameError],
[1, TypeError],
[True, TypeError],
["a" * 32, InvalidLengthError],
],
)
def test_exception(self, value, expected):
with pytest.raises(expected):
validate_excel_sheet_name(value)
["", NullNameError],
["123", ValueError],
[1, TypeError],
[True, TypeError],
],
)
def test_exception_type(self, value, expected):
with pytest.raises(expected):
validate_js_var_name(value)
["", NullNameError],
["123", ValueError],
[1, TypeError],
[True, TypeError],
],
)
def test_exception_type(self, value, expected):
with pytest.raises(expected):
validate_python_var_name(value)
[[None, NullNameError], ["", NullNameError], [1, TypeError], [True, TypeError]],
)
def test_exception_type(self, value, expected):
with pytest.raises(expected):
validate_sqlite_attr_name(value)
def to_query(self):
name = self.sanitize(self._value)
need_quote = self.__RE_NEED_QUOTE.search(name) is not None
try:
validate_sqlite_attr_name(name)
except InvalidReservedNameError:
need_quote = True
except (ValidReservedNameError, NullNameError, InvalidCharError):
pass
if need_quote:
sql_name = '"{:s}"'.format(name)
elif self.__RE_NEED_BRACKET.search(name):
sql_name = "[{:s}]".format(name)
elif name == "join":
sql_name = "[{:s}]".format(name)
else:
sql_name = name
if typepy.is_not_null_string(self.__operation):
sql_name = "{:s}({:s})".format(self.__operation, sql_name)
return sql_name
def _validate_header(self, header):
try:
validate_sqlite_attr_name(header)
except (NullNameError, ReservedNameError):
pass
except InvalidCharError as e:
raise InvalidHeaderNameError(e)
def __sanitize_table_name(self):
preprocessed_table_name = self._preprocess_table_name()
try:
self._validate_table_name(preprocessed_table_name)
new_table_name = preprocessed_table_name
except InvalidTableNameError:
new_table_name = self._sanitize_table_name(
preprocessed_table_name)
self._validate_table_name(new_table_name)
except pv.NullNameError as e:
raise InvalidTableNameError(e)
return new_table_name
if is_require_remove_head:
sanitized_var_name = self._invalid_var_name_head_re.sub("", sanitized_var_name)
else:
match = self._invalid_var_name_head_re.search(sanitized_var_name)
if match is not None:
sanitized_var_name = match.end() * replacement_text + self._invalid_var_name_head_re.sub(
"", sanitized_var_name
)
try:
self._validate(sanitized_var_name)
except ReservedNameError as e:
if e.reusable_name is False:
sanitized_var_name += "_"
except NullNameError:
pass
return sanitized_var_name
def validate_table_name(name):
"""
:param str name: Table name to validate.
:raises NameValidationError: |raises_validate_table_name|
"""
try:
validate_sqlite_table_name(name)
except (InvalidCharError, InvalidReservedNameError) as e:
raise NameValidationError(e)
except NullNameError:
raise NameValidationError("table name is empty")
except ValidReservedNameError:
pass