Merge branch 'master' of git://github.com/ariya/phantomjs

1.4
IceArmy 2011-09-21 00:13:42 -07:00
commit 77d213f3ec
9 changed files with 8 additions and 349 deletions

View File

@ -9,9 +9,9 @@ users= [
'bmoeskau'
'darrellmeyer'
'DavidKaneda'
'DmitryBaranovsk'
'donovanerba'
'edspencer'
'evantrimboli'
'ExtAnimal'
'jamespearce'
'jamieavins'

View File

@ -8,9 +8,9 @@ var users = ['sencha',
'bmoeskau',
'darrellmeyer',
'DavidKaneda',
'DmitryBaranovsk',
'donovanerba',
'edspencer',
'evantrimboli',
'ExtAnimal',
'jamespearce',
'jamieavins',

View File

@ -52,12 +52,8 @@ page.open phantom.args[0], (status) ->
, ->
page.evaluate ->
console.log document.body.querySelector('.description').innerText
list = document.body.querySelectorAll 'div.jasmine_reporter > div.suite.failed'
for i in list
el = i
desc = el.querySelectorAll '.description'
console.log ''
for j in desc
console.log j.innerText
list = document.body.querySelectorAll('.failed > .description, .failed > .messages > .resultMessage')
for el in list
console.log el.innerText
phantom.exit()

View File

@ -23,7 +23,6 @@ from PyQt4.QtNetwork import (QNetworkAccessManager, QNetworkDiskCache,
QNetworkRequest)
from cookiejar import CookieJar
from networkreplyproxy import NetworkReplyProxy
from plugincontroller import do_action
@ -58,7 +57,7 @@ class NetworkAccessManager(QNetworkAccessManager):
def createRequest(self, op, req, outgoingData):
do_action('NetworkAccessManagerCreateRequestPre')
reply = NetworkReplyProxy(self, QNetworkAccessManager.createRequest(self, op, req, outgoingData))
reply = QNetworkAccessManager.createRequest(self, op, req, outgoingData)
if self.m_ignoreSslErrors:
reply.ignoreSslErrors()
@ -107,8 +106,7 @@ class NetworkAccessManager(QNetworkAccessManager):
'contentType': reply.header(QNetworkRequest.ContentTypeHeader),
'redirectURL': reply.header(QNetworkRequest.LocationHeader),
'headers': headers,
'time': QDateTime.currentDateTime(),
'text': reply.body()
'time': QDateTime.currentDateTime()
}
del self.m_ids[reply]

View File

@ -1,111 +0,0 @@
'''
This file is part of the PyPhantomJS project.
Copyright (C) 2011 James Roe <roejames12@hotmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply
class NetworkReplyProxy(QNetworkReply):
def __init__(self, parent, reply):
super(NetworkReplyProxy, self).__init__(parent)
self.m_reply = reply
self.m_buffer = self.m_data = ''
# apply attributes
self.setOperation(self.m_reply.operation())
self.setRequest(self.m_reply.request())
self.setUrl(self.m_reply.url())
# handle these to forward
self.m_reply.metaDataChanged.connect(self.applyMetaData)
self.m_reply.readyRead.connect(self.readInternal)
self.m_reply.error.connect(self.errorInternal)
# forward signals
self.m_reply.finished.connect(self.finished)
self.m_reply.uploadProgress.connect(self.uploadProgress)
self.m_reply.downloadProgress.connect(self.downloadProgress)
# for the data proxy...
self.setOpenMode(QNetworkReply.ReadOnly)
def abort(self):
self.m_reply.abort()
def applyMetaData(self):
for header in self.m_reply.rawHeaderList():
self.setRawHeader(header, self.m_reply.rawHeader(header))
self.setHeader(QNetworkRequest.ContentTypeHeader, self.m_reply.header(QNetworkRequest.ContentTypeHeader))
self.setHeader(QNetworkRequest.ContentLengthHeader, self.m_reply.header(QNetworkRequest.ContentLengthHeader))
self.setHeader(QNetworkRequest.LocationHeader, self.m_reply.header(QNetworkRequest.LocationHeader))
self.setHeader(QNetworkRequest.LastModifiedHeader, self.m_reply.header(QNetworkRequest.LastModifiedHeader))
# :NOTE: This statement is commented due to a bug in PyQt where the cookie headers can't be set correctly due to
# the cookie header expecting QList, but Python Lists are auto-converted to QVariantList, and it is incompatible.
# This bug should be fixed in PyQt 4.8, however we need to maintain backward compatibility with 4.7
# [WARNING] QNetworkRequest::setHeader: QVariant of type QVariantList cannot be used with header Set-Cookie
#self.setHeader(QNetworkRequest.SetCookieHeader, self.m_reply.header(QNetworkRequest.SetCookieHeader))
self.setAttribute(QNetworkRequest.HttpStatusCodeAttribute, self.m_reply.attribute(QNetworkRequest.HttpStatusCodeAttribute))
self.setAttribute(QNetworkRequest.HttpReasonPhraseAttribute, self.m_reply.attribute(QNetworkRequest.HttpReasonPhraseAttribute))
self.setAttribute(QNetworkRequest.RedirectionTargetAttribute, self.m_reply.attribute(QNetworkRequest.RedirectionTargetAttribute))
self.setAttribute(QNetworkRequest.ConnectionEncryptedAttribute, self.m_reply.attribute(QNetworkRequest.ConnectionEncryptedAttribute))
self.setAttribute(QNetworkRequest.CacheLoadControlAttribute, self.m_reply.attribute(QNetworkRequest.CacheLoadControlAttribute))
self.setAttribute(QNetworkRequest.CacheSaveControlAttribute, self.m_reply.attribute(QNetworkRequest.CacheSaveControlAttribute))
self.setAttribute(QNetworkRequest.SourceIsFromCacheAttribute, self.m_reply.attribute(QNetworkRequest.SourceIsFromCacheAttribute))
self.setAttribute(QNetworkRequest.DoNotBufferUploadDataAttribute, self.m_reply.attribute(QNetworkRequest.DoNotBufferUploadDataAttribute))
self.metaDataChanged.emit()
def body(self):
return str(self.m_data)
def bytesAvailable(self):
return len(self.m_buffer) + self.m_reply.bytesAvailable()
def bytesToWrite(self):
return -1
def close(self):
self.m_reply.close()
def errorInternal(self, error):
self.setError(error, str(error))
self.error.emit(error)
def ignoreSslErrors(self):
self.m_reply.ignoreSslErrors()
def isSequential(self):
return self.m_reply.isSequential()
def readData(self, maxlen):
size = min(maxlen, len(self.m_buffer))
data, self.m_buffer = self.m_buffer[:size], self.m_buffer[size:]
return str(data)
def readInternal(self):
data = self.m_reply.readAll()
self.m_data += data
self.m_buffer += data
self.readyRead.emit()
def setReadBufferSize(self, size):
QNetworkReply.setReadBufferSize(size)
self.m_reply.setReadBufferSize(size)

View File

@ -38,7 +38,6 @@
#include "config.h"
#include "cookiejar.h"
#include "networkaccessmanager.h"
#include "networkreplyproxy.h"
static const char *toString(QNetworkAccessManager::Operation op)
{
@ -129,7 +128,7 @@ QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkR
connect(reply, SIGNAL(readyRead()), this, SLOT(handleStarted()));
emit resourceRequested(data);
return new NetworkReplyProxy(this, reply);
return reply;
}
void NetworkAccessManager::handleStarted()
@ -186,9 +185,6 @@ void NetworkAccessManager::handleFinished(QNetworkReply *reply)
data["headers"] = headers;
data["time"] = QDateTime::currentDateTime();
NetworkReplyProxy *nrp = qobject_cast<NetworkReplyProxy*>(reply);
data["text"] = nrp->body();
m_ids.remove(reply);
m_started.remove(reply);

View File

@ -1,149 +0,0 @@
/*
This file is part of the PhantomJS project from Ofi Labs.
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <QNetworkRequest>
#include <QNetworkReply>
#include "networkreplyproxy.h"
NetworkReplyProxy::NetworkReplyProxy(QObject* parent, QNetworkReply* reply)
: QNetworkReply(parent)
, m_reply(reply)
{
// apply attributes...
setOperation(m_reply->operation());
setRequest(m_reply->request());
setUrl(m_reply->url());
// handle these to forward
connect(m_reply, SIGNAL(metaDataChanged()), SLOT(applyMetaData()));
connect(m_reply, SIGNAL(readyRead()), SLOT(readInternal()));
connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(errorInternal(QNetworkReply::NetworkError)));
// forward signals
connect(m_reply, SIGNAL(finished()), SIGNAL(finished()));
connect(m_reply, SIGNAL(uploadProgress(qint64,qint64)), SIGNAL(uploadProgress(qint64,qint64)));
connect(m_reply, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(downloadProgress(qint64,qint64)));
// for the data proxy...
setOpenMode(ReadOnly);
}
NetworkReplyProxy::~NetworkReplyProxy()
{
if (m_reply)
delete m_reply;
}
QString NetworkReplyProxy::body()
{
return QString(m_data);
}
void NetworkReplyProxy::abort()
{
if (m_reply)
m_reply->abort();
}
void NetworkReplyProxy::close()
{
if (m_reply)
m_reply->close();
}
bool NetworkReplyProxy::isSequential() const
{
return m_reply->isSequential();
}
void NetworkReplyProxy::setReadBufferSize(qint64 size)
{
QNetworkReply::setReadBufferSize(size); m_reply->setReadBufferSize(size);
}
qint64 NetworkReplyProxy::bytesAvailable() const
{
return m_buffer.size() + QIODevice::bytesAvailable();
}
qint64 NetworkReplyProxy::bytesToWrite() const
{
return -1;
}
qint64 NetworkReplyProxy::readData(char* data, qint64 maxlen)
{
qint64 size = qMin(maxlen, qint64(m_buffer.size()));
memcpy(data, m_buffer.constData(), size);
m_buffer.remove(0, size);
return size;
}
void NetworkReplyProxy::ignoreSslErrors()
{
m_reply->ignoreSslErrors();
}
void NetworkReplyProxy::applyMetaData()
{
QList<QByteArray> headers = m_reply->rawHeaderList();
foreach(QByteArray header, headers)
setRawHeader(header, m_reply->rawHeader(header));
setHeader(QNetworkRequest::ContentTypeHeader, m_reply->header(QNetworkRequest::ContentTypeHeader));
setHeader(QNetworkRequest::ContentLengthHeader, m_reply->header(QNetworkRequest::ContentLengthHeader));
setHeader(QNetworkRequest::LocationHeader, m_reply->header(QNetworkRequest::LocationHeader));
setHeader(QNetworkRequest::LastModifiedHeader, m_reply->header(QNetworkRequest::LastModifiedHeader));
setHeader(QNetworkRequest::SetCookieHeader, m_reply->header(QNetworkRequest::SetCookieHeader));
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute));
setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, m_reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute));
setAttribute(QNetworkRequest::RedirectionTargetAttribute, m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute));
setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, m_reply->attribute(QNetworkRequest::ConnectionEncryptedAttribute));
setAttribute(QNetworkRequest::CacheLoadControlAttribute, m_reply->attribute(QNetworkRequest::CacheLoadControlAttribute));
setAttribute(QNetworkRequest::CacheSaveControlAttribute, m_reply->attribute(QNetworkRequest::CacheSaveControlAttribute));
setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, m_reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute));
setAttribute(QNetworkRequest::DoNotBufferUploadDataAttribute, m_reply->attribute(QNetworkRequest::DoNotBufferUploadDataAttribute));
emit metaDataChanged();
}
void NetworkReplyProxy::errorInternal(QNetworkReply::NetworkError _error)
{
setError(_error, errorString());
emit error(_error);
}
void NetworkReplyProxy::readInternal()
{
QByteArray data = m_reply->readAll();
m_data += data;
m_buffer += data;
emit readyRead();
}

View File

@ -1,69 +0,0 @@
/*
This file is part of the PhantomJS project from Ofi Labs.
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NETWORKREPLYPROXY_H
#define NETWORKREPLYPROXY_H
#include <QNetworkReply>
#include <QPointer>
class NetworkReplyProxy : public QNetworkReply {
Q_OBJECT
public:
NetworkReplyProxy(QObject* parent, QNetworkReply* reply);
~NetworkReplyProxy();
void abort();
void close();
bool isSequential() const;
QString body();
// not possible...
void setReadBufferSize(qint64 size);
// QIODevice proxy...
virtual qint64 bytesAvailable() const;
virtual qint64 bytesToWrite() const;
virtual qint64 readData(char* data, qint64 maxlen);
public Q_SLOTS:
void ignoreSslErrors();
void applyMetaData();
void errorInternal(QNetworkReply::NetworkError _error);
void readInternal();
private:
QPointer<QNetworkReply> m_reply;
QByteArray m_data;
QByteArray m_buffer;
};
#endif // NETWORKREPLYPROXY_H

View File

@ -15,7 +15,6 @@ HEADERS += csconverter.h \
webpage.h \
consts.h \
utils.h \
networkreplyproxy.h \
networkaccessmanager.h \
cookiejar.h \
filesystem.h \
@ -27,7 +26,6 @@ SOURCES += phantom.cpp \
main.cpp \
csconverter.cpp \
utils.cpp \
networkreplyproxy.cpp \
networkaccessmanager.cpp \
cookiejar.cpp \
filesystem.cpp \