>>> a='привет, '.encode('utf-8')
>>> b='мир!'.encode('cp1251')
>>> c=a+b
>>> c
b'\xd0\xbf\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82, \xec\xe8\xf0!'
text=bytes()
i=0
while i<=len(rawtext)-1:
if rawtext[i]==187 and rawtext[i-1]!=208:
text+=bytes([32])
elif rawtext[i]==171 and rawtext[i-1]!=208:
text+=bytes([32])
else:
text+=bytes([rawtext[i]])
i+=1
return(text.decode('utf-8', 'ignore'))