コード例 #1
0
ファイル: loginer.py プロジェクト: mopperwhite/tiebasigner
 def __init__(self,name,url,cookiefile=None,parent=None):
         super(QListWidgetItem,self).__init__(name,parent)
         #~ super(QObject,self).__init__(parent)
         self.loggedin=False
         #~ print name,cookiefile
         self.cookiefile=cookiefile=name+".cookies" if cookiefile is None else cookiefile
         self.name=name
         self.cookiejar=None
         self.view=LoginWindow(url,cookiefile)
         self.view.setWindowTitle(u"登录:"+name)
         self.dialog=LoginListWindow._Dialog(parent)
         self.show_msg=pyqtSlot(unicode,unicode)
コード例 #2
0
class ErtNotifier(QObject):
    ertChanged = pyqtSignal()

    def __init__(self, ert, config_file, parent=None):
        QObject.__init__(self, parent)
        self._ert = ert
        self._config_file = config_file

    def _checkErt(self):
        if self._ert is None:
            raise ValueError("Ert is undefined.")

    @property
    def ert(self):
        """ @rtype: EnKFMain """
        self._checkErt()
        return self._ert

    @property
    def config_file(self):
        """ @rtype: str """
        self._checkErt()
        return self._config_file

    pyqtSlot()

    def emitErtChange(self):
        print("Emitting ertChanged() - source: %s" % self.sender())
        self._checkErt()
        self.ertChanged.emit()

    pyqtSignal()

    def reloadERT(self, config_file):
        import sys
        import os
        python_executable = sys.executable
        ert_gui_main = sys.argv[0]

        self._ert.free()
        os.execl(python_executable, python_executable, ert_gui_main,
                 config_file)
コード例 #3
0
class HTTPProxy(QObject):

    debug = True
    log = sys.stderr
    username = '******'
    password = '******'
    stopServing = pyqtSlot()

    def __init__(self, parent=None):
        super(HTTPProxy, self).__init__(parent)
        self.proxy_server = QTcpServer(self)
        self.proxy_server.listen(QHostAddress.Any, 8000)
        self.proxy_server.newConnection.connect(self.manage_request)

        if self.debug:
            self.log.write('Proxy server running on 0.0.0.0 port %s\n\n' %
                           self.port())

    def port(self):
        return self.proxy_server.serverPort()

    def addr(self):
        return self.proxy_server.serverAddress().toString()

    def stopServing(self):
        if self.debug:
            self.log.write('Service is stopping...\n\n')

        # does not "close" the server, just stop listening...
        self.proxy_server.close()

        if self.proxy_server.hasPendingConnections():
            socket = self.proxy_server.nextPendingConnection()
            while socket:
                socket.abort()
                socket = self.proxy_server.nextPendingConnection()

    def manage_request(self):
        proxy_server = self.sender()
        # Qt docs says that the caller of nextPendingConnection()
        # is the parent of the socket
        socket = proxy_server.nextPendingConnection()
        socket.readyRead.connect(self.process_request)
        socket.disconnected.connect(socket.deleteLater)

    def authorize_request(self, request_data):
        return True
        header = QHttpRequestHeader(QString(request_data))
        if self.debug:
            self.log.write(header.toString())

        auth = header.value('Proxy-Authorization')
        if not auth:
            return False

        challenge = base64.b64encode(self.username + ':' + self.password)
        return challenge == str(auth).split()[1]

    def process_request(self):
        socket = self.sender()
        request_data = socket.readAll()

        if not self.authorize_request(request_data):
            socket.write('HTTP/1.1 407 Proxy Authentication Required\r\n')
            if self.debug:
                self.log.write('407 Proxy Authentication Required\n\n')
            socket.write('Proxy-Authenticate: Basic realm="test"\r\n')
            socket.write('\r\n')
            socket.disconnectFromHost()
            return
        else:
            # remove Proxy-Authorization header
            start = request_data.indexOf('Proxy-Authorization:')
            end = request_data.lastIndexOf('\r\n')
            request_data.remove(start, end)
            request_data.append('\r\n')

        pos = request_data.indexOf('\r\n')
        request_line = request_data.left(pos)
        request_data.remove(0, pos + 2)

        entries = request_line.split(' ')
        method = entries[0]
        address = entries[1]
        version = entries[2]
        port = '80'

        if address.count(':') > 1:
            protocol, host, port = address.split(':')
        else:
            protocol, host = address.split(':')

        print 'address', address

        #url = QUrl( protocol + host )
        url = QUrl.fromEncoded(address)
        #url.setHost( host )
        #url.setPort( int(port) )

        if not url.isValid():
            if self.debug:
                self.log.write('Invalid URL: %s\n\n', url)
            socket.disconnectFromHost()
            return

        host = url.host()
        port = 80 if (url.port() < 0) else url.port()
        req = url.encodedPath()
        if url.hasQuery():
            req.append('?').append(url.encodedQuery())
        request_line = method + ' ' + req + ' ' + version + '\r\n'
        request_data.prepend(request_line)

        if self.debug:
            self.log.write(method + ' ' + address + ' ' + version + '\n\n')

        key = host + ':' + QString.number(port)
        proxy_socket = socket.findChild(QTcpSocket, key)
        if proxy_socket:
            proxy_socket.setObjectName(key)
            proxy_socket.setProperty('url', url)
            proxy_socket.setProperty('request_data', request_data)
            proxy_socket.write(request_data)
        else:
            proxy_socket = QTcpSocket(socket)
            proxy_socket.setObjectName(key)
            proxy_socket.setProperty('url', url)
            proxy_socket.setProperty('request_data', request_data)
            proxy_socket.connected.connect(self.send_request)
            proxy_socket.readyRead.connect(self.transfer_data)
            proxy_socket.disconnected.connect(self.close_connection)
            proxy_socket.error.connect(self.close_connection)
            proxy_socket.connectToHost(host, port)

    def send_request(self):
        proxy_socket = self.sender()
        request_data = proxy_socket.property('request_data').toByteArray()
        proxy_socket.write(request_data)

    def transfer_data(self):
        proxy_socket = self.sender()
        socket = proxy_socket.parent()
        socket.write(proxy_socket.readAll())

    def close_connection(self):
        proxy_socket = self.sender()
        if proxy_socket:
            socket = proxy_socket.parent()
            if isinstance(socket, QTcpSocket) and socket:
                socket.disconnectFromHost()
            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()
