def serialize(self, stream: IO[bytes], base: Optional[str]=None, encoding: Optional[str]=None, **args):
    if (base is not None):
        self.base = base
    elif (self.store.base is not None):
        self.base = self.store.base
    self.__stream = stream
    self.__serialized: Dict[(Identifier, int)] = {}
    encoding = self.encoding
    self.write = write = (lambda uni: stream.write(uni.encode(encoding, 'replace')))
    write(('<?xml version="1.0" encoding="%s"?>\n' % self.encoding))
    write('<rdf:RDF\n')
    if ('xml_base' in args):
        write(('   xml:base="%s"\n' % args['xml_base']))
    elif self.base:
        write(('   xml:base="%s"\n' % self.base))
    bindings = list(self.__bindings())
    bindings.sort()
    for (prefix, namespace) in bindings:
        if prefix:
            write(('   xmlns:%s="%s"\n' % (prefix, namespace)))
        else:
            write(('   xmlns="%s"\n' % namespace))
    write('>\n')
    for subject in self.store.subjects():
        self.subject(subject, 1)
    write('</rdf:RDF>\n')
    del self.__serialized
def serialize(self, stream: IO[bytes], base: Optional[str]=None, encoding: Optional[str]=None, **args):
    if (base is not None):
        self.base = base
    elif (self.store.base is not None):
        self.base = self.store.base
    self.__stream = stream
    self.__serialized: Dict[(Identifier, int)] = {}
    encoding = self.encoding
    self.write = write = (lambda uni: stream.write(uni.encode(encoding, 'replace')))
    write(('<?xml version="1.0" encoding="%s"?>\n' % self.encoding))
    write('<rdf:RDF\n')
    if ('xml_base' in args):
        write(('   xml:base="%s"\n' % args['xml_base']))
    elif self.base:
        write(('   xml:base="%s"\n' % self.base))
    bindings = list(self.__bindings())
    bindings.sort()
    for (prefix, namespace) in bindings:
        if prefix:
            write(('   xmlns:%s="%s"\n' % (prefix, namespace)))
        else:
            write(('   xmlns="%s"\n' % namespace))
    write('>\n')
    for subject in self.store.subjects():
        self.subject(subject, 1)
    write('</rdf:RDF>\n')
    del self.__serialized