+ info = response.info()
+ if "Content-Type" in info:
+ import re
+ match = re.search(
+ "charset=(?P<charset>[a-zA-Z0-9_\-]+)", info["Content-Type"])
+ if match:
+ charset = match.group("charset").lower()
+
+ if charset in ("x-sjis", "x_sjis", "sjis", "shiftjis", "shift-jis",
+ "shift_jis", "s-jis", "s_jis"):
+ encoding = "cp932"
+ elif charset in ("euc-jp", "euc_jp", "eucjp"):
+ encoding = "euc-jp"
+
+ if encoding:
+ data = data.decode(encoding, "replace")