Exemplo n.º 1
0
    def handle_cookiesSave_clicked(self):
        cookieJar = self.framework.get_global_cookie_jar()
        cookieList = cookieJar.allCookies()
        domain = str(self.mainWindow.cookiesCookieJarDomainEdit.text())
        name = str(self.mainWindow.cookiesCookieJarNameEdit.text())
        value = str(self.mainWindow.cookiesCookieJarValueEdit.text())
        if not (domain and name and value):
            return
        cookie = self.find_cookie_by_domain_and_name(cookieList, domain, name)
        if cookie is None:
            # new
            cookie = QNetworkCookie(name, value)
            index = -1
        else:
            index = cookieList.index(cookie)

        cookie.setName(name)
        cookie.setDomain(domain)
        cookie.setValue(value)
        cookie.setPath(str(self.mainWindow.cookiesCookieJarPathEdit.text()))
        if self.mainWindow.cookiesCookieJarSessionCookieCheckbox.isChecked():
            cookie.setExpirationDate(QDateTime())
        else:
            cookie.setExpirationDate(self.mainWindow.cookiesCookieJarExpiryEdit.dateTime())
        cookie.setSecure(self.mainWindow.cookiesCookieJarSecureCheckbox.isChecked())
        cookie.setHttpOnly(self.mainWindow.cookiesCookieJarHttpOnlyCheckbox.isChecked())

        if -1 == index:
            cookieList.append(cookie)
        else:
            cookieList[index] = cookie

        cookieJar.setAllCookies(cookieList)
        self.populate_cookie_jar_tree()
Exemplo n.º 2
0
 def get_cookie(line):
     fields = map(str.strip, line.split("\t"))
     if len(fields) != 7:
         return
     domain, domain_flag, path, is_secure, expiration, name, value = fields
     cookie = QNetworkCookie(name, value)
     cookie.setDomain(domain)
     cookie.setPath(path)
     cookie.setSecure(str2bool(is_secure))
     cookie.setExpirationDate(QDateTime.fromTime_t(int(expiration)))
     return cookie
Exemplo n.º 3
0
 def get_cookie(line):
     fields = map(str.strip, line.split("\t"))
     if len(fields) != 7:
         return
     domain, domain_flag, path, is_secure, expiration, name, value = fields
     cookie = QNetworkCookie(name, value)
     cookie.setDomain(domain)
     cookie.setPath(path)
     cookie.setSecure(str2bool(is_secure))
     cookie.setExpirationDate(QDateTime.fromTime_t(int(expiration)))
     return cookie
Exemplo n.º 4
0
class ShoutCastForm(PluginBase.PluginBase):
    '''Grab Shoutcast streams and save them as "bookmarks" - and play them on
       the currently selected server.

       General shoutcast information is not preserved between runs. Also, the
       shoutcast server/API is pretty lame so timeouts actually occur quite
       frequently.
    '''
    moduleName = '&Shoutcast'
    moduleIcon = "network-workgroup"

    def load(self):
        pass

    def event(self, event):
        if event.type() == QEvent.Paint:
            if not hasattr(self, 'webView'):
                self._load()
                self.event = super(ShoutCastForm, self).event
        return False

    def _load(self):
        self.cookie = QNetworkCookie('Settings', 'Player~others|Bandwidth~ALL|Codec~ALL')
        self.cookie.setDomain('.shoutcast.com')
        self.cookie.setExpirationDate(QDateTime())
        self.cookie.setPath('/')

        self.webView = QWebView(self)
        self.webPage = self.webView.page()
        self.cookiejar = QNetworkCookieJar()
        self.cookiejar.setAllCookies([self.cookie])
        self.webPage.networkAccessManager().setCookieJar(self.cookiejar)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.webView)
        self.webView.load(QUrl(HOMEURL))
        self.webPage.setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
        self.connect(self.webPage, SIGNAL('linkClicked(const QUrl&)'), self._processLink)

    def _processLink(self, url):
        if url.host() == TUNEIN:
            self._playStation(unicode(url.toString()))
        else:
            self.webView.load(url)
            self.webView.show()

    def _playStation(self, url):
        try:
            streamList = streamTools.getStreamList(url)
        except streamTools.ParseError:
            return
        if streamList:
            self.modelManager.playQueue.extend(streamList)
