traci.exceptions

 1# -*- coding: utf-8 -*-
 2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
 3# Copyright (C) 2008-2026 German Aerospace Center (DLR) and others.
 4# This program and the accompanying materials are made available under the
 5# terms of the Eclipse Public License 2.0 which is available at
 6# https://www.eclipse.org/legal/epl-2.0/
 7# This Source Code may also be made available under the following Secondary
 8# Licenses when the conditions for such availability set forth in the Eclipse
 9# Public License 2.0 are satisfied: GNU General Public License, version 2
10# or later which is available at
11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14# @file    exceptions.py
15# @author  Michael Behrisch
16# @author  Lena Kalleske
17# @author  Mario Krumnow
18# @author  Daniel Krajzewicz
19# @author  Jakob Erdmann
20# @date    2008-10-09
21
22from __future__ import print_function
23from __future__ import absolute_import
24import functools
25import warnings
26
27
28def deprecated(new_name=None):
29    """This is a decorator which can be used to mark functions
30    as deprecated. It will result in a warning being emitted
31    when the function is used."""
32    def Inner(func):
33        @functools.wraps(func)
34        def new_func(*args, **kwargs):
35            if new_name is None:
36                msg = "Call to deprecated function %s." % (func.__name__)
37            else:
38                msg = "Call to deprecated function %s, use %s instead." % (func.__name__, new_name)
39            warnings.warn(msg, stacklevel=2)
40            return func(*args, **kwargs)
41        return new_func
42    return Inner
43
44
45def alias_param(param, alias, deprecate=True):
46    """
47    Decorator for aliasing a param in a function
48    """
49    if isinstance(param, str):
50        subst = [(param, alias)]
51    else:
52        subst = list(zip(param, alias))
53
54    def decorator(func):
55        @functools.wraps(func)
56        def wrapper(*args, **kwargs):
57            for par, ali in subst:
58                if ali in kwargs:
59                    kwargs[par] = kwargs[ali]
60                    del kwargs[ali]
61                    if deprecate:
62                        warnings.warn("Use of deprecated parameter %s in function %s, use %s instead." %
63                                      (ali, func.__name__, par), stacklevel=2)
64            return func(*args, **kwargs)
65        return wrapper
66    return decorator
67
68
69class TraCIException(Exception):
70
71    """Exception class for all TraCI errors which keep the connection intact"""
72
73    def __init__(self, desc, command=None, errorType=None):
74        Exception.__init__(self, desc)
75        self._command = command
76        self._type = errorType
77
78    def getCommand(self):
79        return self._command
80
81    def getType(self):
82        return self._type
83
84
85class FatalTraCIError(Exception):
86
87    """Exception class for all TraCI errors which do not allow for continuation"""
88
89    def __init__(self, desc):
90        Exception.__init__(self, desc)
def deprecated(new_name=None):
29def deprecated(new_name=None):
30    """This is a decorator which can be used to mark functions
31    as deprecated. It will result in a warning being emitted
32    when the function is used."""
33    def Inner(func):
34        @functools.wraps(func)
35        def new_func(*args, **kwargs):
36            if new_name is None:
37                msg = "Call to deprecated function %s." % (func.__name__)
38            else:
39                msg = "Call to deprecated function %s, use %s instead." % (func.__name__, new_name)
40            warnings.warn(msg, stacklevel=2)
41            return func(*args, **kwargs)
42        return new_func
43    return Inner

This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.

def alias_param(param, alias, deprecate=True):
46def alias_param(param, alias, deprecate=True):
47    """
48    Decorator for aliasing a param in a function
49    """
50    if isinstance(param, str):
51        subst = [(param, alias)]
52    else:
53        subst = list(zip(param, alias))
54
55    def decorator(func):
56        @functools.wraps(func)
57        def wrapper(*args, **kwargs):
58            for par, ali in subst:
59                if ali in kwargs:
60                    kwargs[par] = kwargs[ali]
61                    del kwargs[ali]
62                    if deprecate:
63                        warnings.warn("Use of deprecated parameter %s in function %s, use %s instead." %
64                                      (ali, func.__name__, par), stacklevel=2)
65            return func(*args, **kwargs)
66        return wrapper
67    return decorator

Decorator for aliasing a param in a function

class TraCIException(builtins.Exception):
70class TraCIException(Exception):
71
72    """Exception class for all TraCI errors which keep the connection intact"""
73
74    def __init__(self, desc, command=None, errorType=None):
75        Exception.__init__(self, desc)
76        self._command = command
77        self._type = errorType
78
79    def getCommand(self):
80        return self._command
81
82    def getType(self):
83        return self._type

Exception class for all TraCI errors which keep the connection intact

TraCIException(desc, command=None, errorType=None)
74    def __init__(self, desc, command=None, errorType=None):
75        Exception.__init__(self, desc)
76        self._command = command
77        self._type = errorType
def getCommand(self):
79    def getCommand(self):
80        return self._command
def getType(self):
82    def getType(self):
83        return self._type
class FatalTraCIError(builtins.Exception):
86class FatalTraCIError(Exception):
87
88    """Exception class for all TraCI errors which do not allow for continuation"""
89
90    def __init__(self, desc):
91        Exception.__init__(self, desc)

Exception class for all TraCI errors which do not allow for continuation

FatalTraCIError(desc)
90    def __init__(self, desc):
91        Exception.__init__(self, desc)