https://github.com/lazka/giofile
Opens a Gio.File as a Python file object
https://github.com/lazka/giofile
gio pygobject python
Last synced: 12 months ago
JSON representation
Opens a Gio.File as a Python file object
- Host: GitHub
- URL: https://github.com/lazka/giofile
- Owner: lazka
- License: mit
- Created: 2017-08-05T08:18:05.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-15T09:32:54.000Z (over 8 years ago)
- Last Synced: 2025-03-30T18:23:43.516Z (about 1 year ago)
- Topics: gio, pygobject, python
- Language: Python
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
*******
giofile
*******
Opens a Gio.File as a Python file object
.. code:: python
def open(file, mode="r", buffering=-1, encoding=None, errors=None,
newline=None, cancellable=None):
"""
Like io.open() but takes a Gio.File instead of a filename.
The only modes supported are r/rw/rb/r+b
Takes a cancellable kwarg for passing a Gio.Cancellable().
Cancelling it will abort any ongoing blocking operation.
Returns a io.IOBase instance.
"""
.. image:: https://travis-ci.org/lazka/giofile.svg?branch=master
:target: https://travis-ci.org/lazka/giofile
Installation
============
::
pip install giofile
Example
=======
.. code:: python
import mutagen
import giofile
from gi.repository import Gio
gio_file = Gio.File.new_for_uri(
"http://people.xiph.org/~giles/2012/opus/ehren-paper_lights-96.opus")
cancellable = Gio.Cancellable.new()
with giofile.open(gio_file, "rb", cancellable=cancellable) as gfile:
print(mutagen.File(gfile).pprint())
.. code:: sh
$ python example.py
Ogg Opus, 228.11 seconds (audio/ogg)
ENCODER=opusenc from opus-tools 0.1.5
artist=Ehren Starks
title=Paper Lights
album=Lines Build Walls
date=2005-09-05
copyright=Copyright 2005 Ehren Starks
license=http://creativecommons.org/licenses/by-nc-sa/1.0/
organization=magnatune.com