def create_text_record(text):
 opos = text.tell()
 text.seek(0, 2)
 npos = min(((opos + RECORD_SIZE), text.tell()))
 extra = 0
 last = ''
 while (not last.decode(u'utf-8', u'ignore')):
  size = (len(last) + 1)
  text.seek((npos - size))
  last = text.read(size)
 try:
  last.decode(u'utf-8', u'strict')
 except UnicodeDecodeError:
  prev = len(last)
  while True:
   text.seek((npos - prev))
   last = text.read((len(last) + 1))
   try:
    last.decode(u'utf-8')
   except UnicodeDecodeError:
    pass
   else:
    break
  extra = (len(last) - prev)
 text.seek(opos)
 data = text.read(RECORD_SIZE)
 overlap = text.read(extra)
 text.seek(npos)
 return (data, overlap)

def create_text_record ( text ) : opos = text . tell ( ) text . seek ( 0 , 2 ) npos = min ( ( ( opos + RECORD_SIZE ) , text . tell ( ) ) ) extra = 0 last = '' while ( not last . decode ( u'utf-8' , u'ignore' ) ) : size = ( len ( last ) + 1 ) text . seek ( ( npos - size ) ) last = text . read ( size ) try : last . decode ( u'utf-8' , u'strict' ) except UnicodeDecodeError : prev = len ( last ) while True : text . seek ( ( npos - prev ) ) last = text . read ( ( len ( last ) + 1 ) ) try : last . decode ( u'utf-8' ) except UnicodeDecodeError : pass else : break extra = ( len ( last ) - prev ) text . seek ( opos ) data = text . read ( RECORD_SIZE ) overlap = text . read ( extra ) text . seek ( npos ) return ( data , overlap )
return a palmdoc record of size record_size from the text file object .