本文整理汇总了Python中PyQt4.QtNetwork.QNetworkProxy.setPort方法的典型用法代码示例。如果您正苦于以下问题:Python QNetworkProxy.setPort方法的具体用法?Python QNetworkProxy.setPort怎么用?Python QNetworkProxy.setPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtNetwork.QNetworkProxy
的用法示例。
在下文中一共展示了QNetworkProxy.setPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configureProxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def configureProxy(self, host, port, user=None, password=None):
"""Add a proxy configuration for the Network Requests.
:param host: the proxy host
:param port: the proxy port
:param user: if the proxy has authentication this param sets
the user to be used. It should be None if it's not required to
access with a user
:param password: if the proxy has authentication this param sets
the password to be used. It should be None if it's not required to
access with a password
"""
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName(host)
proxy.setPort(port)
if user is not None:
proxy.setUser(user)
if password is not None:
proxy.setPassword(password)
self._proxyAuth = (user, password)
self.setProxy(proxy)
示例2: get_proxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def get_proxy():
"""Adaption by source of Plugin Installer - Version 1.0.10"""
settings = QSettings()
settings.beginGroup("proxy")
if settings.value("/proxyEnabled", False, type=bool):
proxy = QNetworkProxy()
proxyType = settings.value("/proxyType", 0, type=int)
if proxyType in ["1", "Socks5Proxy"]:
proxy.setType(QNetworkProxy.Socks5Proxy)
elif proxyType in ["2", "NoProxy"]:
proxy.setType(QNetworkProxy.NoProxy)
elif proxyType in ["3", "HttpProxy"]:
proxy.setType(QNetworkProxy.HttpProxy)
elif proxyType in ["4", "HttpCachingProxy"] and QT_VERSION >= 0X040400:
proxy.setType(QNetworkProxy.HttpCachingProxy)
elif proxyType in ["5", "FtpCachingProxy"] and QT_VERSION >= 0X040400:
proxy.setType(QNetworkProxy.FtpCachingProxy)
else:
proxy.setType(QNetworkProxy.DefaultProxy)
proxy.setHostName(settings.value("/proxyHost"))
proxy.setPort(settings.value("/proxyPort", type=int))
proxy.setUser(settings.value("/proxyUser"))
proxy.setPassword(settings.value("/proxyPassword"))
settings.endGroup()
return proxy
示例3: get_proxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def get_proxy():
"""
Get a proxy according to QSettings
@return: proxy
@rtype: QNetworkProxy
"""
s = QSettings()
if s.value('proxy/proxyEnabled', '') == 'true':
proxy_type = s.value('proxy/proxyType', '')
proxy_host = s.value('proxy/proxyHost', '')
proxy_port = s.value('proxy/proxyPort', '')
proxy_user = s.value('proxy/proxyUser', '')
proxy_password = s.value('proxy/proxyPassword', '')
proxy = QNetworkProxy()
if proxy_type == 'DefaultProxy':
proxy.setType(QNetworkProxy.DefaultProxy)
elif proxy_type == 'Socks5Proxy':
proxy.setType(QNetworkProxy.Socks5Proxy)
elif proxy_type == 'HttpProxy':
proxy.setType(QNetworkProxy.HttpProxy)
elif proxy_type == 'HttpCachingProxy':
proxy.setType(QNetworkProxy.HttpCachingProxy)
elif proxy_type == 'FtpCachingProxy':
proxy.setType(QNetworkProxy.FtpCachingProxy)
proxy.setHostName(proxy_host)
proxy.setPort(int(proxy_port))
proxy.setUser(proxy_user)
proxy.setPassword(proxy_password)
return proxy
else:
return None
示例4: set_proxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def set_proxy(self, string_proxy):
"""Set proxy [http|socks5]://username:[email protected]:port"""
urlinfo = urlparse.urlparse(string_proxy)
proxy = QNetworkProxy()
if urlinfo.scheme == 'socks5' :
proxy.setType(1)
elif urlinfo.scheme == 'http' :
proxy.setType(3)
else :
proxy.setType(2)
self.manager.setProxy(proxy)
return self.manager.proxy()
proxy.setHostName(urlinfo.hostname)
proxy.setPort(urlinfo.port)
if urlinfo.username != None :
proxy.setUser(urlinfo.username)
else :
proxy.setUser('')
if urlinfo.password != None :
proxy.setPassword(urlinfo.password)
else :
proxy.setPassword('')
self.manager.setProxy(proxy)
return self.manager.proxy()
示例5: setUp
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def setUp(self):
if len(argv) == 2:
site = argv[1]
else:
site = None
options = extract_options(site)
if options['cookie_file'] is not None:
options['cookie_file'] = (
expanduser("~/.eilat/cookies/") + options['cookie_file'])
# Proxy
if options['use_proxy']:
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName('localhost')
proxy.setPort(3128)
QNetworkProxy.setApplicationProxy(proxy)
self.mainwin = MainWin(clipboard=CLIPBOARD, options=options, parent=None)
if site:
self.mainwin.add_tab(site)
else:
self.mainwin.add_tab()
self.mainwin.show()
示例6: setTempProxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def setTempProxy(self, host, port=None, username=None, password=None):
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.HttpProxy)
if username:
proxy.setUser(username)
if password:
proxy.setPassword(password)
if port:
proxy.setPort(port)
proxy.setHostName(host)
self.page().networkAccessManager().setProxy(proxy)
示例7: prox
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def prox(self,mode,user,password,host,port):
proxy = QNetworkProxy()
if mode == "DefaultProxy":
proxy.setType(QNetworkProxy.DefaultProxy)
elif mode == "Socks5Proxy":
proxy.setType(QNetworkProxy.Socks5Proxy)
proxy.setHostName(host)
proxy.setPort(int(port))
proxy.setUser(self.usern)
proxy.setPassword(self.passw)
QNetworkProxy.setApplicationProxy(proxy)
elif mode == "HttpProxy":
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName(host)
proxy.setPort(int(port))
proxy.setUser(self.usern)
proxy.setPassword(self.passw)
QNetworkProxy.setApplicationProxy(proxy)
elif mode == "HttpCachingProxy":
proxy.setType(QNetworkProxy.HttpCachingProxy)
proxy.setHostName(host)
proxy.setPort(int(port))
proxy.setUser(self.usern)
proxy.setPassword(self.passw)
QNetworkProxy.setApplicationProxy(proxy)
elif mode == "FtpCachingProxy":
proxy.setType(QNetworkProxy.FtpCachingProxy)
proxy.setHostName(host)
proxy.setPort(int(port))
proxy.setUser(self.usern)
proxy.setPassword(self.passw)
QNetworkProxy.setApplicationProxy(proxy)
示例8: __set_proxy_slot
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def __set_proxy_slot(self, host, port):
proxy = QNetworkProxy()
if not host:
proxy.setType(QNetworkProxy.NoProxy)
else:
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName(host)
proxy.setPort(port)
self.__web_view.page().networkAccessManager().setProxy(proxy)
self.__set_proxy_condition.acquire()
self.__set_proxy_condition.notifyAll()
self.__set_proxy_condition.release()
示例9: applySettings
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def applySettings(self):
if self.feedView.siteServer.session.user != str(self.ffNickname.text()) or self.feedView.siteServer.session.remoteKey != str(self.ffRemoteKey.text()):
self.feedView.siteServer.session.user = str(self.ffNickname.text())
self.feedView.siteServer.session.remoteKey = str(self.ffRemoteKey.text())
self.feedView.goHome()
proxy = QNetworkProxy()
proxyType = self.proxyType.currentIndex()
proxy.setType( (proxyType == 2) and QNetworkProxy.Socks5Proxy or ( (proxyType == 1) and QNetworkProxy.HttpProxy or QNetworkProxy.NoProxy ) )
if proxyType:
proxy.setHostName(self.proxyHost.text())
proxy.setPort(self.proxyPort.value())
if self.proxyAuth.checkState() == Qt.Checked:
proxy.setUser(self.proxyAuthUser.text())
proxy.setPassword(self.proxyAuthPassword.text())
QNetworkProxy.setApplicationProxy(proxy)
示例10: get_proxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def get_proxy():
"""Adaption by source of Plugin Installer - Version 1.0.10
:returns: Get proxy that currently used.
:rtype: QNetworkProxy
"""
settings = QSettings()
settings.beginGroup('proxy')
enabled = settings.value('/proxyEnabled', False, type=bool)
if not enabled:
return None
proxy = QNetworkProxy()
try:
proxy_type = settings.value('/proxyType', 0, type=int)
except TypeError:
# Catch for this:
# TypeError: unable to convert a QVariant of type 10 to a
# QMetaType of type 2
# TODO: can we do anything to handle this more gracefully? TS
settings.setValue('/proxyType', 0)
return proxy
if proxy_type in ['1', 'Socks5Proxy']:
proxy.setType(QNetworkProxy.Socks5Proxy)
elif proxy_type in ['2', 'NoProxy']:
proxy.setType(QNetworkProxy.NoProxy)
elif proxy_type in ['3', 'HttpProxy']:
proxy.setType(QNetworkProxy.HttpProxy)
elif proxy_type in ['4', 'HttpCachingProxy'] and QT_VERSION >= 0X040400:
proxy.setType(QNetworkProxy.HttpCachingProxy)
elif proxy_type in ['5', 'FtpCachingProxy'] and QT_VERSION >= 0X040400:
proxy.setType(QNetworkProxy.FtpCachingProxy)
else:
proxy.setType(QNetworkProxy.DefaultProxy)
proxy.setHostName(settings.value('/proxyHost'))
proxy.setPort(settings.value('/proxyPort', type=int))
user = settings.value('/proxyUser', type=str)
password = settings.value('/proxyPassword', type=str)
if user is not None:
proxy.setUser(user)
if password is not None and user is not None:
proxy.setPassword(password)
settings.endGroup()
return proxy
示例11: configure_proxy
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def configure_proxy(cls, hostname, port, user=None, password=None,
proxy_type=QNetworkProxy.HttpProxy):
"""
Configure network proxy layer.
@param proxy_type: see QNetworkProxy.ProxyType. Default: HttpProxy.
@param hostname: Proxy hostname.
@param port: Proxy port.
@param username: Proxy username (optional).
@param passwrod: Proxy password (optional).
"""
proxy = QNetworkProxy()
proxy.setType(proxy_type)
proxy.setHostName(hostname)
proxy.setPort(port)
if user and password is not None:
proxy.setUser(user)
proxy.setPassword(password)
QNetworkProxy.setApplicationProxy(proxy);
示例12: main
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def main():
""" Catch the url (if any); then choose adequate defaults and build
a browser window. Save cookies, if appropiate, at close.
"""
# Considerations:
# Will use proxy? (if not google, fb, twitter... then yes)
use_proxy = True
# Which whitelist will use instead?
host_whitelist = None
# Will allow cookies? Which? Where are they saved?
cookie_allow = ["github.com", "linkedin.com", "freerepublic.com"]
cookie_file = None
prefix = ""
if len(argv) == 2:
sitio = argv[1]
if (sitio.split('.')[-2:] == ["facebook","com"]):
use_proxy = False
host_whitelist = ["facebook.com", "akamaihd.net", "fbcdn.net"]
cookie_allow = ["facebook.com"]
cookie_file = "fbcookies.cj"
prefix = "FB"
elif (sitio.split('.')[-2:] == ["twitter","com"]):
use_proxy = False
host_whitelist = ["twitter.com", "twimg.com"]
cookie_allow = ["twitter.com"]
cookie_file = "twcookies.cj"
prefix = "TW"
elif (sitio.split('.')[-2:] == ["google","com"]):
print "GOOGLE"
use_proxy = False
host_whitelist = [
"google.com",
"google.com.mx",
"googleusercontent.com",
"gstatic.com",
"googleapis.com"]
cookie_allow = ["google.com"]
cookie_file = "gcookies.cj"
prefix = "G"
else:
print "GENERAL"
else:
sitio = None
print "EMPTY"
# Proxy
if use_proxy:
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName('localhost')
proxy.setPort(3128)
QNetworkProxy.setApplicationProxy(proxy)
app = QtGui.QApplication([])
clipboard = app.clipboard()
db_log = DatabaseLog()
netmanager = InterceptNAM(
parent = app, name = prefix,
log = db_log, whitelist = host_whitelist)
cookiejar = CookieJar(
parent = app, allowed = cookie_allow, storage = cookie_file)
netmanager.setCookieJar(cookiejar)
app.setApplicationName("Eilat")
app.setApplicationVersion("1.2.002")
mainwin = MainWin(netmanager, clipboard)
if sitio:
mainwin.add_tab(sitio)
else:
mainwin.add_tab()
mainwin.show()
def end_call():
""" The browser is closing - save cookies, if required.
"""
print "END"
if cookie_file:
print "SAVING COOKIES"
with open(cookie_file, "w") as savefile:
for cookie in cookiejar.allCookies():
savefile.write(cookie.toRawForm()+"\n")
app.lastWindowClosed.connect(end_call)
app.exec_()
示例13: __init__
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def __init__(self, parent = None):
QMainWindow.__init__(self, parent)
self.setWindowTitle("FeedLol")
self.aboutAction = QAction(QIcon("data/icons/help-about.svg"), "&About FeedLol...", self)
self.connect(self.aboutAction, SIGNAL("triggered()"), self.slotAbout)
self.reloadAction = QAction(QIcon("data/icons/view-refresh.svg"), "&Reload", self)
self.reloadAction.setShortcut(QKeySequence.Refresh)
self.homeAction = QAction(QIcon("data/icons/go-home.svg"), "Go &Home", self)
self.homeAction.setShortcut("Alt+Home")
self.userAction = QAction(QIcon("data/icons/user-identity.svg"), "&Me", self)
self.userAction.setShortcut("Ctrl+M")
self.logoutAction = QAction(QIcon("data/icons/dialog-close.svg"), "Log&out", self)
self.logoutAction.setShortcut(QKeySequence.Close)
self.settingsAction = QAction(QIcon("data/icons/configure.svg"), "&Preferences...", self)
self.connect(self.settingsAction, SIGNAL("triggered()"), self.slotSettings)
self.toolbar = QToolBar("Toolbar", self)
self.toolbar.setObjectName("toolbar")
self.toolbar.addAction(self.homeAction)
self.toolbar.addAction(self.userAction)
self.toolbar.addAction(self.reloadAction)
self.toolbar.addSeparator()
self.toolbar.addAction(self.logoutAction)
self.toolbar.addSeparator()
self.toolbar.addAction(self.settingsAction)
self.toolbar.addAction(self.aboutAction)
self.addToolBar(self.toolbar)
self.loadStatus = QProgressBar(self)
self.loadStatus.setRange(0, 100)
self.loadStatus.setMaximumWidth(200)
self.loadStatus.setTextVisible(False)
self.loadStatus.hide()
self.statusBar().addPermanentWidget(self.loadStatus)
self.feedView = FeedView(self)
self.setCentralWidget(self.feedView)
self.connect(self.feedView, SIGNAL("titleChanged(const QString&)"), self.slotSetTitle)
self.connect(self.feedView, SIGNAL("statusBarMessage(const QString&)"), self.statusBar(), SLOT("showMessage(const QString&)"))
self.connect(self.feedView, SIGNAL("loadStarted()"), self.loadStart)
self.connect(self.feedView, SIGNAL("loadFinished(bool)"), self.loadStop)
self.connect(self.feedView, SIGNAL("loadProgress(int)"), self.loadProgress)
self.connect(self.reloadAction, SIGNAL("triggered()"), self.feedView.reload)
self.connect(self.homeAction, SIGNAL("triggered()"), self.feedView.goHome)
self.connect(self.userAction, SIGNAL("triggered()"), self.feedView.goToUserPage)
self.connect(self.logoutAction, SIGNAL("triggered()"), self.feedView.logout)
self.connect(self.feedView.page(), SIGNAL("linkHovered(const QString&, const QString&, const QString&)"), self.linkHovered)
self.settingsDialog = SettingsDialog(self.feedView, self)
settings = QSettings()
if settings.contains("proxy/type"):
proxy = QNetworkProxy()
proxyType = settings.value("proxy/type").toInt()[0]
proxy.setType( (proxyType == 2) and QNetworkProxy.Socks5Proxy or ( (proxyType == 1) and QNetworkProxy.HttpProxy or QNetworkProxy.NoProxy ) )
if proxy.type() != QNetworkProxy.NoProxy:
proxy.setHostName(settings.value("proxy/host").toString())
proxy.setPort(settings.value("proxy/port").toInt()[0])
if settings.value("proxy/user").toString():
proxy.setUser(settings.value("proxy/user").toString())
proxy.setPassword(settings.value("proxy/password").toString())
QNetworkProxy.setApplicationProxy(proxy)
if settings.contains("mainWindow/geometry"):
self.restoreGeometry(settings.value("mainWindow/geometry").toByteArray())
else:
self.resize(320,480)
if settings.contains("mainWindow/state"):
self.restoreState(settings.value("mainWindow/state").toByteArray())
self.feedView.goHome()
示例14: __init__
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
def __init__(self, parent, logger, db_conn, update_func, safe_conn):
super(TwitterGui, self).__init__(parent)
self._db_conn = db_conn
self.logger = logger
self._reply_to_id = 0
self._update_func = update_func
self._list = None
if get_settings().get_proxy():
u = urlparse.urlsplit(get_settings().get_proxy())
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName(u.hostname);
proxy.setPort(u.port)
QNetworkProxy.setApplicationProxy(proxy);
self.msgview = QWebView(self)
self.msgview.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.msgview.linkClicked.connect(self.link_clicked)
self.userCombo = QComboBox(self)
self.userCombo.setEditable(True)
self.userCombo.activated.connect(self.toggle_user_in_list)
self.showButton = QPushButton(chr(94), self)
self.showButton.setMaximumHeight(13)
self.showButton.clicked.connect(self.show_hide_animation)
self.post_field = QTextEdit(self)
self.post_field.setMaximumHeight(50)
self.post_field.textChanged.connect(self.text_changed)
self.send_button = QPushButton("Post", self)
self.send_button.clicked.connect(self.post_status_clicked)
self.refresh_button = QPushButton("Refresh", self)
self.refresh_button.clicked.connect(self._update_func)
self.attach_button = QPushButton("Attach", self)
self.attach_button.clicked.connect(lambda _ : self.set_status("Attach something"))
self.lists_box = QComboBox(self)
self.lists_box.currentIndexChanged.connect(self.list_changed)
self.lists_box.setEditable(False)
self.lists_box.addItems([u"Home"] + self._db_conn.get_lists())
self.statusLabel = QLabel("Status", self)
self.charCounter = QLabel("0", self)
self.gridw = QWidget(self)
self.gridw.setContentsMargins(0, 0, 0, 0)
gridlay = QGridLayout(self.gridw)
gridlay.setContentsMargins(0, 0, 0, 0)
gridlay.addWidget(self.post_field, 0, 0, 2, 1)
gridlay.addWidget(self.attach_button, 0, 1, 1, 1)
gridlay.addWidget(self.send_button, 1, 1, 1, 1)
gridlay.addWidget(self.lists_box, 0, 2, 1, 1)
gridlay.addWidget(self.refresh_button, 1, 2, 1, 1)
gridlay.addWidget(self.statusLabel, 2, 0, 1, 1)
gridlay.addWidget(self.charCounter, 2, 1, 1, 2)
hlay = QVBoxLayout(self)
hlay.addWidget(self.msgview)
hlay.addWidget(self.userCombo)
hlay.addWidget(self.showButton)
hlay.addWidget(self.gridw)
safe_conn.connect_home_timeline_updated(self.update_view)
safe_conn.connect_twitter_loop_started(self.start_refresh_animation)
safe_conn.connect_twitter_loop_stopped(self.stop_refresh_animation)
safe_conn.connect_update_posted(self.enable_posting)
safe_conn.connect_range_limit_exceeded(lambda _ : self.set_status("Range limit exceeded"))
safe_conn.connect_not_authenticated(lambda _ : self.set_status("Authentication failed"))
self.gridw.hide()
self.update_view()
self.set_status("Twitter plugin initialized")
示例15: QCoreApplication
# 需要导入模块: from PyQt4.QtNetwork import QNetworkProxy [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkProxy import setPort [as 别名]
if proxy_socket.error() != QTcpSocket.RemoteHostClosedError:
url = proxy_socket.property('url').toUrl()
error_string = proxy_socket.errorString()
if self.debug:
self.log.write('Error for %s %s\n\n' % (url, error_string))
proxy_socket.deleteLater()
if __name__ == '__main__':
app = QCoreApplication(sys.argv)
server = HTTPProxy()
manager = QNetworkAccessManager()
manager.finished.connect(server.stopServing)
manager.finished.connect(app.quit)
proxy = QNetworkProxy()
proxy.setType(QNetworkProxy.HttpProxy)
proxy.setHostName('127.0.0.1')
proxy.setPort(server.port())
proxy.setUser(server.username)
proxy.setPassword(server.password)
manager.setProxy(proxy)
reply = manager.get(QNetworkRequest(QUrl('http://aws.amazon.com/')))
sys.exit(app.exec_())