Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Classes | Functions | Variables
babel.util Namespace Reference

Classes

class  FixedOffsetTimezone
 
class  TextWrapper
 

Functions

Generator[_T, None, None] distinct (Iterable[_T] iterable)
 
str|None parse_encoding (IO[bytes] fp)
 
int parse_future_flags (IO[bytes] fp, str encoding='latin-1')
 
bool pathmatch (str pattern, str filename)
 
list[str] wraptext (str text, int width=70, str initial_indent='', str subsequent_indent='')
 
 _cmp (Any a, Any b)
 

Variables

 missing = object()
 
 _T = TypeVar("_T")
 
 PYTHON_MAGIC_COMMENT_re
 
 PYTHON_FUTURE_IMPORT_re
 
 odict = dict
 
 UTC = dates.UTC
 
 LOCALTZ = dates.LOCALTZ
 
 get_localzone = localtime.get_localzone
 
 STDOFFSET = localtime.STDOFFSET
 
 DSTOFFSET = localtime.DSTOFFSET
 
 DSTDIFF = localtime.DSTDIFF
 
 ZERO = localtime.ZERO
 

Detailed Description

    babel.util
    ~~~~~~~~~~

    Various utility classes and functions.

    :copyright: (c) 2013-2025 by the Babel Team.
    :license: BSD, see LICENSE for more details.

Function Documentation

◆ distinct()

Generator[_T, None, None] babel.util.distinct ( Iterable[_T]  iterable)
Yield all items in an iterable collection that are distinct.

Unlike when using sets for a similar effect, the original ordering of the
items in the collection is preserved by this function.

>>> print(list(distinct([1, 2, 1, 3, 4, 4])))
[1, 2, 3, 4]
>>> print(list(distinct('foobar')))
['f', 'o', 'b', 'a', 'r']

:param iterable: the iterable collection providing the data

◆ parse_encoding()

str | None babel.util.parse_encoding ( IO[bytes]  fp)
Deduce the encoding of a source file from magic comment.

It does this in the same way as the `Python interpreter`__

.. __: https://docs.python.org/3.4/reference/lexical_analysis.html#encoding-declarations

The ``fp`` argument should be a seekable file object.

(From Jeff Dairiki)

◆ parse_future_flags()

int babel.util.parse_future_flags ( IO[bytes]  fp,
str   encoding = 'latin-1' 
)
Parse the compiler flags by :mod:`__future__` from the given Python
code.

◆ pathmatch()

bool babel.util.pathmatch ( str  pattern,
str  filename 
)
Extended pathname pattern matching.

This function is similar to what is provided by the ``fnmatch`` module in
the Python standard library, but:

 * can match complete (relative or absolute) path names, and not just file
   names, and
 * also supports a convenience pattern ("**") to match files at any
   directory level.

Examples:

>>> pathmatch('**.py', 'bar.py')
True
>>> pathmatch('**.py', 'foo/bar/baz.py')
True
>>> pathmatch('**.py', 'templates/index.html')
False

>>> pathmatch('./foo/**.py', 'foo/bar/baz.py')
True
>>> pathmatch('./foo/**.py', 'bar/baz.py')
False

>>> pathmatch('^foo/**.py', 'foo/bar/baz.py')
True
>>> pathmatch('^foo/**.py', 'bar/baz.py')
False

>>> pathmatch('**/templates/*.html', 'templates/index.html')
True
>>> pathmatch('**/templates/*.html', 'templates/foo/bar.html')
False

:param pattern: the glob pattern
:param filename: the path name of the file to match against

◆ wraptext()

list[str] babel.util.wraptext ( str  text,
int   width = 70,
str   initial_indent = '',
str   subsequent_indent = '' 
)
Simple wrapper around the ``textwrap.wrap`` function in the standard
library. This version does not wrap lines on hyphens in words. It also
does not wrap PO file locations containing spaces.

:param text: the text to wrap
:param width: the maximum line width
:param initial_indent: string that will be prepended to the first line of
                       wrapped output
:param subsequent_indent: string that will be prepended to all lines save
                          the first of wrapped output

Variable Documentation

◆ PYTHON_FUTURE_IMPORT_re

babel.util.PYTHON_FUTURE_IMPORT_re
Initial value:
1= re.compile(
2 r'from\s+__future__\s+import\s+\‍(*(.+)\‍)*')

◆ PYTHON_MAGIC_COMMENT_re

babel.util.PYTHON_MAGIC_COMMENT_re
Initial value:
1= re.compile(
2 br'[ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)', re.VERBOSE)