def create_file(dest, content):
    """
    Creates a file at dest with content.
    If content is a string or unicode, use it as the content.
    Otherwise, use content.read() as the content.
    """
    if not isinstance(content, (binary_type, text_type)):
        content = content.read()
    parent = os.path.dirname(dest)
    if not os.path.exists(parent):
        os.makedirs(parent)
    if isinstance(content, binary_type):
        with io.open(dest, "wb") as f:
            f.write(content)
    elif isinstance(content, text_type):
        with io.open(dest, "w", encoding="utf-8") as f:
            f.write(content)
    return dest

    Creates a file at dest with content.
    If content is a string or unicode, use it as the content.
    Otherwise, use content.read() as the content.
    
lib/stashutils/extensions.py