#-*- coding: utf-8 -*-
def mdcode(str, encoding = 'utf-8'):
	if isinstance(str, unicode):
		return str.encode(encoding)

	for c in ('utf-8', 'gbk', 'gb2312' ,'gb18030', 'utf-16'):
		try:
			if encoding == 'unicode':
				return str.decode(c)
			else:
				return str.decode(c).encode(encoding)
		except:
			pass
	raise 'Unkown charset'
d32692ba8a6ea52b77147b36e987aa2eb88397bc
<mask token>

def mdcode(str, encoding='utf-8'):
    if isinstance(str, unicode):
        return str.encode(encoding)
    for c in ('utf-8', 'gbk', 'gb2312', 'gb18030', 'utf-16'):
        try:
            if encoding == 'unicode':
                return str.decode(c)
            else:
                return str.decode(c).encode(encoding)
        except:
            pass
    raise 'Unkown charset'

#-*- coding: utf-8 -*-
def mdcode(str, encoding = 'utf-8'):
	if isinstance(str, unicode):
		return str.encode(encoding)

	for c in ('utf-8', 'gbk', 'gb2312' ,'gb18030', 'utf-16'):
		try:
			if encoding == 'unicode':
				return str.decode(c)
			else:
				return str.decode(c).encode(encoding)
		except:
			pass
	raise 'Unkown charset'