summaryrefslogtreecommitdiff
path: root/src/cchardet/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/cchardet/__init__.py')
-rw-r--r--src/cchardet/__init__.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/cchardet/__init__.py b/src/cchardet/__init__.py
new file mode 100644
index 0000000..de2a3db
--- /dev/null
+++ b/src/cchardet/__init__.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+from cchardet import _cchardet
+
+def detect(msg):
+ """
+ Args:
+ msg: str
+ Returns:
+ {
+ "encoding": str,
+ "confidence": float
+ }
+ """
+ encoding, confidence = _cchardet.detect_with_confidence(msg)
+ if isinstance(encoding, bytes):
+ encoding = encoding.decode()
+ return {"encoding": encoding, "confidence": confidence}