Repository navigation
Expand file tree
/
Copy pathstring_utils.pyx
More file actions
80 lines (72 loc) · 2.58 KB
/
Copy pathstring_utils.pyx
File metadata and controls
80 lines (72 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright (c) 2012 CefPython Authors. All rights reserved.
# License: New BSD License.
# Website: http://code.google.com/p/cefpython/
cdef str CharToPyString(
char* charString):
cdef str pyString
if bytes == str:
# Python 2.7, bytes and str are the same types.
# "" + charString >> makes a copy of char*
pyString = "" + charString
else:
# Python 3.
pyString = (b"" + charString).decode("utf-8", "ignore")
return pyString
cdef str CefToPyString(
ConstCefString& cefString):
if cefString.empty():
return ""
IF UNAME_SYSNAME == "Windows":
cdef wchar_t* wcharstr = <wchar_t*> cefString.c_str()
return WidecharToPyString(wcharstr)
ELSE:
# The windows version above is probably more efficient.
return cefString.ToString()
cdef void PyToCefString(
py_string pyString,
CefString& cefString
) except *:
if bytes == str:
# Python 2.7, bytes and str are the same types.
if type(pyString) == unicode:
pyString = pyString.encode(
g_applicationSettings["unicode_to_bytes_encoding"])
else:
# Python 3 requires bytes before converting to char*.
if type(pyString) != bytes:
pyString = pyString.encode("utf-8")
cdef cpp_string cppString = pyString
# When used cefString.FromASCII(), a DCHECK failed
# when passed a unicode string.
cefString.FromString(cppString)
cdef CefString PyToCefStringValue(
py_string pyString
) except *:
cdef CefString cefString
PyToCefString(pyString, cefString)
return cefString
cdef void PyToCefStringPointer(
py_string pyString,
CefString* cefString
) except *:
if bytes == str:
# Python 2.7, bytes and str are the same types.
if type(pyString) == unicode:
pyString = pyString.encode(
g_applicationSettings["unicode_to_bytes_encoding"])
else:
# Python 3 requires bytes before converting to char*.
if type(pyString) != bytes:
pyString = pyString.encode("utf-8")
cdef cpp_string cppString = pyString
# When used cefString.FromASCII(), a DCHECK failed
# when passed a unicode string.
cefString.FromString(cppString)
cdef str VoidPtrToStr(const void* data, size_t dataLength):
cdef object pyData
if PY_MAJOR_VERSION < 3:
pyData = (<char*>data)[:dataLength]
else:
pyData = (<char*>data)[:dataLength].decode(
g_applicationSettings["unicode_to_bytes_encoding"])
return pyData