oplus/util.py
def get_string_buffer(path_or_content, expected_extension):
    """
    path_or_content: path or content_str or content_bts or string_io or bytes_io

    Returns
    -------
    string_buffer, path

    path will be None if input was not a path
    """
    buffer, path = None, None

    # path or content string

    if isinstance(path_or_content, str):
        if path_or_content[-len(expected_extension)-1:] == ".%s" % expected_extension:
            if not os.path.isfile(path_or_content):
                raise FileNotFoundError("No file at given path: '%s'." % path_or_content)
            buffer, path = open(path_or_content, encoding=CONF.encoding), path_or_content
        else:
            buffer = io.StringIO(path_or_content, )

    # text io
    elif isinstance(path_or_content, io.TextIOBase):
        buffer = path_or_content

    # bytes
    elif isinstance(path_or_content, bytes):
        buffer = io.StringIO(path_or_content.decode(encoding=CONF.encoding))
    elif isinstance(path_or_content, io.BufferedIOBase):
        buffer = io.StringIO(path_or_content.read().decode(encoding=CONF.encoding))
    else:
        raise ValueError("path_or_content type could not be identified")

    return buffer, path
def get_string_buffer(path_or_content, expected_extension):
    """
    path_or_content: path or content_str or content_bts or string_io or bytes_io

    Returns
    -------
    string_buffer, path

    path will be None if input was not a path
    """
    buffer, path = None, None

    # path or content string

    if isinstance(path_or_content, str):
        if path_or_content[-len(expected_extension)-1:] == ".%s" % expected_extension:
            if not os.path.isfile(path_or_content):
                raise FileNotFoundError("No file at given path: '%s'." % path_or_content)
            buffer, path = open(path_or_content, encoding=CONF.encoding), path_or_content
        else:
            buffer = io.StringIO(path_or_content, )

    # text io
    elif isinstance(path_or_content, io.TextIOBase):
        buffer = path_or_content

    # bytes
    elif isinstance(path_or_content, bytes):
        buffer = io.StringIO(path_or_content.decode(encoding=CONF.encoding))
    elif isinstance(path_or_content, io.BufferedIOBase):
        buffer = io.StringIO(path_or_content.read().decode(encoding=CONF.encoding))
    else:
        raise ValueError("path_or_content type could not be identified")

    return buffer, path
def get_string_buffer ( path_or_content , expected_extension ) : buffer , path = None , None # path or content string if isinstance ( path_or_content , str ) : if path_or_content [ - len ( expected_extension ) - 1 : ] == ".%s" % expected_extension : if not os . path . isfile ( path_or_content ) : raise FileNotFoundError ( "No file at given path: '%s'." % path_or_content ) buffer , path = open ( path_or_content , encoding = CONF . encoding ) , path_or_content else : buffer = io . StringIO ( path_or_content , ) # text io elif isinstance ( path_or_content , io . TextIOBase ) : buffer = path_or_content # bytes elif isinstance ( path_or_content , bytes ) : buffer = io . StringIO ( path_or_content . decode ( encoding = CONF . encoding ) ) elif isinstance ( path_or_content , io . BufferedIOBase ) : buffer = io . StringIO ( path_or_content . read ( ) . decode ( encoding = CONF . encoding ) ) else : raise ValueError ( "path_or_content type could not be identified" ) return buffer , path
path_or_content: path or content_str or content_bts or string_io or bytes_io

    Returns
    -------
    string_buffer, path

    path will be None if input was not a path
path_or_content : path or content_str or content_bts or string_io or bytes_io