Exemplo n.º 5
0
 def line2qcookie(line):
         domain,initial_dot,path,isSecure,expires,name,value=line.split()
         isSecure=(isSecure=="TRUE")
         dt=QDateTime()
         dt.setTime_t(int(expires))
         expires=dt
         c=QNetworkCookie()
         c.setDomain(domain)
         c.setPath(path)
         c.setSecure(isSecure)
         c.setExpirationDate(expires)
         c.setName(name)
         c.setValue(value)
         return c
Exemplo n.º 6
0
 def toQtCookie(pyCookie):
     qc = QNetworkCookie(pyCookie.name, pyCookie.value)
     qc.setSecure(pyCookie.secure)
     if pyCookie.path_specified:
         qc.setPath(pyCookie.path)
     if pyCookie.domain != "":
         qc.setDomain(pyCookie.domain)
     if pyCookie.expires != 0:
         t = QDateTime()
         t.setTime_t(pyCookie.expires)
         qc.setExpirationDate(t)
     # not yet handled(maybe less useful):
     #   py cookie.rest / QNetworkCookie.setHttpOnly()
     return qc
Exemplo n.º 7
0
 def toQtCookie(PyCookie):
     qc = QNetworkCookie( PyCookie.name, PyCookie.value )
     qc.setSecure(PyCookie.secure)
     if PyCookie.path_specified:
         qc.setPath(PyCookie.path)
     if PyCookie.domain != "" :
         qc.setDomain(PyCookie.domain)
     if PyCookie.expires != 0:
         t = QDateTime()
         t.setTime_t(PyCookie.expires)
         qc.setExpirationDate(t)
     # not yet handled(maybe less useful):
     #   py cookie.rest / QNetworkCookie.setHttpOnly()
     return qc
Exemplo n.º 8
0
    def load_cookies(self, url, cookie_strings):
        p = urlparse(url)

        cookies = list()
        for c in cookie_strings:
            n = c.find('=')
            name, value = c[:n], c[n+1:]
            cookie = QNetworkCookie(name, value)
            cookie.setDomain(p.netloc)
            cookies.append(cookie)

        cookiejar = QNetworkCookieJar()
        cookiejar.setAllCookies(cookies)
        self.networkAccessManager().setCookieJar(cookiejar)
Exemplo n.º 9
0
    def load(self):
      try:
        ds = pickle.load(open(self.m_cookiesFile, 'rb'))
      except:
        ds = []
      qs = []
      t = int(time.time())
      for d in ds:
        if d['expirationDate'] > t and not d['isSessionCookie']:
          c = QNetworkCookie(d['name'],d['value'])
          c.setDomain(d['domain'])
          c.setExpirationDate(QDateTime.fromTime_t(d['expirationDate']))
          c.setHttpOnly(d['isHttpOnly'])
          c.setSecure(d['isSecure'])
          c.setPath(d['path'])
          qs.append(c)

      #for c in cs
      self.setAllCookies(qs)
Exemplo n.º 10
0
    def har_cookie2qt(cls, cookie):
        qcookie = QNetworkCookie()
        qcookie.setName(cookie["name"])
        qcookie.setValue(cookie["value"])

        if 'domain' in cookie:
            qcookie.setDomain(cookie["domain"])

        if 'httpOnly' in cookie:
            qcookie.setHttpOnly(cookie["httpOnly"])

        if 'secure' in cookie:
            qcookie.setSecure(cookie["secure"])

        if 'path' in cookie:
            qcookie.setPath(cookie["path"])

        if cookie.get('expires'):
            expires = QDateTime.fromString(cookie["expires"], Qt.ISODate)
            qcookie.setExpirationDate(expires)

        return qcookie
Exemplo n.º 11
0
    def har_cookie2qt(cls, cookie):
        qcookie = QNetworkCookie()
        qcookie.setName(cookie["name"])
        qcookie.setValue(cookie["value"])

        if 'domain' in cookie:
            qcookie.setDomain(cookie["domain"])

        if 'httpOnly' in cookie:
            qcookie.setHttpOnly(cookie["httpOnly"])

        if 'secure' in cookie:
            qcookie.setSecure(cookie["secure"])

        if 'path' in cookie:
            qcookie.setPath(cookie["path"])

        if cookie.get('expires'):
            expires = QDateTime.fromString(cookie["expires"], Qt.ISODate)
            qcookie.setExpirationDate(expires)

        return qcookie
