|
| 1 | +# Copyright (c) 2012-2013 CefPython Authors. All rights reserved. |
| 2 | +# License: New BSD License. |
| 3 | +# Website: http://code.google.com/p/cefpython/ |
| 4 | + |
| 5 | +cdef Cookie cookie = Cookie() |
| 6 | +cookie.SetName("asd1") |
| 7 | +print("cookie.cefCookie: %s" % cookie.cefCookie) |
| 8 | +print("cookie.GetName(): %s" % cookie.GetName()) |
| 9 | +print("cookie.GetCreation(): %s" % cookie.GetCreation()) |
| 10 | +cookie.SetCreation(datetime.datetime(2013,5,23)) |
| 11 | +print("cookie.GetCreation(): %s" % cookie.GetCreation()) |
| 12 | +print("cookie: %s" % cookie.Get()) |
| 13 | + |
| 14 | +# ------------------------------------------------------------------------------ |
| 15 | +# Cookie |
| 16 | +# ------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +cdef class Cookie: |
| 19 | + cdef CefCookie cefCookie |
| 20 | + |
| 21 | + cpdef py_void Set(self, dict cookie): |
| 22 | + for key in cookie: |
| 23 | + if key == "name": |
| 24 | + self.SetName(cookie[key]) |
| 25 | + elif key == "value": |
| 26 | + self.SetValue(cookie[key]) |
| 27 | + elif key == "domain": |
| 28 | + self.SetDomain(cookie[key]) |
| 29 | + elif key == "path": |
| 30 | + self.SetPath(cookie[key]) |
| 31 | + elif key == "secure": |
| 32 | + self.SetSecure(cookie[key]) |
| 33 | + elif key == "httpOnly": |
| 34 | + self.SetHttpOnly(cookie[key]) |
| 35 | + elif key == "creation": |
| 36 | + self.SetCreation(cookie[key]) |
| 37 | + elif key == "lastAccess": |
| 38 | + self.SetLastAccess(cookie[key]) |
| 39 | + elif key == "hasExpires": |
| 40 | + self.SetHasExpires(cookie[key]) |
| 41 | + elif key == "expires": |
| 42 | + self.SetExpires(cookie[key]) |
| 43 | + else: |
| 44 | + raise Exception("Invalid key: %s" % key) |
| 45 | + |
| 46 | + cpdef dict Get(self): |
| 47 | + return { |
| 48 | + "name": self.GetName(), |
| 49 | + "value": self.GetValue(), |
| 50 | + "domain": self.GetDomain(), |
| 51 | + "path": self.GetPath(), |
| 52 | + "secure": self.GetSecure(), |
| 53 | + "httpOnly": self.GetHttpOnly(), |
| 54 | + "creation": self.GetCreation(), |
| 55 | + "lastAccess": self.GetLastAccess(), |
| 56 | + "hasExpires": self.GetHasExpires(), |
| 57 | + "expires": self.GetExpires(), |
| 58 | + } |
| 59 | + |
| 60 | + cpdef py_void SetName(self, py_string name): |
| 61 | + # This works: |
| 62 | + # | CefString(&self.cefCookie.name).FromString(name) |
| 63 | + # This does not work (strange!): |
| 64 | + # | cdef CefString cefString = CefString(&self.cefCookie.name) |
| 65 | + # | PyToCefString(name, cefString) |
| 66 | + # But this works: |
| 67 | + # | cdef CefString* cefString = new CefString(&self.cefCookie.name) |
| 68 | + # | PyToCefStringPointer(name, cefString) |
| 69 | + # | del cefString |
| 70 | + CefString(&self.cefCookie.name).FromString(name) |
| 71 | + |
| 72 | + cpdef str GetName(self): |
| 73 | + cdef CefString cefString = CefString(&self.cefCookie.name) |
| 74 | + return CefToPyString(cefString) |
| 75 | + |
| 76 | + cpdef py_void SetValue(self, py_string value): |
| 77 | + CefString(&self.cefCookie.value).FromString(value) |
| 78 | + |
| 79 | + cpdef str GetValue(self): |
| 80 | + cdef CefString cefString = CefString(&self.cefCookie.value) |
| 81 | + return CefToPyString(cefString) |
| 82 | + |
| 83 | + cpdef py_void SetDomain(self, py_string domain): |
| 84 | + CefString(&self.cefCookie.domain).FromString(domain) |
| 85 | + |
| 86 | + cpdef str GetDomain(self): |
| 87 | + cdef CefString cefString = CefString(&self.cefCookie.domain) |
| 88 | + return CefToPyString(cefString) |
| 89 | + |
| 90 | + cpdef py_void SetPath(self, py_string path): |
| 91 | + CefString(&self.cefCookie.path).FromString(path) |
| 92 | + |
| 93 | + cpdef str GetPath(self): |
| 94 | + cdef CefString cefString = CefString(&self.cefCookie.path) |
| 95 | + return CefToPyString(cefString) |
| 96 | + |
| 97 | + cpdef py_void SetSecure(self, py_bool secure): |
| 98 | + self.cefCookie.secure = secure |
| 99 | + |
| 100 | + cpdef py_bool GetSecure(self): |
| 101 | + return self.cefCookie.secure |
| 102 | + |
| 103 | + cpdef py_void SetHttpOnly(self, py_bool httpOnly): |
| 104 | + self.cefCookie.httponly = httpOnly |
| 105 | + |
| 106 | + cpdef py_bool GetHttpOnly(self): |
| 107 | + return self.cefCookie.httponly |
| 108 | + |
| 109 | + cpdef py_void SetCreation(self, object creation): |
| 110 | + DatetimeToCefTimeT(creation, self.cefCookie.creation) |
| 111 | + |
| 112 | + cpdef object GetCreation(self): |
| 113 | + return CefTimeTToDatetime(self.cefCookie.creation) |
| 114 | + |
| 115 | + cpdef py_void SetLastAccess(self, object lastAccess): |
| 116 | + DatetimeToCefTimeT(lastAccess, self.cefCookie.last_access) |
| 117 | + |
| 118 | + cpdef object GetLastAccess(self): |
| 119 | + return CefTimeTToDatetime(self.cefCookie.last_access) |
| 120 | + |
| 121 | + cpdef py_void SetHasExpires(self, py_bool hasExpires): |
| 122 | + self.cefCookie.has_expires = hasExpires |
| 123 | + |
| 124 | + cpdef py_bool GetHasExpires(self): |
| 125 | + return self.cefCookie.has_expires |
| 126 | + |
| 127 | + cpdef py_void SetExpires(self, object expires): |
| 128 | + DatetimeToCefTimeT(expires, self.cefCookie.expires) |
| 129 | + |
| 130 | + cpdef object GetExpires(self): |
| 131 | + return CefTimeTToDatetime(self.cefCookie.expires) |
| 132 | + |
| 133 | +# ------------------------------------------------------------------------------ |
| 134 | +# CookieManager |
| 135 | +# ------------------------------------------------------------------------------ |
| 136 | + |
| 137 | +class CookieManager: |
| 138 | + pass |
| 139 | + |
| 140 | +# ------------------------------------------------------------------------------ |
| 141 | +# PyCookieManager |
| 142 | +# ------------------------------------------------------------------------------ |
| 143 | + |
| 144 | +cdef class PyCookieManager: |
| 145 | + pass |
| 146 | + |
| 147 | +# ------------------------------------------------------------------------------ |
| 148 | +# PyCookieVisitor |
| 149 | +# ------------------------------------------------------------------------------ |
| 150 | + |
| 151 | +cdef class PyCookieVisitor: |
| 152 | + pass |
0 commit comments