Ejemplo n.º 1
0
def detect_format(stream):
    """Return format name of given stream."""
    for fmt in registry.formats():
        try:
            if fmt.detect(stream):
                return fmt.title
        except AttributeError:
            pass
Ejemplo n.º 2
0
def detect_format(stream):
    """Return format name of given stream (file-like object, string, or bytestring)."""
    stream = normalize_input(stream)
    fmt_title = None
    for fmt in registry.formats():
        try:
            if fmt.detect(stream):
                fmt_title = fmt.title
                break
        except AttributeError:
            pass
        finally:
            if hasattr(stream, 'seek'):
                stream.seek(0)
    return fmt_title