'Add a file to this container. Entries for the file are
automatically created in the OPF manifest and spine
(if the file is a text document)'

def add_file(self, name, data, media_type=None, spine_index=None, modify_name_if_needed=False, process_manifest_item=None):

    if (u'..' in name):
        raise ValueError(u'Names    are    not    allowed    to    have    ..    in    them')
    href = self.name_to_href(name, self.opf_name)
    if (self.has_name_case_insensitive(name) or self.manifest_has_name(name)):
        if (not modify_name_if_needed):
            raise ValueError(((u'A    file    with    the    name    %s    already    exists' % name) if self.has_name_case_insensitive(name) else (u'An    item    with    the    href    %s    already    exists    in    the    manifest' % href)))
        name = self.make_name_unique(name)
        href = self.name_to_href(name, self.opf_name)
    path = self.name_to_abspath(name)
    base = os.path.dirname(path)
    if (not os.path.exists(base)):
        os.makedirs(base)
    with lopen(path, u'wb') as f:
        if hasattr(data, u'read'):
            shutil.copyfileobj(data, f)
        else:
            f.write(data)
    mt = (media_type or self.guess_type(name))
    self.name_path_map[name] = path
    self.mime_map[name] = mt
    if self.ok_to_be_unmanifested(name):
        return name
    item_id = self.add_name_to_manifest(name, process_manifest_item=process_manifest_item)
    if (mt in OEB_DOCS):
        manifest = self.opf_xpath(u'//opf:manifest')[0]
        spine = self.opf_xpath(u'//opf:spine')[0]
        si = manifest.makeelement(OPF(u'itemref'), idref=item_id)
        self.insert_into_xml(spine, si, index=spine_index)
    return name
