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


Python reprlib.Repr方法代碼示例

本文整理匯總了Python中reprlib.Repr方法的典型用法代碼示例。如果您正苦於以下問題:Python reprlib.Repr方法的具體用法?Python reprlib.Repr怎麽用?Python reprlib.Repr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在reprlib的用法示例。


在下文中一共展示了reprlib.Repr方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def __init__(self: object, backoff: object, verbose: bool = False):
        """
        Setup for SequentialBackoffLemmatizer
        :param backoff: Next lemmatizer in backoff chain
        :type verbose: bool
        :param verbose: Flag to include which lemmatizer assigned in
            a given tag in the return tuple
        """
        SequentialBackoffTagger.__init__(self, backoff=None)

        # Setup backoff chain
        if backoff is None:
            self._taggers = [self]
        else:
            self._taggers = [self] + backoff._taggers

        self.VERBOSE = verbose
        self.repr = reprlib.Repr()
        self.repr.maxlist = 1
        self.repr.maxdict = 1 
開發者ID:cltk,項目名稱:cltk,代碼行數:22,代碼來源:backoff.py

示例2: __init__

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def __init__(self: object, backoff: object, verbose: bool = False):
        """
        Setup for SequentialBackoffLemmatizer

        :param backoff: Next lemmatizer in backoff chain
        :param verbose: Flag to include which lemmatizer assigned in a given tag in the return tuple
        """
        SequentialBackoffTagger.__init__(self, backoff=None)
        # Setup backoff chain
        if backoff is None:
            self._taggers = [self]
        else:
            self._taggers = [self] + backoff._taggers

        self.VERBOSE = verbose
        self.repr = reprlib.Repr()
        self.repr.maxlist = 1
        self.repr.maxdict = 1 
開發者ID:cltk,項目名稱:cltk,代碼行數:20,代碼來源:ensemble.py

示例3: test_repr

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def test_repr(self) -> None:
        a_repr = reprlib.Repr()
        a_repr.maxlist = 3

        @icontract.require(lambda x: len(x) < 10, a_repr=a_repr)
        def some_func(x: List[int]) -> None:
            pass

        violation_error = None  # type: Optional[icontract.ViolationError]
        try:
            some_func(x=list(range(10 * 1000)))
        except icontract.ViolationError as err:
            violation_error = err

        self.assertIsNotNone(violation_error)
        self.assertEqual("len(x) < 10:\n"
                         "len(x) was 10000\n"
                         "x was [0, 1, 2, ...]", tests.error.wo_mandatory_location(str(violation_error))) 
開發者ID:Parquery,項目名稱:icontract,代碼行數:20,代碼來源:test_represent.py

示例4: repr

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def repr(self, x):
        return self._callhelper(reprlib.Repr.repr, self, x) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:4,代碼來源:saferepr.py

示例5: saferepr

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def saferepr(obj, maxsize=240):
    """return a size-limited safe repr-string for the given object.
    Failing __repr__ functions of user instances will be represented
    with a short exception info and 'saferepr' generally takes
    care to never raise exceptions itself.  This function is a wrapper
    around the Repr/reprlib functionality of the standard 2.6 lib.
    """
    # review exception handling
    srepr = SafeRepr()
    srepr.maxstring = maxsize
    srepr.maxsize = maxsize
    srepr.maxother = 160
    return srepr.repr(obj) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:15,代碼來源:saferepr.py

示例6: saferepr

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def saferepr(obj: object, maxsize: int = 240) -> str:
    """return a size-limited safe repr-string for the given object.
    Failing __repr__ functions of user instances will be represented
    with a short exception info and 'saferepr' generally takes
    care to never raise exceptions itself.  This function is a wrapper
    around the Repr/reprlib functionality of the standard 2.6 lib.
    """
    return SafeRepr(maxsize).repr(obj) 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:10,代碼來源:saferepr.py

示例7: __init__

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def __init__(self, master, title, dict=None):
        width = 0
        height = 40
        if dict:
            height = 20*len(dict) # XXX 20 == observed height of Entry widget
        self.master = master
        self.title = title
        import reprlib
        self.repr = reprlib.Repr()
        self.repr.maxstring = 60
        self.repr.maxother = 60
        self.frame = frame = Frame(master)
        self.frame.pack(expand=1, fill="both")
        self.label = Label(frame, text=title, borderwidth=2, relief="groove")
        self.label.pack(fill="x")
        self.vbar = vbar = Scrollbar(frame, name="vbar")
        vbar.pack(side="right", fill="y")
        self.canvas = canvas = Canvas(frame,
                                      height=min(300, max(40, height)),
                                      scrollregion=(0, 0, width, height))
        canvas.pack(side="left", fill="both", expand=1)
        vbar["command"] = canvas.yview
        canvas["yscrollcommand"] = vbar.set
        self.subframe = subframe = Frame(canvas)
        self.sfid = canvas.create_window(0, 0, window=subframe, anchor="nw")
        self.load_dict(dict) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:28,代碼來源:Debugger.py

