/usr/lib/python3/dist-packages/bioblend/util/__init__.py is in python3-bioblend 0.7.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import os
from collections import namedtuple
class Bunch(object):
"""
A convenience class to allow dict keys to be represented as object fields.
The end result is that this allows a dict to be to be represented the same
as a database class, thus the two become interchangeable as a data source.
"""
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
"""
Return the contents of the dict in a printable representation
"""
return str(self.__dict__)
def _file_stream_close(self):
"""
Close the open file descriptor associated with the FileStream
object.
"""
self[1].close()
FileStream = namedtuple("FileStream", ["name", "fd"])
FileStream.close = _file_stream_close
def attach_file(path, name=None):
"""
Attach a path to a request payload object.
:type path: str
:param path: Path to file to attach to payload.
:type name: str
:param name: Name to give file, if different than actual pathname.
:rtype: object
:return: Returns an object compatible with requests post operation and
capable of being closed with a ``close()`` method.
"""
if name is None:
name = os.path.basename(path)
attachment = FileStream(name, open(path, "rb"))
return attachment
__all__ = [
'Bunch',
'attach_file',
]
|