import sqlite3
import io


def _fetch_plist(filename):
    """ Retrieves the embedded plist from the Sketch doc """
    conn = sqlite3.connect(filename)
    c = conn.cursor()

    c.execute("select value from payload where name='main'")
    payload = c.fetchone()[0]
    plist_obj = io.BytesIO(payload)

    conn.close()

    return plist_obj