當前位置: 首頁>>代碼示例>>Python>>正文


Python typepy.TypeConversionError方法代碼示例

本文整理匯總了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 
開發者ID:thombashi,項目名稱:typepy,代碼行數:20,代碼來源:make_result_matrix.py

示例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) 
開發者ID:thombashi,項目名稱:DataProperty,代碼行數:23,代碼來源:_function.py

示例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) 
開發者ID:thombashi,項目名稱:pingparsing,代碼行數:19,代碼來源:_pingtransmitter.py

示例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 
開發者ID:thombashi,項目名稱:typepy,代碼行數:7,代碼來源:_common.py

示例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 
開發者ID:thombashi,項目名稱:pytablereader,代碼行數:14,代碼來源:core.py

示例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) 
開發者ID:thombashi,項目名稱:DateTimeRange,代碼行數:37,代碼來源:__init__.py

示例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) 
開發者ID:thombashi,項目名稱:DateTimeRange,代碼行數:36,代碼來源:__init__.py

示例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 
開發者ID:thombashi,項目名稱:tcconfig,代碼行數:37,代碼來源:htb.py

示例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)) 
開發者ID:thombashi,項目名稱:pingparsing,代碼行數:16,代碼來源:_pingtransmitter.py

示例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") 
開發者ID:thombashi,項目名稱:pingparsing,代碼行數:14,代碼來源:_pingtransmitter.py

示例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) 
開發者ID:thombashi,項目名稱:pingparsing,代碼行數:12,代碼來源:_pingtransmitter.py


注:本文中的typepy.TypeConversionError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。