Exemplo n.º 12
0
    def handle_cookiesSave_clicked(self):
        cookieJar = self.framework.get_global_cookie_jar()
        cookieList = cookieJar.allCookies()
        domain = str(self.mainWindow.cookiesCookieJarDomainEdit.text())
        name = str(self.mainWindow.cookiesCookieJarNameEdit.text())
        value = str(self.mainWindow.cookiesCookieJarValueEdit.text())
        if not (domain and name and value):
            return
        cookie = self.find_cookie_by_domain_and_name(cookieList, domain, name)
        if cookie is None:
            # new
            cookie = QNetworkCookie(name, value)
            index = -1
        else:
            index = cookieList.index(cookie)

        cookie.setName(name)
        cookie.setDomain(domain)
        cookie.setValue(value)
        cookie.setPath(str(self.mainWindow.cookiesCookieJarPathEdit.text()))
        if self.mainWindow.cookiesCookieJarSessionCookieCheckbox.isChecked():
            cookie.setExpirationDate(QDateTime())
        else:
            cookie.setExpirationDate(
                self.mainWindow.cookiesCookieJarExpiryEdit.dateTime())
        cookie.setSecure(
            self.mainWindow.cookiesCookieJarSecureCheckbox.isChecked())
        cookie.setHttpOnly(
            self.mainWindow.cookiesCookieJarHttpOnlyCheckbox.isChecked())

        if -1 == index:
            cookieList.append(cookie)
        else:
            cookieList[index] = cookie

        cookieJar.setAllCookies(cookieList)
        self.populate_cookie_jar_tree()
Exemplo n.º 13
0
    def request(self, url, user_agent='Mozilla', cookies=None, timeout=15,
                method='get', data=None, headers=None):
        if cookies is None:
            cookies = {}
        if headers is None:
            headers = {}
        url_info = urlsplit(url)

        self.resource_list = []
        loop = QEventLoop()
        self.view.loadFinished.connect(loop.quit)

        # Timeout
        timer = QTimer()
        timer.setSingleShot(True)
        timer.timeout.connect(loop.quit)
        timer.start(timeout * 1000)

        # User-Agent
        self.page.user_agent = user_agent

        # Cookies
        cookie_obj_list = []
        for name, value in cookies.items():
            domain = ('.' + url_info.netloc).split(':')[0]
            #print 'CREATE COOKIE %s=%s' % (name, value)
            #print 'DOMAIN = %s' % domain
            cookie_obj = QNetworkCookie(name, value)
            cookie_obj.setDomain(domain)
            cookie_obj_list.append(cookie_obj)
        self.cookie_jar.setAllCookies(cookie_obj_list)

        # Method
        method_obj = getattr(QNetworkAccessManager, '%sOperation'
                             % method.capitalize())

        # Ensure that Content-Type is correct if method is post
        if method == 'post':
            headers['Content-Type'] = 'application/x-www-form-urlencoded'

        # Post data
        if data is None:
            data = QByteArray()

        # Request object
        request_obj = QNetworkRequest(QUrl(url))

        # Headers
        for name, value in headers.items():
            request_obj.setRawHeader(name, value)

        # Make a request
        self.view.load(request_obj, method_obj, data)

        loop.exec_()

        if timer.isActive():
            request_resource = None
            url = str(self.page.mainFrame().url().toString()).rstrip('/')
            for res in self.resource_list:
                if url == res.url or url == res.url.rstrip('/'):
                    request_resource = res
                    break
            if request_resource:
                return self.build_response(request_resource)
            else:
                raise KitError('Request was successful but it is not possible'
                               ' to associate the request to one of received'
                               ' responses')
        else:
            raise KitError('Timeout while loading %s' % url)
