Example #1
0
def _parse_filter(
    arg: str, *, escape: bool
) -> "Tuple[str, str, Type[Warning], str, int]":
    """Parse a warnings filter string.

    This is copied from warnings._setoption, but does not apply the filter,
    only parses it, and makes the escaping optional.
    """
    parts = arg.split(":")
    if len(parts) > 5:
        raise warnings._OptionError("too many fields (max 5): {!r}".format(arg))
    while len(parts) < 5:
        parts.append("")
    action_, message, category_, module, lineno_ = [s.strip() for s in parts]
    action = warnings._getaction(action_)  # type: str # type: ignore[attr-defined]
    category = warnings._getcategory(
        category_
    )  # type: Type[Warning] # type: ignore[attr-defined]
    if message and escape:
        message = re.escape(message)
    if module and escape:
        module = re.escape(module) + r"\Z"
    if lineno_:
        try:
            lineno = int(lineno_)
            if lineno < 0:
                raise ValueError
        except (ValueError, OverflowError) as e:
            raise warnings._OptionError("invalid lineno {!r}".format(lineno_)) from e
    else:
        lineno = 0
    return (action, message, category, module, lineno)
Example #2
0
from uuid import UUID
import dateutil.parser
import requests
from requests.auth import AuthBase
from requests.models import Request
import warnings
from .oauth_client import NexaasIDOAuthClient
from .oauth_token import OAuthToken
from .exceptions import SignedOutException

__all__ = ['NexaasIDClient']

try:
    DeprecationWarning = warnings.DeprecationWarning
except AttributeError:
    DeprecationWarning = warnings._getcategory('DeprecationWarning')

ClientProps = namedtuple('ClientProps', 'token id secret server')


class NexaasIDClient:
    __slots__ = (
        '__internal_tuple',
        '_personal_info',
        '_professional_info',
        '_emails',
        '_contacts',
    )

    @classmethod
    def from_oauth(cls, token: OAuthToken, *,
Example #3
0
    'COLCON_WARNINGS',
    'Set the warnings filter similar to PYTHONWARNINGS except that the module '
    "entry is implicitly set to 'colcon.*'")

warnings_filters = os.environ.get(WARNINGS_ENVIRONMENT_VARIABLE.name)
if warnings_filters:
    import warnings
    # filters are separated by commas
    for f in warnings_filters.split(','):
        # fields are separated by colons
        fields = f.split(':', 4)
        if len(fields) < 5:
            fields += [''] * (5 - len(fields))
        action, message, category, module, line = fields
        try:
            category = warnings._getcategory(category)
        except Exception:
            print(
                "The category field '{category}' must be a valid warnings "
                'class name'.format_map(locals()), file=sys.stderr)
            sys.exit(1)
        if module:
            print(
                'The module field of the {WARNINGS_ENVIRONMENT_VARIABLE.name} '
                'filter should be empty, otherwise use PYTHONWARNINGS instead'
                .format_map(locals()), file=sys.stderr)
            sys.exit(1)
        warnings.filterwarnings(
            action, message=message, category=category or Warning,
            module='colcon.*', lineno=line if line else 0)
Example #4
0
 def update_event(self, inp=-1):
     self.set_output_val(0, warnings._getcategory(self.input(0)))