コード例 #4
0
ファイル: user_profiles.py プロジェクト: yangmaoer/DsgTools
    def saveUserState(self):
        """
        Saves the user state.
        The assigned and installed profiles are updated for the current selected user
        """
        if self.comboBox.currentIndex() == 0:
            return

        user = self.comboBox.currentText()
        grant = []
        revoke = []
        profiles1 = []
        for i in range(self.assignedProfiles.__len__()):
            role = self.assignedProfiles.item(i).text()
            profiles1.append(role)
            
        for role in profiles1:
            if role not in self.assigned:
                grant.append(role)

        profiles2 = []
        for i in range(self.installedProfiles.__len__()):
            role = self.installedProfiles.item(i).text()
            profiles2.append(role)
            
        for role in profiles2:
            if role not in self.installed:
                revoke.append(role)
            
        for role in grant:
            try:
                self.widget.abstractDb.grantRole(user, role)
            except Exception as e:
                QtGui.QMessageBox.critical(self, self.tr('Critical!'), e.args[0])
                self.getProfiles(user)
                return

        for role in revoke:
            try:
                self.widget.abstractDb.revokeRole(user, role)
            except Exception as e:
                QtGui.QMessageBox.critical(self, self.tr('Critical!'), ':'.join(e.args)
                self.getProfiles(user)
                return

        self.getProfiles(user)
        QtGui.QMessageBox.warning(self, self.tr('Warning!'), self.tr('User updated successfully!'))
        
    @pyqtSlot(bool)
    def on_closeButton_clicked(self):
        """
        Closes the dialog
        """
        self.close()
        
    @pyqtSlot(bool)
    def on_insertAllButton_clicked(self):
        """
        Slot to assign all profiles
        """
        tam = self.installedProfiles.__len__()
        if tam == 0:
            QtGui.QMessageBox.warning(self, self.tr('Warning!'), self.tr('No profiles installed! Install at least one and try again.'))
            return
        
        for i in range(tam+1,1,-1):
            item = self.installedProfiles.takeItem(i-2)
            self.assignedProfiles.addItem(item)
        self.assignedProfiles.sortItems()
        
        self.saveUserState()

    @pyqtSlot(bool)
    def on_removeAllButton_clicked(self):
        """
        Slot to remove all assigned profiles
        """
        tam = self.assignedProfiles.__len__()
        if tam == 0:
            QtGui.QMessageBox.warning(self, self.tr('Warning!'), self.tr('No profiles assigned! Assign at least one and try again.'))
            return
        
        for i in range(tam+1,1,-1):
            item = self.assignedProfiles.takeItem(i-2)
            self.installedProfiles.addItem(item)
        self.installedProfiles.sortItems()

        self.saveUserState()

    @pyqtSlot(bool)
    def on_insertButton_clicked(self):
        """
        Slot to assign a profile
        """
        listedItems = self.installedProfiles.selectedItems()
        if len(listedItems) == 0:
            QtGui.QMessageBox.warning(self, self.tr('Warning!'), self.tr('Select a profile first!'))
            return
        
        for i in listedItems:
            item = self.installedProfiles.takeItem(self.installedProfiles.row(i))
            self.assignedProfiles.addItem(item)
        self.assignedProfiles.sortItems()

        self.saveUserState()

    @pyqtSlot(bool)
    def on_removeButton_clicked(self):
        """
        Slot to remove a assigned profile
        """
        listedItems = self.assignedProfiles.selectedItems()
        if len(listedItems) == 0:
            QtGui.QMessageBox.warning(self, self.tr('Warning!'), self.tr('Select a profile first!'))
            return
        
        for i in listedItems:
            item = self.assignedProfiles.takeItem(self.assignedProfiles.row(i))
            self.installedProfiles.addItem(item)
        self.installedProfiles.sortItems()

        self.saveUserState()
コード例 #5
0
ファイル: Task.py プロジェクト: yshao/weathergit

class TestTask(TaskImpl):
    ""

class FabricTask(TaskImpl):
    ""

class ShellTask(TaskImpl):
    ""

class SmapUtilTask(TaskImpl):
    ""

class ConnTask(TaskImpl):
    ""

class OperatorTask(TaskImpl):
    ""

class FtpTask(TaskImpl):
    ""

    def run(self):
        ""


ftask=Task(run=fc.client.fetch,params=())

pyqtSlot()
guiUpdate(get_data())