backtrader.utils.py3 module¶
Python 3 Compatibility Module.
This module provides common type aliases and utility functions used throughout the backtrader framework. Originally a Python 2/3 shim, now simplified to Python 3 only.
- Exports:
string_types: Tuple of string types —
(str,). integer_types: Tuple of integer types —(int,). MAXINT / MININT / MAXFLOAT / MINFLOAT: Numeric limits. range, zip, map, filter: Built-in references (kept for import compat). queue:import queue. cmp, bytes, bstr: Helper functions. iterkeys, itervalues, iteritems, keys, values, items: Dict helpers. urlquote, urlopen, ProxyHandler, build_opener, install_opener: URL helpers. winreg: Windows registry module (None on non-Windows). with_metaclass: Metaclass helper.
- backtrader.utils.py3.urlquote(s, *args, **kwargs)[源代码]¶
Quote a string for use in a URL.
- 参数:
s -- The string to quote.
*args -- Additional positional arguments passed to urllib.parse.quote.
**kwargs -- Additional keyword arguments passed to urllib.parse.quote.
- 返回:
The quoted string safe for use in URLs.
- backtrader.utils.py3.urlopen(*args, **kwargs)[源代码]¶
Open a URL.
- 参数:
*args -- Positional arguments passed to urllib.request.urlopen.
**kwargs -- Keyword arguments passed to urllib.request.urlopen.
- 返回:
A file-like object representing the URL response.
- backtrader.utils.py3.ProxyHandler(*args, **kwargs)[源代码]¶
Create a proxy handler for opening URLs.
- 参数:
*args -- Positional arguments passed to urllib.request.ProxyHandler.
**kwargs -- Keyword arguments passed to urllib.request.ProxyHandler.
- 返回:
A ProxyHandler instance for configuring URL proxies.
- backtrader.utils.py3.build_opener(*args, **kwargs)[源代码]¶
Build a URL opener with a chain of handlers.
- 参数:
*args -- Positional arguments passed to urllib.request.build_opener.
**kwargs -- Keyword arguments passed to urllib.request.build_opener.
- 返回:
An OpenerDirector instance configured with the specified handlers.
- backtrader.utils.py3.install_opener(*args, **kwargs)[源代码]¶
Install an opener as the default global opener.
- 参数:
*args -- Positional arguments passed to urllib.request.install_opener.
**kwargs -- Keyword arguments passed to urllib.request.install_opener.
- 返回:
None.
- backtrader.utils.py3.cmp(a, b)[源代码]¶
Compare two values.
- 参数:
a -- First value to compare.
b -- Second value to compare.
- 返回:
1 if a > b, 0 if a == b, -1 if a < b.
- 返回类型:
- backtrader.utils.py3.bytes(x)[源代码]¶
Encode a string to bytes using UTF-8 encoding.
- 参数:
x -- String to encode.
- 返回:
Bytes representation of the input string.
- backtrader.utils.py3.bstr(x)[源代码]¶
Convert a value to a byte string.
- 参数:
x -- Value to convert.
- 返回:
String representation of the input value.
- backtrader.utils.py3.iterkeys(d)[源代码]¶
Return an iterator over the dictionary's keys.
- 参数:
d -- Dictionary to iterate over.
- 返回:
An iterator over the dictionary's keys.
- backtrader.utils.py3.itervalues(d)[源代码]¶
Return an iterator over the dictionary's values.
- 参数:
d -- Dictionary to iterate over.
- 返回:
An iterator over the dictionary's values.
- backtrader.utils.py3.iteritems(d)[源代码]¶
Return an iterator over the dictionary's items.
- 参数:
d -- Dictionary to iterate over.
- 返回:
An iterator over (key, value) tuples.
- backtrader.utils.py3.keys(d)[源代码]¶
Return a list of the dictionary's keys.
- 参数:
d -- Dictionary to extract keys from.
- 返回:
A list containing the dictionary's keys.
- backtrader.utils.py3.values(d)[源代码]¶
Return a list of the dictionary's values.
- 参数:
d -- Dictionary to extract values from.
- 返回:
A list containing the dictionary's values.
- backtrader.utils.py3.items(d)[源代码]¶
Return a list of the dictionary's items.
- 参数:
d -- Dictionary to extract items from.
- 返回:
A list of (key, value) tuples.
- backtrader.utils.py3.with_metaclass(meta, *bases)[源代码]¶
Create a base class with a metaclass.
This function provides a compatibility layer for creating classes with metaclasses in a way that works across Python versions. Originally designed for Python 2/3 compatibility, now simplified for Python 3 only.
- 参数:
meta -- The metaclass to use for the created class.
*bases -- Base classes to inherit from.
- 返回:
A temporary base class that, when inherited from, creates a class with the specified metaclass and base classes.
备注
Modern Python 3 code can use metaclass directly in class definition:
class MyClass(metaclass=Meta):. This function is kept for backward compatibility with existing code.