def serialize(self, stream: IO[bytes], base: Optional[str]=None, encoding: Optional[str]=None, **args):
    self.__serialized: Dict[(Identifier, int)] = {}
    store = self.store
    if (base is not None):
        self.base = base
    elif (store.base is not None):
        self.base = store.base
    self.max_depth = args.get('max_depth', 3)
    assert (self.max_depth > 0), 'max_depth must be greater than 0'
    self.nm = nm = store.namespace_manager
    self.writer = writer = XMLWriter(stream, nm, encoding)
    namespaces = {}
    possible = set(store.predicates()).union(store.objects(None, RDF.type))
    for predicate in possible:
        (prefix, namespace, local) = nm.compute_qname_strict(predicate)
        namespaces[prefix] = namespace
    namespaces['rdf'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    writer.push(RDFVOC.RDF)
    if ('xml_base' in args):
        writer.attribute(XMLBASE, args['xml_base'])
    elif self.base:
        writer.attribute(XMLBASE, self.base)
    writer.namespaces(namespaces.items())
    subject: Identifier
    for subject in store.subjects():
        if ((None, None, subject) in store):
            if ((subject, None, subject) in store):
                self.subject(subject, 1)
        else:
            self.subject(subject, 1)
    bnodes = set()
    for subject in store.subjects():
        if isinstance(subject, BNode):
            bnodes.add(subject)
            continue
        self.subject(subject, 1)
    for bnode in bnodes:
        if (bnode not in self.__serialized):
            self.subject(subject, 1)
    writer.pop(RDFVOC.RDF)
    stream.write('\n'.encode('latin-1'))
    self.__serialized = None
def serialize(self, stream: IO[bytes], base: Optional[str]=None, encoding: Optional[str]=None, **args):
    self.__serialized: Dict[(Identifier, int)] = {}
    store = self.store
    if (base is not None):
        self.base = base
    elif (store.base is not None):
        self.base = store.base
    self.max_depth = args.get('max_depth', 3)
    assert (self.max_depth > 0), 'max_depth must be greater than 0'
    self.nm = nm = store.namespace_manager
    self.writer = writer = XMLWriter(stream, nm, encoding)
    namespaces = {}
    possible = set(store.predicates()).union(store.objects(None, RDF.type))
    for predicate in possible:
        (prefix, namespace, local) = nm.compute_qname_strict(predicate)
        namespaces[prefix] = namespace
    namespaces['rdf'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    writer.push(RDFVOC.RDF)
    if ('xml_base' in args):
        writer.attribute(XMLBASE, args['xml_base'])
    elif self.base:
        writer.attribute(XMLBASE, self.base)
    writer.namespaces(namespaces.items())
    subject: Identifier
    for subject in store.subjects():
        if ((None, None, subject) in store):
            if ((subject, None, subject) in store):
                self.subject(subject, 1)
        else:
            self.subject(subject, 1)
    bnodes = set()
    for subject in store.subjects():
        if isinstance(subject, BNode):
            bnodes.add(subject)
            continue
        self.subject(subject, 1)
    for bnode in bnodes:
        if (bnode not in self.__serialized):
            self.subject(subject, 1)
    writer.pop(RDFVOC.RDF)
    stream.write('\n'.encode('latin-1'))
    self.__serialized = None