示例8: __repr__

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def __repr__(self):
        reprer = reprlib.Repr()
        reprer.maxstring = 100
        reprer.maxother = 100
        meshes_names = reprer.repr(self._meshes)
        if self.name is not None:
            return f"{self.__class__.__name__}({meshes_names}, name={self.name})"
        else:
            return f"{self.__class__.__name__}{meshes_names}" 
開發者ID:mancellin,項目名稱:capytaine,代碼行數:11,代碼來源:collections.py

示例9: __repr__

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def __repr__(self):
        reprer = reprlib.Repr()
        reprer.maxstring = 90
        reprer.maxother = 90
        slice_name = reprer.repr(self._meshes[0])
        if self.name is not None:
            return f"{self.__class__.__name__}({slice_name}, name={self.name})"
        else:
            return f"{self.__class__.__name__}({slice_name})" 
開發者ID:mancellin,項目名稱:capytaine,代碼行數:11,代碼來源:symmetric.py

示例10: __init__

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def __init__(self,
                 condition: Callable[..., Any],
                 description: Optional[str] = None,
                 a_repr: reprlib.Repr = icontract._globals.aRepr,
                 enabled: bool = __debug__,
                 error: Optional[Union[Callable[..., Exception], type]] = None) -> None:
        """
        Initialize.

        :param condition: precondition predicate
        :param description: textual description of the precondition
        :param a_repr: representation instance that defines how the values are represented
        :param enabled:
            The decorator is applied only if this argument is set.

            Otherwise, the condition check is disabled and there is no run-time overhead.

            The default is to always check the condition unless the interpreter runs in optimized mode (``-O`` or
            ``-OO``).
        :param error:
            if given as a callable, ``error`` is expected to accept a subset of function arguments
            (*e.g.*, also including ``result`` for perconditions, only ``self`` for invariants *etc.*) and return
            an exception. The ``error`` is called on contract violation and the resulting exception is raised.

            Otherwise, it is expected to denote an Exception class which is instantiated with the violation message
            and raised on contract violation.

        """
        # pylint: disable=too-many-arguments
        self.enabled = enabled
        self._contract = None  # type: Optional[Contract]

        if not enabled:
            return

        location = None  # type: Optional[str]
        tb_stack = traceback.extract_stack(limit=2)[:1]
        if len(tb_stack) > 0:
            frame = tb_stack[0]
            location = 'File {}, line {} in {}'.format(frame.filename, frame.lineno, frame.name)

        self._contract = Contract(
            condition=condition, description=description, a_repr=a_repr, error=error, location=location) 
開發者ID:Parquery,項目名稱:icontract,代碼行數:45,代碼來源:_decorators.py

示例11: __init__

# 需要導入模塊: import reprlib [as 別名]
# 或者: from reprlib import Repr [as 別名]
def __init__(self,
                 condition: Callable[..., bool],
                 description: Optional[str] = None,
                 a_repr: reprlib.Repr = icontract._globals.aRepr,
                 error: Optional[Union[Callable[..., Exception], type]] = None,
                 location: Optional[str] = None) -> None:
        """
        Initialize.

        :param condition: condition predicate
        :param description: textual description of the contract
        :param a_repr: representation instance that defines how the values are represented
        :param error:
            if given as a callable, ``error`` is expected to accept a subset of function arguments
            (*e.g.*, also including ``result`` for perconditions, only ``self`` for invariants *etc.*) and return
            an exception. The ``error`` is called on contract violation and the resulting exception is raised.

            Otherwise, it is expected to denote an Exception class which is instantiated with the violation message
            and raised on contract violation.
        :param location: indicate where the contract was defined (*e.g.*, path and line number)
        """
        # pylint: disable=too-many-arguments
        self.condition = condition

        signature = inspect.signature(condition)

        # All argument names of the condition
        self.condition_args = list(signature.parameters.keys())  # type: List[str]
        self.condition_arg_set = set(self.condition_args)  # type: Set[str]

        # Names of the mandatory arguments of the condition
        self.mandatory_args = [
            name for name, param in signature.parameters.items() if param.default == inspect.Parameter.empty
        ]

        self.description = description
        self._a_repr = a_repr

        self.error = error
        self.error_args = None  # type: Optional[List[str]]
        self.error_arg_set = None  # type: Optional[Set[str]]
        if error is not None and (inspect.isfunction(error) or inspect.ismethod(error)):
            self.error_args = list(inspect.signature(error).parameters.keys())
            self.error_arg_set = set(self.error_args)

        self.location = location 
開發者ID:Parquery,項目名稱:icontract,代碼行數:48,代碼來源:_types.py


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