validation.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:Main 作者: N-BodyPhysicsSimulator 项目源码 文件源码
def int_is_valid_port(port: int) -> int:
    """
    >>> int_is_valid_port(4092)
    4092

    >>> int_is_valid_port(80)
    Traceback (most recent call last):
    argparse.ArgumentTypeError: Privileged port used.

    >>> int_is_valid_port(9999999)
    Traceback (most recent call last):
    argparse.ArgumentTypeError: Port outside port range.

    >>> int_is_valid_port(-4092)
    Traceback (most recent call last):
    argparse.ArgumentTypeError: Port outside port range.
    """
    port = int(port)

    if port in range(1, 1024):
        raise ArgumentTypeError("Privileged port used.")
    elif not port in range(1024, 2 ** 16):
        raise ArgumentTypeError("Port outside port range.")
    else:
        return int_is_open_port(port)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号