本文整理汇总了Python中typepy.TypeConversionError方法的典型用法代码示例。如果您正苦于以下问题:Python typepy.TypeConversionError方法的具体用法?Python typepy.TypeConversionError怎么用?Python typepy.TypeConversionError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typepy
的用法示例。
在下文中一共展示了typepy.TypeConversionError方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exeute
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def exeute(self, method, value):
str_convert_type = (
six.text_type, ipaddress.IPv4Address, ipaddress.IPv6Address)
try:
result = getattr(
self.typeclass(value, self.strict_level), method)()
if method == "validate":
result = "NOP [#f1]_"
elif isinstance(result, str_convert_type):
result = '``"{}"``'.format(result)
except TypeError:
result = "E [#f2]_"
except typepy.TypeConversionError:
result = "E [#f3]_"
return result
示例2: get_integer_digit
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def get_integer_digit(value):
from typepy import TypeConversionError
from typepy.type import RealNumber
float_type = RealNumber(value)
try:
abs_value = abs(float_type.convert())
except TypeConversionError:
raise ValueError(
"the value must be a number: value='{}' type='{}'".format(
value, type(value)))
if abs_value.is_zero():
return 1
try:
return len(str(abs_value.quantize(
Decimal("1."), rounding=decimal.ROUND_DOWN)))
except decimal.InvalidOperation as e:
raise ValueError(e)
示例3: __get_deadline_option
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def __get_deadline_option(self):
try:
deadline = Integer(self.deadline).convert()
except typepy.TypeConversionError:
if self.count:
return ""
deadline = DEFAULT_DEADLINE
if self.__is_windows():
# ping for Windows not have the option with equals to the deadline
# option.
return "-n {:d}".format(deadline)
elif self.__is_osx():
return "-t {:d}".format(deadline)
return "-w {:d}".format(deadline)
示例4: convert_wrapper
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def convert_wrapper(typeobj, method):
try:
return getattr(typeobj, method)()
except (typepy.TypeConversionError):
return EXCEPTION_RESULT
示例5: __modify_item
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def __modify_item(data):
try:
return typepy.type.Integer(data).convert()
except typepy.TypeConversionError:
pass
try:
return typepy.type.RealNumber(data).convert()
except typepy.TypeConversionError:
pass
return MultiByteStrDecoder(data).unicode_str
示例6: set_start_datetime
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def set_start_datetime(self, value, timezone=None):
"""
Set the start time of the time range.
:param value: |param_start_datetime|
:type value: |datetime|/|str|
:raises ValueError: If the value is invalid as a |datetime| value.
:Sample Code:
.. code:: python
from datetimerange import DateTimeRange
time_range = DateTimeRange()
print time_range
time_range.set_start_datetime("2015-03-22T10:00:00+0900")
print time_range
:Output:
.. parsed-literal::
NaT - NaT
2015-03-22T10:00:00+0900 - NaT
"""
if value is None:
self.__start_datetime = None
return
try:
self.__start_datetime = typepy.type.DateTime(
value,
strict_level=typepy.StrictLevel.MIN,
timezone=timezone
).convert()
except typepy.TypeConversionError as e:
raise ValueError(e)
示例7: set_end_datetime
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def set_end_datetime(self, value, timezone=None):
"""
Set the end time of the time range.
:param datetime.datetime/str value: |param_end_datetime|
:raises ValueError: If the value is invalid as a |datetime| value.
:Sample Code:
.. code:: python
from datetimerange import DateTimeRange
time_range = DateTimeRange()
print time_range
time_range.set_end_datetime("2015-03-22T10:10:00+0900")
print time_range
:Output:
.. parsed-literal::
NaT - NaT
NaT - 2015-03-22T10:10:00+0900
"""
if value is None:
self.__end_datetime = None
return
try:
self.__end_datetime = typepy.type.DateTime(
value,
strict_level=typepy.StrictLevel.MIN,
timezone=timezone
).convert()
except typepy.TypeConversionError as e:
raise ValueError(e)
示例8: __get_unique_qdisc_minor_id
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def __get_unique_qdisc_minor_id(self):
if (self._tc_obj.tc_command_output != TcCommandOutput.NOT_SET or
self._tc_obj.is_change_shaping_rule):
self.__qdisc_minor_id_count += 1
return self.__DEFAULT_CLASS_MINOR_ID + self.__qdisc_minor_id_count
exist_class_item_list = re.findall(
"class {algorithm:s} {qdisc_major_id:s}[\:][0-9]+".format(
algorithm=ShapingAlgorithm.HTB,
qdisc_major_id=self._tc_obj.qdisc_major_id_str),
run_tc_show(Tc.Subcommand.CLASS, self._tc_device),
re.MULTILINE)
exist_class_minor_id_list = []
for class_item in exist_class_item_list:
try:
exist_class_minor_id_list.append(
typepy.type.Integer(class_item.split(":")[1]).convert())
except typepy.TypeConversionError:
continue
logger.debug("existing class list with {:s}: {}".format(
self._dev, exist_class_item_list))
logger.debug("existing minor classid list with {:s}: {}".format(
self._dev, exist_class_minor_id_list))
next_minor_id = self.__DEFAULT_CLASS_MINOR_ID
while True:
if next_minor_id not in exist_class_minor_id_list:
break
next_minor_id += 1
return next_minor_id
示例9: __validate_deadline
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def __validate_deadline(self):
if self.deadline is None:
return
try:
deadline = Integer(self.deadline).convert()
except typepy.TypeConversionError:
raise ValueError("deadline must be an integer: actual={}".format(
self.deadline))
if deadline <= 0:
raise ValueError(
"deadline must be greater than zero: actual={}".format(
self.deadline))
示例10: __validate_count
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def __validate_count(self):
if self.count is None:
return
try:
count = Integer(self.count).convert()
except typepy.TypeConversionError:
raise ValueError("count must be an integer: actual={}".format(
self.count))
if count <= 0:
raise ValueError("count must be greater than zero")
示例11: __get_count_option
# 需要导入模块: import typepy [as 别名]
# 或者: from typepy import TypeConversionError [as 别名]
def __get_count_option(self):
try:
count = Integer(self.count).convert()
except typepy.TypeConversionError:
return ""
if self.__is_windows():
return "-n {:d}".format(count)
return "-c {:d}".format(count)