<s> """<STR_LIT>""" <EOL> from rdflib . serializer import Serializer <EOL> import warnings <EOL> class NTSerializer ( Serializer ) : <EOL> """<STR_LIT>""" <EOL> def serialize ( self , stream , base = None , encoding = None , ** args ) : <EOL> if base is not None : <EOL> warnings . warn ( "<STR_LIT>" ) <EOL> if encoding is not None : <EOL> warnings . warn ( "<STR_LIT>" ) <EOL> encoding = self . encoding <EOL> for triple in self . store : <EOL> stream . write ( _nt_row ( triple ) . encode ( encoding , "<STR_LIT:replace>" ) ) <EOL> stream . write ( "<STR_LIT:\n>" ) <EOL> def _nt_row ( triple ) : <EOL> return u"<STR_LIT>" % ( triple [ <NUM_LIT:0> ] . n3 ( ) , <EOL> triple [ <NUM_LIT:1> ] . n3 ( ) , <EOL> _xmlcharref_encode ( triple [ <NUM_LIT:2> ] . n3 ( ) ) ) <EOL> def _xmlcharref_encode ( unicode_data , encoding = "<STR_LIT:ascii>" ) : <EOL> """<STR_LIT>""" <EOL> chars = [ ] <EOL> unicode_data = unicode_data . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> if unicode_data . startswith ( '<STR_LIT>' ) : <EOL> unicode_data = unicode_data . replace ( '<STR_LIT>' , '<STR_LIT:">' ) <EOL> for char in unicode_data : <EOL> try : <EOL> chars . append ( char . encode ( encoding , '<STR_LIT:strict>' ) ) <EOL> except UnicodeError : <EOL> chars . append ( '<STR_LIT>' % ord ( char ) if ord ( char ) <= <NUM_LIT> else '<STR_LIT>' % ord ( char ) ) <EOL> return '<STR_LIT>' . join ( chars ) </s>
