# Copyright (c) 2013 CEF Python, see the Authors file.# All rights reserved. Licensed under BSD 3-clause license.# Project website: https://github.com/cztomczak/cefpythoninclude "cefpython.pyx"cdef PyResponse CreatePyResponse(CefRefPtr[CefResponse] cefResponse):cdef PyResponse pyResponse = PyResponse()pyResponse.cefResponse = cefResponsereturn pyResponsecdef class PyResponse:cdef CefRefPtr[CefResponse] cefResponsecdef CefRefPtr[CefResponse] GetCefResponse(self) except *:if <void*>self.cefResponse != NULL and self.cefResponse.get():return self.cefResponseraise Exception("CefResponse was destroyed, you cannot use this object anymore")cpdef py_bool IsReadOnly(self):return self.GetCefResponse().get().IsReadOnly()cpdef int GetStatus(self) except *:return self.GetCefResponse().get().GetStatus()cpdef py_void SetStatus(self, int status):assert type(status) == int, "Response.SetStatus() failed: status param is not an int"self.GetCefResponse().get().SetStatus(status)cpdef str GetStatusText(self):return CefToPyString(self.GetCefResponse().get().GetStatusText())cpdef py_void SetStatusText(self, py_string statusText):assert type(statusText) in (str, unicode, bytes), ("Response.SetStatusText() failed: statusText param is not a string")cdef CefString cefStatusTextPyToCefString(statusText, cefStatusText)self.GetCefResponse().get().SetStatusText(cefStatusText)cpdef str GetMimeType(self):return CefToPyString(self.GetCefResponse().get().GetMimeType())cpdef py_void SetMimeType(self, py_string mimeType):assert type(mimeType) in (str, unicode, bytes), ("Response.SetMimeType() failed: mimeType param is not a string")cdef CefString cefMimeTypePyToCefString(mimeType, cefMimeType)self.GetCefResponse().get().SetMimeType(cefMimeType)cpdef str GetHeader(self, py_string name):assert type(name) in (str, unicode, bytes), ("Response.GetHeader() failed: name param is not a string")cdef CefString cefNamePyToCefString(name, cefName)return CefToPyString(self.GetCefResponse().get().GetHeader(cefName))cpdef dict GetHeaderMap(self):cdef list headerMultimap = self.GetHeaderMultimap()cdef dict headerMap = {}cdef tuple headerTuplefor headerTuple in headerMultimap:key = headerTuple[0]value = headerTuple[1]headerMap[key] = valuereturn headerMapcpdef list GetHeaderMultimap(self):cdef cpp_multimap[CefString, CefString] cefHeaderMapself.GetCefResponse().get().GetHeaderMap(cefHeaderMap)cdef list pyHeaderMultimap = []cdef cpp_multimap[CefString, CefString].iterator iterator = (cefHeaderMap.begin())cdef CefString cefKeycdef CefString cefValuecdef str pyKeycdef str pyValuewhile iterator != cefHeaderMap.end():cefKey = deref(iterator).firstcefValue = deref(iterator).secondpyKey = CefToPyString(cefKey)pyValue = CefToPyString(cefValue)pyHeaderMultimap.append((pyKey, pyValue))preinc(iterator)return pyHeaderMultimapcpdef py_void SetHeaderMap(self, dict headerMap):assert len(headerMap) > 0, "headerMap param is empty"cpdef list headerMultimap = []cdef object keyfor key in headerMap:headerMultimap.append((str(key), str(headerMap[key])))self.SetHeaderMultimap(headerMultimap)cpdef py_void SetHeaderMultimap(self, list headerMultimap):assert len(headerMultimap) > 0, "headerMultimap param is empty"cdef cpp_multimap[CefString, CefString] cefHeaderMapcdef CefString cefKeycdef CefString cefValuecdef cpp_pair[CefString, CefString] paircdef tuple headerTuplefor headerTuple in headerMultimap:PyToCefString(str(headerTuple[0]), cefKey)PyToCefString(str(headerTuple[1]), cefValue)pair.first, pair.second = cefKey, cefValuecefHeaderMap.insert(pair)self.GetCefResponse().get().SetHeaderMap(cefHeaderMap)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。