Exemplo n.º 14
0
class ShoutCastForm(PluginBase.PluginBase):
    '''Grab Shoutcast streams and save them as "bookmarks" - and play them on
       the currently selected server.

       General shoutcast information is not preserved between runs. Also, the
       shoutcast server/API is pretty lame so timeouts actually occur quite
       frequently.
    '''
    moduleName = '&Shoutcast'
    moduleIcon = "network-workgroup"

    def load(self):
        pass

    def event(self, event):
        if event.type() == QEvent.Paint:
            if not hasattr(self, 'webView'):
                self._load()
                self.event = super(ShoutCastForm, self).event
        return False

    def _load(self):
        self.cookie = QNetworkCookie('Settings',
                                     'Player~others|Bandwidth~ALL|Codec~ALL')
        self.cookie.setDomain('.shoutcast.com')
        self.cookie.setExpirationDate(QDateTime())
        self.cookie.setPath('/')

        self.webView = QWebView(self)
        self.webPage = self.webView.page()
        self.cookiejar = QNetworkCookieJar()
        self.cookiejar.setAllCookies([self.cookie])
        self.webPage.networkAccessManager().setCookieJar(self.cookiejar)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.webView)
        self.webView.load(QUrl(HOMEURL))
        self.webPage.setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
        self.connect(self.webPage, SIGNAL('linkClicked(const QUrl&)'),
                     self._processLink)

    def _processLink(self, url):
        if url.host() == TUNEIN:
            self._playStation(url.toString())
        else:
            self.webView.load(url)
            self.webView.show()

    def _playStation(self, url):
        data = self._retreivePLS(url)
        adrlist = self._parsePLS(data)
        self.mpdclient.send('command_list_ok_begin')
        try:
            for address in adrlist:
                self.mpdclient.send('add', (address, ))
        finally:
            self.mpdclient.send('command_list_end')

    def _retreivePLS(self, url):
        conn = httplib.HTTPConnection(TUNEIN)
        conn.request("GET", TUNEINFORMAT % url.split('=')[-1])
        resp = conn.getresponse()
        if resp.status == 200:
            return resp.read().split('\n')
        else:
            raise httplib.HTTPException('Got bad status code.')

    def _parsePLS(self, data):
        adrlist = []
        state = ''
        while data:
            line = data.pop(0)
            if state == '' and line == '[playlist]':
                state = 'playlist'
            elif state == 'playlist':
                if '=' in line:
                    key, value = line.split('=', 1)
                    if key.startswith('File'):
                        adrlist.append(value)
            else:
                raise httplib.HTTPException(
                    'Encountered error during parsing of the playlist.')
        return adrlist
Exemplo n.º 15
0
    def request(self,
                url,
                user_agent='Mozilla',
                cookies={},
                timeout=15,
                method='get',
                data=None,
                headers={}):
        url_info = urlsplit(url)

        self.resource_list = []
        loop = QEventLoop()
        self.view.loadFinished.connect(loop.quit)

        # Timeout
        timer = QTimer()
        timer.setSingleShot(True)
        timer.timeout.connect(loop.quit)
        timer.start(timeout * 1000)

        # User-Agent
        self.page.user_agent = user_agent

        # Cookies
        cookie_obj_list = []
        for name, value in cookies.items():
            domain = ('.' + url_info.netloc).split(':')[0]
            #print 'CREATE COOKIE %s=%s' % (name, value)
            #print 'DOMAIN = %s' % domain
            cookie_obj = QNetworkCookie(name, value)
            cookie_obj.setDomain(domain)
            cookie_obj_list.append(cookie_obj)
        self.cookie_jar.setAllCookies(cookie_obj_list)

        # Method
        method_obj = getattr(QNetworkAccessManager,
                             '%sOperation' % method.capitalize())

        # Ensure that Content-Type is correct if method is post
        if method == 'post':
            headers['Content-Type'] = 'application/x-www-form-urlencoded'

        # Post data
        if data is None:
            data = QByteArray()

        # Request object
        request_obj = QNetworkRequest(QUrl(url))

        # Headers
        for name, value in headers.items():
            request_obj.setRawHeader(name, value)

        # Make a request
        self.view.load(request_obj, method_obj, data)

        loop.exec_()

        if timer.isActive():
            request_resource = None
            url = str(self.page.mainFrame().url().toString()).rstrip('/')
            for res in self.resource_list:
                if url == res.url or url == res.url.rstrip('/'):
                    request_resource = res
                    break
            if request_resource:
                return self.build_response(request_resource)
            else:
                raise KitError('Request was successfull but it is not possible '\
                               'to associate the request to one of received responses')
        else:
            raise KitError('Timeout while loading %s' % url)
