Create the object from a *file* or *file-like object*.
551434
def from_file(cls, file):
        """"""
        opf_xml = etree.parse(file)
        # Check if ``file`` is file-like.
        if hasattr(file, 'read'):
            name = os.path.basename(file.name)
            root = os.path.abspath(os.path.dirname(file.name))
        else:  # ...a filepath
            name = os.path.basename(file)
            root = os.path.abspath(os.path.dirname(file))
        parser = OPFParser(opf_xml)

        # Roll through the item entries
        manifest = opf_xml.xpath('/opf:package/opf:manifest/opf:item',
                                 namespaces=EPUB_OPF_NAMESPACES)
        pkg_items = []
        for item in manifest:
            absolute_filepath = os.path.join(root, item.get('href'))
            properties = item.get('properties', '').split()
            is_navigation = 'nav' in properties
            media_type = item.get('media-type')
            pkg_items.append(Item.from_file(absolute_filepath,
                                            media_type=media_type,
                                            is_navigation=is_navigation,
                                            properties=properties))
        # Ignore spine ordering, because it is not important
        #   for our use cases.
        return cls(name, pkg_items, parser.metadata)
565314
def _fileobj_to_fd(fileobj):
    
    if isinstance(fileobj, _INTEGER_TYPES):
        fd = fileobj
    else:
        for _integer_type in _INTEGER_TYPES:
            try:
                fd = _integer_type(fileobj.fileno())
                break
            except (AttributeError, TypeError, ValueError):
                continue
        else:
            raise ValueError("Invalid file object: {0!r}".format(fileobj))
    if fd < 0:
        raise ValueError("Invalid file descriptor: {0}".format(fd))
    return fd
1252854
def create(obj: PersistedObject, obj_type: Type[Any], arg_name: str):
        

        return MissingMandatoryAttributeFiles('Multifile object ' + str(obj) + ' cannot be built from constructor of '
                                              'type ' + get_pretty_type_str(obj_type) +
                                              ', mandatory constructor argument \'' + arg_name + '\'was not found on '
                                              'filesystem')
418033
def from_blob(cls, blob):
        
        stream = BytesIO(blob)
        return cls._from_stream(stream, blob)
1163963
def from_prefix(cls, container, prefix):
        """"""
        if prefix is None:
            raise errors.NoObjectException

        return cls(container,
                   name=prefix.name,
                   obj_type=cls.type_cls.SUBDIR)
1097612
def from_pubkey_file(cls, file):
        """"""
        if hasattr(file, 'read'):
            return cls.from_pubkey_line(file.read())

        return cls.from_pubkey_line(open(file).read())
1005293
def FromString(s, **kwargs):
    """"""
    
    f = StringIO.StringIO(s)
    return FromFile(f, **kwargs)
211459
def from_srt(cls, file):
        """"""
        parser = SRTParser().read(file)
        return cls(file=file, captions=parser.captions)
1296723
def fromfile(file, dtype, count, *args, **kwargs):
    """"""
    try:
        return numpy.fromfile(file, dtype=dtype, count=count, *args, **kwargs)
    except (TypeError, IOError):
        return numpy.frombuffer(file.read(count * numpy.dtype(dtype).itemsize),
                                dtype=dtype, count=count, *args, **kwargs)
1317848
def from_sbv(cls, file):
        """"""
        parser = SBVParser().read(file)
        return cls(file=file, captions=parser.captions)
296469
def factory(fileobject, jfs, parentpath): # fileobject from lxml.objectify
        ''
        if hasattr(fileobject, 'currentRevision'): # a normal file
            return JFSFile(fileobject, jfs, parentpath)
        elif str(fileobject.latestRevision.state) == ProtoFile.STATE_INCOMPLETE:
            return JFSIncompleteFile(fileobject, jfs, parentpath)
        elif str(fileobject.latestRevision.state) == ProtoFile.STATE_CORRUPT:
            return JFSCorruptFile(fileobject, jfs, parentpath)
        else:
            raise NotImplementedError('No JFS*File support for state %r. Please file a bug!' % fileobject.latestRevision.state)
596519
def new_from_file(self, filename: str, header_data: Optional[Header] = None,
                      mask_data: Optional[np.ndarray] = None):
        """"""
9118
def save(self, outfile):
        """"""
        if isinstance(outfile, compat.string_type):
            outfile = open(outfile, 'wb')
        assert hasattr(outfile, 'write') and callable(outfile.write), \
            "Expect a file or file-like object with a .write() method"
        outfile.write(self.data)
723684
def create(self, object_name, size=0, hash=None, extra=None, meta_data=None):
        
        obj = BaseObject(container=self.container,
                         driver=self.driver,
                         name=object_name,
                         size=size,
                         hash=hash,
                         extra=extra,
                         meta_data=meta_data)
        return Object(obj=obj)
791641
def fromfile(cls, f):
        """"""
        filter = cls()
        filter._setup(*unpack(cls.FILE_FMT, f.read(calcsize(cls.FILE_FMT))))
        nfilters, = unpack(b'<l', f.read(calcsize(b'<l')))
        if nfilters > 0:
            header_fmt = b'<' + b'Q'*nfilters
            bytes = f.read(calcsize(header_fmt))
            filter_lengths = unpack(header_fmt, bytes)
            for fl in filter_lengths:
                filter.filters.append(BloomFilter.fromfile(f, fl))
        else:
            filter.filters = []

        return filter
594058
def get_filelikeobject(filename: str = None,
                       blob: bytes = None) -> BinaryIO:
    
    if not filename and not blob:
        raise ValueError("no filename and no blob")
    if filename and blob:
        raise ValueError("specify either filename or blob")
    if filename:
        return open(filename, 'rb')
    else:
        return io.BytesIO(blob)
1284340
def load_object(self, filename):
        

        """
        p = Path(filename)
        with open(p, 'rb') as f:
            d = pickle.load(f)
        obj = self._new_object(objtype=p.suffix.strip('.'),
                               name=p.name.split('.')[0])
        obj.update(d)