示例#1
0
    def __init__(self,
                 cookie: QNetworkCookie = None,
                 parent: QWidget = None) -> None:
        super().__init__(parent)
        self.setupUi(self)
        if cookie:
            self.m_nameLineEdit.setText(cookie.name().data().decode())
            self.m_domainLineEdit.setText(cookie.domain())
            self.m_valueLineEdit.setText(cookie.value().data().decode())
            self.m_pathLineEdit.setText(cookie.path())
            self.m_dateEdit.setDate(cookie.expirationDate().date())
            self.m_isSecureComboBox.addItem(
                self.tr("yes") if cookie.isSecure() else self.tr("no"))
            self.m_isHttpOnlyComboBox.addItem(
                self.tr("yes") if cookie.isHttpOnly() else self.tr("no"))
            self.m_addButton.setVisible(False)
            self.m_cancelButton.setText(self.tr("Close"))

        else:
            self.m_nameLineEdit.setReadOnly(False)
            self.m_domainLineEdit.setReadOnly(False)
            self.m_valueLineEdit.setReadOnly(False)
            self.m_pathLineEdit.setReadOnly(False)
            self.m_dateEdit.setReadOnly(False)
            self.m_dateEdit.setDate(
                QDateTime.currentDateTime().addYears(1).date())
            self.m_isSecureComboBox.addItem(self.tr("no"))
            self.m_isSecureComboBox.addItem(self.tr("yes"))
            self.m_isHttpOnlyComboBox.addItem(self.tr("no"))
            self.m_isHttpOnlyComboBox.addItem(self.tr("yes"))
示例#2
0
    def onCookieAdd(self, cookie: QNetworkCookie):
        """

        :param cookie: QNetworkCookie
        """
        domain = cookie.domain()  # '.hf666.net'
        path = cookie.path()  # '/'
        name = self.bytes2str(cookie.name().data())  # QByteArray-> (char)bytes
        value = self.bytes2str(cookie.value().data())
        self.DomainCookies[name] = value
        # if domain in self.DomainCookies:
        #     _cookie = self.DomainCookies[domain]
        #     _cookie[name] = value
        # else:
        #     self.DomainCookies[domain] = {
        #         name: value
        #     }
        # # -------------------------- ↓
        #
        # # -------------------------- ↑

        domain_path = domain + path
        if domain_path in self.PathCookies:
            _cookie = self.PathCookies[domain_path]
            _cookie[name] = value
        else:
            self.PathCookies[domain_path] = {
                name: value
            }
示例#3
0
 def __init__(self, cookie: QNetworkCookie, parent: QWidget = None) -> None:
     super().__init__(parent)
     self.setupUi(self)
     self.setAutoFillBackground(True)
     self.m_nameLabel.setText(cookie.name().data().decode())
     self.m_domainLabel.setText(cookie.domain())
     self.m_viewButton.clicked.connect(self.viewClicked)
     self.m_deleteButton.clicked.connect(self.deleteClicked)
示例#4
0
 def check_cookie_domain(self, cookie: QNetworkCookie):
     """
     检查 Cookie 的域名
     :param cookie: Cookie
     :type cookie: QNetworkCookie
     :return: 是否匹配域名
     :rtype: bool
     """
     cookie_domain = cookie.domain().lstrip('.')
     urisegs = urlparse(self.init_uri)
     return urisegs.hostname.endswith(cookie_domain)
示例#5
0
 def __cookie_to_json(self):
     cookies_list_info = []
     for c in self.__cookies:
         c = QNetworkCookie(c)
         data = {
             "name": bytearray(c.name()).decode(),
             "domain": c.domain(),
             "value": bytearray(c.value()).decode(),
             "path": c.path(),
             "expirationDate": c.expirationDate().toString(Qt.ISODate),
             "secure": c.isSecure(),
             "httponly": c.isHttpOnly()
         }
         cookies_list_info.append(data)
     return cookies_list_info
示例#6
0
def toPyCookie(qt_cookie: QNetworkCookie) -> Cookie:
    port = None
    port_specified = False
    secure = qt_cookie.isSecure()
    name = qt_cookie.name().data().decode()
    value = qt_cookie.value().data().decode()
    v = qt_cookie.path()
    path_specified = bool(v != "")
    path = v if path_specified else None
    v = qt_cookie.domain()
    domain_specified = bool(v != "")
    domain = v
    if domain_specified:
        domain_initial_dot = v.startswith(".")
    else:
        domain_initial_dot = None
    v = int(qt_cookie.expirationDate().toTime_t())
    expires = 2147483647 if v > 2147483647 else v
    rest = {"HttpOnly": qt_cookie.isHttpOnly()}
    discard = False
    return Cookie(
        0,
        name,
        value,
        port,
        port_specified,
        domain,
        domain_specified,
        domain_initial_dot,
        path,
        path_specified,
        secure,
        expires,
        discard,
        None,
        None,
        rest,
    )