⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 __init__.py

📁 Requirement =====================================================================================
💻 PY
📖 第 1 页 / 共 2 页
字号:
    else:        return Nonedef unchanged_required(argument):    """    Return the argument text, unchanged.    (Directive option conversion function.)    Raise ``ValueError`` if no argument is found.    """    if argument is None:        raise ValueError('argument required but none supplied')    else:        return argument  # unchanged!def unchanged(argument):    """    Return the argument text, unchanged.    (Directive option conversion function.)    No argument implies empty string ("").    """    if argument is None:        return u''    else:        return argument  # unchanged!def path(argument):    """    Return the path argument unwrapped (with newlines removed).    (Directive option conversion function.)    Raise ``ValueError`` if no argument is found.    """    if argument is None:        raise ValueError('argument required but none supplied')    else:        path = ''.join([s.strip() for s in argument.splitlines()])        return pathdef uri(argument):    """    Return the URI argument with whitespace removed.    (Directive option conversion function.)    Raise ``ValueError`` if no argument is found.    """    if argument is None:        raise ValueError('argument required but none supplied')    else:        uri = ''.join(argument.split())        return uridef nonnegative_int(argument):    """    Check for a nonnegative integer argument; raise ``ValueError`` if not.    (Directive option conversion function.)    """    value = int(argument)    if value < 0:        raise ValueError('negative value; must be positive or zero')    return valuelength_units = ['em', 'ex', 'px', 'in', 'cm', 'mm', 'pt', 'pc']def get_measure(argument, units):    """    Check for a positive argument of one of the units and return a    normalized string of the form "<value><unit>" (without space in    between).        To be called from directive option conversion functions.    """    match = re.match(r'^([0-9.]+) *(%s)$' % '|'.join(units), argument)    try:        assert match is not None        float(match.group(1))    except (AssertionError, ValueError):        raise ValueError(            'not a positive measure of one of the following units:\n%s'            % ' '.join(['"%s"' % i for i in units]))    return match.group(1) + match.group(2)def length_or_unitless(argument):    return get_measure(argument, length_units + [''])def length_or_percentage_or_unitless(argument):    return get_measure(argument, length_units + ['%', ''])def class_option(argument):    """    Convert the argument into a list of ID-compatible strings and return it.    (Directive option conversion function.)    Raise ``ValueError`` if no argument is found.    """    if argument is None:        raise ValueError('argument required but none supplied')    names = argument.split()    class_names = []    for name in names:        class_name = nodes.make_id(name)        if not class_name:            raise ValueError('cannot make "%s" into a class name' % name)        class_names.append(class_name)    return class_namesunicode_pattern = re.compile(    r'(?:0x|x|\\x|U\+?|\\u)([0-9a-f]+)$|&#x([0-9a-f]+);$', re.IGNORECASE)def unicode_code(code):    r"""    Convert a Unicode character code to a Unicode character.    (Directive option conversion function.)    Codes may be decimal numbers, hexadecimal numbers (prefixed by ``0x``,    ``x``, ``\x``, ``U+``, ``u``, or ``\u``; e.g. ``U+262E``), or XML-style    numeric character entities (e.g. ``&#x262E;``).  Other text remains as-is.    Raise ValueError for illegal Unicode code values.    """    try:        if code.isdigit():                  # decimal number            return unichr(int(code))        else:            match = unicode_pattern.match(code)            if match:                       # hex number                value = match.group(1) or match.group(2)                return unichr(int(value, 16))            else:                           # other text                return code    except OverflowError, detail:        raise ValueError('code too large (%s)' % detail)def single_char_or_unicode(argument):    """    A single character is returned as-is.  Unicode characters codes are    converted as in `unicode_code`.  (Directive option conversion function.)    """    char = unicode_code(argument)    if len(char) > 1:        raise ValueError('%r invalid; must be a single character or '                         'a Unicode code' % char)    return chardef single_char_or_whitespace_or_unicode(argument):    """    As with `single_char_or_unicode`, but "tab" and "space" are also supported.    (Directive option conversion function.)    """    if argument == 'tab':        char = '\t'    elif argument == 'space':        char = ' '    else:        char = single_char_or_unicode(argument)    return chardef positive_int(argument):    """    Converts the argument into an integer.  Raises ValueError for negative,    zero, or non-integer values.  (Directive option conversion function.)    """    value = int(argument)    if value < 1:        raise ValueError('negative or zero value; must be positive')    return valuedef positive_int_list(argument):    """    Converts a space- or comma-separated list of values into a Python list    of integers.    (Directive option conversion function.)    Raises ValueError for non-positive-integer values.    """    if ',' in argument:        entries = argument.split(',')    else:        entries = argument.split()    return [positive_int(entry) for entry in entries]def encoding(argument):    """    Verfies the encoding argument by lookup.    (Directive option conversion function.)    Raises ValueError for unknown encodings.    """    try:        codecs.lookup(argument)    except LookupError:        raise ValueError('unknown encoding: "%s"' % argument)    return argumentdef choice(argument, values):    """    Directive option utility function, supplied to enable options whose    argument must be a member of a finite set of possible values (must be    lower case).  A custom conversion function must be written to use it.  For    example::        from docutils.parsers.rst import directives        def yesno(argument):            return directives.choice(argument, ('yes', 'no'))    Raise ``ValueError`` if no argument is found or if the argument's value is    not valid (not an entry in the supplied list).    """    try:        value = argument.lower().strip()    except AttributeError:        raise ValueError('must supply an argument; choose from %s'                         % format_values(values))    if value in values:        return value    else:        raise ValueError('"%s" unknown; choose from %s'                         % (argument, format_values(values)))def format_values(values):    return '%s, or "%s"' % (', '.join(['"%s"' % s for s in values[:-1]]),                            values[-1])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -