Skip to content

Commit 1f7f3d0

Browse files
linesightclaude
andcommitted
Upgrade Cython 0.29.36 to 3.2.4 for Python 3.13 compatibility
Cython 0.29.36 generates code using CPython internals removed in Python 3.13 (_PyDict_SetItem_KnownHash, _PyInterpreterState_GetConfig, _PyLong_AsByteArray), causing CI build failures on Python 3.13+. - requirements.txt: Cython == 0.29.36 -> == 3.2.4 - cython_setup.py: language_level 2 -> "3str"; remove c_string_type / c_string_encoding directives - All .pyx files: py_string type annotations -> object (Cython 3.x rejects string literals assigned to ctypedef object aliases) - All .pyx files: iteritems() -> items(), basestring -> (str, bytes), long -> int (Python 2 builtins removed under language_level=3str) - cefpython_app.cpp: remove extern "C" forward declarations that conflicted with Cython 3.x extern "C++" default in _fixed.h - build.py: fix_cefpython_api_header_file to write #pragma only to _fixed.h so Cython 3.x can overwrite its own output on rebuilds Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c6f7075 commit 1f7f3d0

27 files changed

Lines changed: 137 additions & 136 deletions

src/browser.pyx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ cdef class PyBrowser:
232232
if self.imageBuffer:
233233
free(self.imageBuffer)
234234

235-
cpdef py_void SetClientCallback(self, py_string name, object callback):
235+
cpdef py_void SetClientCallback(self, object name, object callback):
236236
if not self.allowedClientCallbacks:
237237
# DisplayHandler
238238
self.allowedClientCallbacks += [
@@ -291,7 +291,7 @@ cdef class PyBrowser:
291291
raise Exception("Browser.SetClientHandler() failed: __class__ "
292292
"attribute missing")
293293
cdef dict methods = {}
294-
cdef py_string key
294+
cdef object key
295295
cdef object method
296296
cdef tuple value
297297
for value in inspect.getmembers(clientHandler,
@@ -301,7 +301,7 @@ cdef class PyBrowser:
301301
if key and key[0] != '_':
302302
self.SetClientCallback(key, method)
303303

304-
cpdef object GetClientCallback(self, py_string name):
304+
cpdef object GetClientCallback(self, object name):
305305
if name in self.clientCallbacks:
306306
return self.clientCallbacks[name]
307307

@@ -347,7 +347,7 @@ cdef class PyBrowser:
347347
NonCriticalError("GetImage not implemented on this platform")
348348
return None
349349

350-
cpdef object GetSetting(self, py_string key):
350+
cpdef object GetSetting(self, object key):
351351
cdef int browser_id = self.GetIdentifier()
352352
if browser_id in g_browser_settings:
353353
if key in g_browser_settings[browser_id]:
@@ -358,7 +358,7 @@ cdef class PyBrowser:
358358
# CEF API.
359359
# --------------
360360

361-
cpdef py_void AddWordToDictionary(self, py_string word):
361+
cpdef py_void AddWordToDictionary(self, object word):
362362
cdef CefString cef_word
363363
PyToCefString(word, cef_word)
364364
self.GetCefBrowserHost().get().AddWordToDictionary(cef_word)
@@ -411,11 +411,13 @@ cdef class PyBrowser:
411411
def ExecuteFunction(self, *args):
412412
self.GetMainFrame().ExecuteFunction(*args)
413413

414-
cpdef py_void ExecuteJavascript(self, py_string jsCode,
415-
py_string scriptUrl="", int startLine=1):
414+
cpdef py_void ExecuteJavascript(self, object jsCode,
415+
object scriptUrl=None, int startLine=1):
416+
if scriptUrl is None:
417+
scriptUrl = u""
416418
self.GetMainFrame().ExecuteJavascript(jsCode, scriptUrl, startLine)
417419

418-
cpdef py_void Find(self, py_string searchText,
420+
cpdef py_void Find(self, object searchText,
419421
py_bool forward, py_bool matchCase,
420422
py_bool findNext):
421423
cdef CefString cefSearchText
@@ -428,14 +430,14 @@ cdef class PyBrowser:
428430
"Browser.GetFocusedFrame() may only be called on UI thread")
429431
return GetPyFrame(self.GetCefBrowser().get().GetFocusedFrame())
430432

431-
cpdef PyFrame GetFrameByName(self, py_string name):
433+
cpdef PyFrame GetFrameByName(self, object name):
432434
assert IsThread(TID_UI), (
433435
"Browser.GetFrameByName() may only be called on the UI thread")
434436
cdef CefString cefName
435437
PyToCefString(name, cefName)
436438
return GetPyFrame(self.GetCefBrowser().get().GetFrameByName(cefName))
437439

438-
cpdef object GetFrameByIdentifier(self, py_string identifier):
440+
cpdef object GetFrameByIdentifier(self, object identifier):
439441
cdef CefString cefIdentifier
440442
PyToCefString(identifier, cefIdentifier)
441443
return GetPyFrame(self.GetCefBrowser().get().GetFrameByIdentifier(
@@ -482,7 +484,7 @@ cdef class PyBrowser:
482484
else:
483485
return self.GetWindowHandle()
484486

485-
cpdef py_string GetUrl(self):
487+
cpdef object GetUrl(self):
486488
return self.GetMainFrame().GetUrl()
487489

488490
cpdef object GetUserData(self, object key):
@@ -525,10 +527,10 @@ cdef class PyBrowser:
525527
cpdef py_bool IsWindowRenderingDisabled(self):
526528
return self.GetCefBrowserHost().get().IsWindowRenderingDisabled()
527529

528-
cpdef py_string LoadUrl(self, py_string url):
530+
cpdef object LoadUrl(self, object url):
529531
self.GetMainFrame().LoadUrl(url)
530532

531-
cpdef py_void Navigate(self, py_string url):
533+
cpdef py_void Navigate(self, object url):
532534
self.LoadUrl(url)
533535

534536
cpdef py_void NotifyMoveOrResizeStarted(self):
@@ -543,7 +545,7 @@ cdef class PyBrowser:
543545
cpdef py_void ReloadIgnoreCache(self):
544546
self.GetCefBrowser().get().ReloadIgnoreCache()
545547

546-
cpdef py_void ReplaceMisspelling(self, py_string word):
548+
cpdef py_void ReplaceMisspelling(self, object word):
547549
cdef CefString cef_word
548550
PyToCefString(word, cef_word)
549551
self.GetCefBrowserHost().get().ReplaceMisspelling(cef_word)
@@ -739,7 +741,7 @@ cdef class PyBrowser:
739741
cpdef py_void SendCaptureLostEvent(self):
740742
self.GetCefBrowserHost().get().SendCaptureLostEvent()
741743

742-
cpdef py_void StartDownload(self, py_string url):
744+
cpdef py_void StartDownload(self, object url):
743745
self.GetCefBrowserHost().get().StartDownload(PyToCefStringValue(
744746
url))
745747

src/cefpython.pyx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,15 @@ cdef public void cefpython_GetDebugOptions(
403403
cdef public cpp_bool ApplicationSettings_GetBool(const char* key
404404
) except * with gil:
405405
# Called from client_handler/client_handler.cpp for example
406-
cdef py_string pyKey = CharToPyString(key)
406+
cdef object pyKey = CharToPyString(key)
407407
if pyKey in g_applicationSettings:
408408
return bool(g_applicationSettings[pyKey])
409409
return False
410410

411411
cdef public cpp_bool ApplicationSettings_GetBoolFromDict(const char* key1,
412412
const char* key2) except * with gil:
413-
cdef py_string pyKey1 = CharToPyString(key1)
414-
cdef py_string pyKey2 = CharToPyString(key2)
413+
cdef object pyKey1 = CharToPyString(key1)
414+
cdef object pyKey2 = CharToPyString(key2)
415415
cdef object dictValue # Yet to be checked whether it is `dict`
416416
if pyKey1 in g_applicationSettings:
417417
dictValue = g_applicationSettings[pyKey1]
@@ -423,14 +423,14 @@ cdef public cpp_bool ApplicationSettings_GetBoolFromDict(const char* key1,
423423

424424
cdef public cpp_string ApplicationSettings_GetString(const char* key
425425
) except * with gil:
426-
cdef py_string pyKey = CharToPyString(key)
426+
cdef object pyKey = CharToPyString(key)
427427
cdef cpp_string cppString
428428
if pyKey in g_applicationSettings:
429429
cppString = PyStringToChar(AnyToPyString(g_applicationSettings[pyKey]))
430430
return cppString
431431

432432
cdef public int CommandLineSwitches_GetInt(const char* key) except * with gil:
433-
cdef py_string pyKey = CharToPyString(key)
433+
cdef object pyKey = CharToPyString(key)
434434
if pyKey in g_commandLineSwitches:
435435
return int(g_commandLineSwitches[pyKey])
436436
return 0
@@ -1006,7 +1006,7 @@ def SetOsModalLoop(py_bool modalLoop):
10061006
with nogil:
10071007
CefSetOSModalLoop(cefModalLoop)
10081008

1009-
cpdef py_void SetGlobalClientCallback(py_string name, object callback):
1009+
cpdef py_void SetGlobalClientCallback(object name, object callback):
10101010
global g_globalClientCallbacks
10111011
# Global callbacks are prefixed with "_" in documentation.
10121012
# Accept both with and without a prefix.
@@ -1024,7 +1024,7 @@ cpdef py_void SetGlobalClientHandler(object clientHandler):
10241024
raise Exception("SetGlobalClientHandler() failed: __class__ "
10251025
"attribute missing")
10261026
cdef dict methods = {}
1027-
cdef py_string key
1027+
cdef object key
10281028
cdef object method
10291029
cdef tuple value
10301030
for value in inspect.getmembers(clientHandler,
@@ -1034,14 +1034,14 @@ cpdef py_void SetGlobalClientHandler(object clientHandler):
10341034
if key and key[0:2] != '__':
10351035
SetGlobalClientCallback(key, method)
10361036

1037-
cpdef object GetGlobalClientCallback(py_string name):
1037+
cpdef object GetGlobalClientCallback(object name):
10381038
global g_globalClientCallbacks
10391039
if name in g_globalClientCallbacks:
10401040
return g_globalClientCallbacks[name]
10411041
else:
10421042
return None
10431043

1044-
cpdef object GetAppSetting(py_string key):
1044+
cpdef object GetAppSetting(object key):
10451045
global g_applicationSettings
10461046
if key in g_applicationSettings:
10471047
return g_applicationSettings[key]
@@ -1060,7 +1060,7 @@ cpdef dict GetVersion():
10601060
cef_commit_number=__cef_commit_number__,
10611061
)
10621062

1063-
cpdef LoadCrlSetsFile(py_string path):
1063+
cpdef LoadCrlSetsFile(object path):
10641064
CefLoadCRLSetsFile(PyToCefStringValue(path))
10651065

10661066
cpdef GetDataUrl(data, mediatype="html"):

src/command_line.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ cdef void AppendSwitchesToCommandLine(
1212
# 1. App_OnBeforeCommandLineProcessing_BrowserProcess()
1313
# 2. BrowserProcessHandler_OnRenderProcessThreadCreated()
1414
cdef PyCommandLine pyCommandLine = CreatePyCommandLine(cefCommandLine)
15-
cdef py_string switch
16-
cdef py_string value
17-
for switch, value in switches.iteritems():
18-
if not isinstance(switch, basestring) or switch[0] == '-':
15+
cdef object switch
16+
cdef object value
17+
for switch, value in switches.items():
18+
if not isinstance(switch, (str, bytes)) or switch[0] == '-':
1919
Debug("Invalid command line switch: %s" % switch)
2020
continue
2121
if value:
@@ -39,27 +39,27 @@ cdef PyCommandLine CreatePyCommandLine(
3939
cdef class PyCommandLine:
4040
cdef CefRefPtr[CefCommandLine] cefCommandLine
4141

42-
cdef py_void AppendSwitch(self, py_string switch):
42+
cdef py_void AppendSwitch(self, object switch):
4343
cdef CefString cefSwitch
4444
cefSwitch = PyToCefStringValue(switch)
4545
self.cefCommandLine.get().AppendSwitch(cefSwitch)
4646

47-
cdef py_void AppendSwitchWithValue(self, py_string switch, py_string value):
47+
cdef py_void AppendSwitchWithValue(self, object switch, object value):
4848
cdef CefString cefSwitch
4949
cdef CefString cefValue
5050
cefSwitch = PyToCefStringValue(switch)
5151
cefValue = PyToCefStringValue(value)
5252
self.cefCommandLine.get().AppendSwitchWithValue(cefSwitch, cefValue)
5353

54-
cdef py_string GetCommandLineString(self):
54+
cdef object GetCommandLineString(self):
5555
return CefToPyString(self.cefCommandLine.get().GetCommandLineString())
5656

57-
cdef py_bool HasSwitch(self, py_string switch):
57+
cdef py_bool HasSwitch(self, object switch):
5858
cdef CefString cefSwitch
5959
cefSwitch = PyToCefStringValue(switch)
6060
return self.cefCommandLine.get().HasSwitch(cefSwitch)
6161

62-
cdef py_string GetSwitchValue(self, py_string switch):
62+
cdef object GetSwitchValue(self, object switch):
6363
cdef CefString cefValue
6464
cdef CefString cefSwitch
6565
cefSwitch = PyToCefStringValue(switch)

src/cookie.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ cdef class Cookie:
8484
"expires": self.GetExpires(),
8585
}
8686

87-
cpdef py_void SetName(self, py_string name):
87+
cpdef py_void SetName(self, object name):
8888
# This works:
8989
# | CefString(&self.cefCookie.name).FromString(name)
9090
# This does not work:
@@ -108,7 +108,7 @@ cdef class Cookie:
108108
cefString.Attach(&self.cefCookie.name, False)
109109
return CefToPyString(cefString)
110110

111-
cpdef py_void SetValue(self, py_string value):
111+
cpdef py_void SetValue(self, object value):
112112
cdef CefString cefString
113113
cefString.Attach(&self.cefCookie.value, False)
114114
PyToCefString(value, cefString)
@@ -118,7 +118,7 @@ cdef class Cookie:
118118
cefString.Attach(&self.cefCookie.value, False)
119119
return CefToPyString(cefString)
120120

121-
cpdef py_void SetDomain(self, py_string domain):
121+
cpdef py_void SetDomain(self, object domain):
122122
pattern = re.compile(r"^(?:[a-z0-9](?:[a-z0-9-_]{0,61}[a-z0-9])?\.)"
123123
r"+[a-z0-9][a-z0-9-_]{0,61}[a-z]$")
124124
if PY_MAJOR_VERSION == 2:
@@ -144,7 +144,7 @@ cdef class Cookie:
144144
cefString.Attach(&self.cefCookie.domain, False)
145145
return CefToPyString(cefString)
146146

147-
cpdef py_void SetPath(self, py_string path):
147+
cpdef py_void SetPath(self, object path):
148148
cdef CefString cefString
149149
cefString.Attach(&self.cefCookie.path, False)
150150
PyToCefString(path, cefString)
@@ -240,7 +240,7 @@ cdef class PyCookieManager:
240240
return self.cefCookieManager.get().VisitAllCookies(
241241
cefCookieVisitor)
242242

243-
cpdef py_bool VisitUrlCookies(self, py_string url,
243+
cpdef py_bool VisitUrlCookies(self, object url,
244244
py_bool includeHttpOnly, object userCookieVisitor):
245245
self.ValidateUserCookieVisitor(userCookieVisitor)
246246
cdef int cookieVisitorId = StoreUserCookieVisitor(userCookieVisitor)
@@ -251,14 +251,14 @@ cdef class PyCookieManager:
251251
PyToCefStringValue(url), bool(includeHttpOnly),
252252
cefCookieVisitor)
253253

254-
cpdef py_void SetCookie(self, py_string url, PyCookie cookie):
254+
cpdef py_void SetCookie(self, object url, PyCookie cookie):
255255
assert isinstance(cookie, Cookie), "cookie object is invalid"
256256
CefPostTask(TID_IO, CreateTask_SetCookie(
257257
self.cefCookieManager.get(),
258258
PyToCefStringValue(url), cookie.cefCookie,
259259
<CefRefPtr[CefSetCookieCallback]?>nullptr))
260260

261-
cpdef py_void DeleteCookies(self, py_string url, py_string cookie_name):
261+
cpdef py_void DeleteCookies(self, object url, object cookie_name):
262262
CefPostTask(TID_IO, CreateTask_DeleteCookies(
263263
self.cefCookieManager.get(),
264264
PyToCefStringValue(url), PyToCefStringValue(cookie_name),

src/dpi_aware_win.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DpiAware:
4141
# modern displays have equal horizontal and vertical resolution.
4242
default_dpix = 96
4343
scale = MulDiv(dpix, 100, default_dpix)
44-
if isinstance(arg, (int, long)):
44+
if isinstance(arg, int):
4545
v = arg
4646
new_value = MulDiv(v, scale, 100)
4747
return new_value

src/drag_data.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ cdef class DragData:
2424
cpdef py_bool IsFragment(self):
2525
return self.cef_drag_data.get().IsFragment()
2626

27-
cpdef py_string GetLinkUrl(self):
27+
cpdef object GetLinkUrl(self):
2828
return CefToPyString(self.cef_drag_data.get().GetLinkURL())
2929

30-
cpdef py_string GetLinkTitle(self):
30+
cpdef object GetLinkTitle(self):
3131
return CefToPyString(self.cef_drag_data.get().GetLinkTitle())
3232

33-
cpdef py_string GetFragmentText(self):
33+
cpdef object GetFragmentText(self):
3434
return CefToPyString(self.cef_drag_data.get().GetFragmentText())
3535

36-
cpdef py_string GetFragmentHtml(self):
36+
cpdef object GetFragmentHtml(self):
3737
return CefToPyString(self.cef_drag_data.get().GetFragmentHtml())
3838

3939
cpdef PyImage GetImage(self):

0 commit comments

Comments
 (0)