Exemplo n.º 16
0
    def request(self, url=None, user_agent=None, cookies=None,
                timeout=DEFAULT_PAGE_LOAD_TIMEOUT,
                referer=None, method='get', data=None,
                headers=None, proxy=None, wait=True):
        # Reset things bound to previous response
        self._response = None
        self.resource_list = []
        self._page_loaded = False
        #self.view.setHtml('', QUrl('blank://'))

        # Proxy
        if proxy:
            self.manager.setup_proxy(proxy)

        # User-Agent
        if user_agent is None:
            user_agent = DEFAULT_USER_AGENT
        self.page.set_user_agent(user_agent)

        # Cookies
        if cookies is None:
            cookies = {}
        cookie_obj_list = []
        for name, value in cookies.items():
            domain = ('.' + urlsplit(url).netloc).split(':')[0]
            #print 'CREATE COOKIE %s=%s' % (name, value)
            #print 'DOMAIN = %s' % domain
            cookie_obj = QNetworkCookie(name, value)
            cookie_obj.setDomain(domain)
            cookie_obj_list.append(cookie_obj)
        #self.cookie_jar.setAllCookies(cookie_obj_list)

        # HTTP Method
        method_obj = getattr(QNetworkAccessManager, '%sOperation'
                             % method.capitalize())
        # Ensure that Content-Type is correct if method is post
        if method == 'post':
            headers['Content-Type'] = 'application/x-www-form-urlencoded'

        # POST Data
        if data is None:
            data = QByteArray()

        # Build Request object
        req = QNetworkRequest(QUrl(url))

        # Referer
        if referer:
            req.setRawHeader('Referer', referer)

        # Headers
        if headers is None:
            headers = {}
        for name, value in headers.items():
            req.setRawHeader(name, value)
        self.content_type_stats = Counter()
        
        # Spawn request
        self.view.load(req, method_obj, data)

        if wait:
            self.wait_for_page_loaded(timeout=timeout)
            return self.get_page_response()
        else:
            return None
Exemplo n.º 17
0
class ShoutCastForm(PluginBase.PluginBase):
    '''Grab Shoutcast streams and save them as "bookmarks" - and play them on
       the currently selected server.

       General shoutcast information is not preserved between runs. Also, the
       shoutcast server/API is pretty lame so timeouts actually occur quite
       frequently.
    '''
    moduleName = '&Shoutcast'
    moduleIcon = "network-workgroup"

    def load(self):
        pass

    def event(self, event):
        if event.type() == QEvent.Paint:
            if not hasattr(self, 'webView'):
                self._load()
                self.event = super(ShoutCastForm, self).event
        return False

    def _load(self):
        self.cookie = QNetworkCookie('Settings', 'Player~others|Bandwidth~ALL|Codec~ALL')
        self.cookie.setDomain('.shoutcast.com')
        self.cookie.setExpirationDate(QDateTime())
        self.cookie.setPath('/')

        self.webView = QWebView(self)
        self.webPage = self.webView.page()
        self.cookiejar = QNetworkCookieJar()
        self.cookiejar.setAllCookies([self.cookie])
        self.webPage.networkAccessManager().setCookieJar(self.cookiejar)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.webView)
        self.webView.load(QUrl(HOMEURL))
        self.webPage.setLinkDelegationPolicy(QWebPage.DelegateExternalLinks)
        self.connect(self.webPage, SIGNAL('linkClicked(const QUrl&)'), self._processLink)

    def _processLink(self, url):
        if url.host() == TUNEIN:
            self._playStation(url.toString())
        else:
            self.webView.load(url)
            self.webView.show()

    def _playStation(self, url):
        data = self._retreivePLS(url)
        adrlist = self._parsePLS(data)
        self.mpdclient.send('command_list_ok_begin')
        try:
            for address in adrlist:
                self.mpdclient.send('add', (address,))
        finally:
            self.mpdclient.send('command_list_end')

    def _retreivePLS(self, url):
        conn = httplib.HTTPConnection(TUNEIN)
        conn.request("GET", TUNEINFORMAT % url.split('=')[-1])
        resp = conn.getresponse()
        if resp.status == 200:
            return resp.read().split('\n')
        else:
            raise httplib.HTTPException('Got bad status code.')

    def _parsePLS(self, data):
        adrlist = []
        state = ''
        while data:
            line = data.pop(0)
            if state == '' and line == '[playlist]':
                state = 'playlist'
            elif state == 'playlist':
                if '=' in line:
                    key, value = line.split('=', 1)
                    if key.startswith('File'):
                        adrlist.append(value)
            else:
                raise httplib.HTTPException('Encountered error during parsing of the playlist.')
        return adrlist