Shortcuts

HTTPBackend

class mmeval.fileio.HTTPBackend[源代码]

HTTP and HTTPS storage bachend.

get(filepath: str)bytes[源代码]

Read bytes from a given filepath.

参数

filepath (str) – Path to read data.

返回

Expected bytes object.

返回类型

bytes

实际案例

>>> backend = HTTPBackend()
>>> backend.get('http://path/of/file')
b'hello world'
get_local_path(filepath: str)Generator[Union[str, pathlib.Path], None, None][源代码]

Download a file from filepath to a local temporary directory, and return the temporary path.

get_local_path is decorated by contxtlib.contextmanager(). It can be called with with statement, and when exists from the with statement, the temporary path will be released.

参数

filepath (str) – Download a file from filepath.

生成器

Iterable[str] – Only yield one temporary path.

实际案例

>>> backend = HTTPBackend()
>>> # After existing from the ``with`` clause,
>>> # the path will be removed
>>> with backend.get_local_path('http://path/of/file') as path:
...     # do something here
get_text(filepath, encoding='utf-8')str[源代码]

Read text from a given filepath.

参数
  • filepath (str) – Path to read data.

  • encoding (str) – The encoding format used to open the filepath. Defaults to ‘utf-8’.

返回

Expected text reading from filepath.

返回类型

str

实际案例

>>> backend = HTTPBackend()
>>> backend.get_text('http://path/of/file')
'hello world'
Read the Docs v: latest
Versions
latest
stable
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.