text stringlengths 0 828 |
|---|
else: |
return func(**kwargs) |
except UsageError, e: |
parser.error(e.message) |
main.__doc__ = func.__doc__ |
main.__name__ = func.__name__ |
main.__module__ = func.__module__ |
main.__dict__ = func.__dict__.copy() |
return main" |
525,"def quote(text): |
'Handle quote characters' |
# Convert to unicode. |
if not isinstance(text, unicode): |
text = text.decode('utf-8') |
# Look for quote characters. Keep the text as is if it's already quoted. |
for qp in QUOTEPAIRS: |
if text[0] == qp[0] and text[-1] == qp[-1] and len(text) >= 2: |
return text |
# If it's not quoted, try quoting |
for qp in QUOTEPAIRS: |
if qp[1] not in text: |
return qp[0] + text + qp[1] |
#Darn |
raise ValueError(u'The value ""%s"" is not quoted and contains too many quote characters to quote' % text)" |
526,"def register_opener(suffix, opener=None): |
"""""" |
Register a callback that opens an archive with the specified *suffix*. |
The object returned by the *opener* must implement the #tarfile.Tarfile |
interface, more specifically the following methods: |
- `add(filename, arcname) -> None` |
- `getnames() -> list of str` |
- `getmember(filename) -> TarInfo` |
- `extractfile(filename) -> file obj` |
This function can be used as a decorator when *opener* is not provided. |
The opener must accept the following arguments: |
%%arglist |
file (file-like): A file-like object to read the archive data from. |
mode (str): The mode to open the file in. Valid values are |
`'w'`, `'r'` and `'a'`. |
options (dict): A dictionary with possibly additional arguments. |
"""""" |
if opener is None: |
def decorator(func): |
register_opener(suffix, func) |
return func |
return decorator |
if suffix in openers: |
raise ValueError('opener suffix {0!r} already registered'.format(suffix)) |
openers[suffix] = opener" |
527,"def get_opener(filename): |
"""""" |
Finds a matching opener that is registed with :func:`register_opener` |
and returns a tuple ``(suffix, opener)``. If there is no opener that |
can handle this filename, :class:`UnknownArchive` is raised. |
"""""" |
for suffix, opener in openers.items(): |
if filename.endswith(suffix): |
return suffix, opener |
raise UnknownArchive(filename)" |
528,"def open(filename=None, file=None, mode='r', suffix=None, options=None): |
"""""" |
Opens the archive at the specified *filename* or from the file-like |
object *file* using the appropriate opener. A specific opener can be |
specified by passing the *suffix* argument. |
# Parameters |
filename (str): A filename to open the archive from. |
file (file-like): A file-like object as source/destination. |
mode (str): The mode to open the archive in. |
suffix (str): Possible override for the *filename* suffix. Must be |
specified when *file* is passed instead of *filename*. |
options (dict): A dictionary that will be passed to the opener |
with which additional options can be specified. |
return (archive-like): An object that represents the archive and follows |
the interface of the #tarfile.TarFile class. |
"""""" |
if mode not in ('r', 'w', 'a'): |
raise ValueError(""invalid mode: {0!r}"".format(mode)) |
if suffix is None: |
suffix, opener = get_opener(filename) |
if file is not None: |
filename = None # We don't need it anymore. |
else: |
if file is not None and filename is not None: |
raise ValueError(""filename must not be set with file & suffix specified"") |
try: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.