예제 #1
0
 def done(self, reply: QNetworkReply) -> None:
     if reply.error() != QNetworkReply.NoError:
         self.logger.error(reply.errorString())
         sys.stderr.write(reply.errorString())
         return
     if os.getenv('DEBUG', False):
         self.log_request(reply)
     # noinspection PyTypeChecker
     jsonobj = json.loads(str(reply.readAll(), 'utf-8'))
     reply.deleteLater()
     latest = parse_version(jsonobj.get('tag_name'))
     current = parse_version(qApp.applicationVersion())
     self.mbox.show_result(latest, current)
예제 #2
0
 def done(self, reply: QNetworkReply) -> None:
     if reply.error() != QNetworkReply.NoError:
         self.logger.error(reply.errorString())
         sys.stderr.write(reply.errorString())
         return
     if os.getenv('DEBUG', False):
         self.log_request(reply)
     try:
         jsonobj = loads(str(reply.readAll(), 'utf-8'))
         reply.deleteLater()
         latest = jsonobj.get('tag_name')
         current = qApp.applicationVersion()
         self.mbox.show_result(latest, current)
     except JSONDecodeError:
         self.logger.exception('Updater JSON decoding error', exc_info=True)
         raise
예제 #3
0
파일: ping.py 프로젝트: trinitymkt/memority
 def process_response(self, response: QNetworkReply):
     print(f'done {self.__class__.__name__}')
     if response.error() == QNetworkReply.NoError:
         self.finished.emit(True)
     else:
         print(response.errorString())
         self.finished.emit(False)
예제 #4
0
 def sendingFinished(reply: QNetworkReply) -> None:
     if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200:
         Logger.log(
             "e",
             "Received error code from printer when syncing material: {code}, {text}"
             .format(code=reply.attribute(
                 QNetworkRequest.HttpStatusCodeAttribute),
                     text=reply.errorString()))
예제 #5
0
    def _onGetRemoteMaterials(self, reply: QNetworkReply) -> None:
        # Got an error from the HTTP request. If we did not receive a 200 something happened.
        if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200:
            Logger.log("e", "Error fetching materials from printer: %s", reply.errorString())
            return

        # Collect materials from the printer's reply and send the missing ones if needed.
        remote_materials_by_guid = self._parseReply(reply)
        if remote_materials_by_guid:
            self._sendMissingMaterials(remote_materials_by_guid)
예제 #6
0
    def _onGetRemoteMaterials(self, reply: QNetworkReply) -> None:
        # Got an error from the HTTP request. If we did not receive a 200 something happened.
        if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200:
            Logger.log("e", "Error fetching materials from printer: %s",
                       reply.errorString())
            return

        # Collect materials from the printer's reply and send the missing ones if needed.
        remote_materials_by_guid = self._parseReply(reply)
        if remote_materials_by_guid:
            self._sendMissingMaterials(remote_materials_by_guid)
    def on_received_response(self, reply: QNetworkReply):
        if reply.error() != QNetworkReply.NoError:
            error_msg = "Unable to create new print share: {}".format(reply.errorString())
            logging.error(error_msg)
            app_settings.app_data_writer.signals.exchange_share_failed.emit(error_msg)
            return

        share_location = reply.rawHeader(QByteArray(bytes("Location", encoding="utf-8")))
        app_settings.app_data_writer.signals.exchange_share_created.emit(share_location.data().decode())
        reply.deleteLater()
        self.buffer.close()
예제 #8
0
 def _sendingFinished(self, reply: QNetworkReply) -> None:
     if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200:
         Logger.log("w", "Error while syncing material: %s", reply.errorString())
         return
     body = reply.readAll().data().decode('utf8')
     if "not added" in body:
         # For some reason the cluster returns a 200 sometimes even when syncing failed.
         return
     # Inform the user that materials have been synced. This message only shows itself when not already visible.
     # Because of the guards above it is not shown when syncing failed (which is not always an actual problem).
     MaterialSyncMessage(self.device).show()
예제 #9
0
 def _parse_result(self, reply: QNetworkReply) -> str:
     if reply.error():
         print(reply.errorString())
     print('parsing reply')
     text = 'no help available'
     try:
         text = bytes(reply.readAll()).decode('ascii', 'ignore')
     except Exception as e:
         print(e)
         pass
     return text
예제 #10
0
    def getResult(self, reply: QNetworkReply):
        error = reply.error()

        # request was successfully made
        if error == QNetworkReply.NoError:
            data = reply.readAll()
            self.successCallback(str(data, 'utf-8'))
        else:
            # request was failed
            errorStr = reply.errorString()
            self.errorCallback(errorStr)
예제 #11
0
 def done(self, reply: QNetworkReply):
     if reply.error() != QNetworkReply.NoError:
         sys.stderr.write(reply.errorString())
         return
     try:
         json_data = json.loads(str(reply.readAll(), 'utf-8'))
         reply.deleteLater()
         latest = json_data.get('tag_name')
         current = qApp.applicationVersion()
         self.parent.update_available(latest, current)
     except json.JSONDecodeError:
         self.logger.exception('Error retrieving data', exc_info=True)
         raise
예제 #12
0
    def saveServerFinished(self, reply: QNetworkReply):
        # if error on server occured
        if reply.error():
            QMessageBox.critical(self.app, 'Query error', reply.errorString())
            return

        try:
            data = loads(bytes(reply.readAll()))
            QMessageBox.information(self.app, 'Success query', data['message'])
        except Exception as e:
            QMessageBox.critical(self.app, 'Query error', 'Error in parsing')
            print(e)
            return

        # save path to clipboard
        cb: QClipboard = QApplication.clipboard()
        cb.setText(data['path'], mode=cb.Clipboard)
예제 #13
0
 def from_reply(cls, reply: QtNetwork.QNetworkReply) -> 'Response':
     """Slowly populates a new Response object with data from the request."""
     r = cls()
     
     # Signal mapping
     reply.metaDataChanged.connect(functools.partial(r._insert_headers, reply.rawHeaderPairs()))
     reply.redirected.connect(r._insert_url)
     reply.error.connect(r._update_code)
     reply.error.connect(functools.partial(r._update_error_string, reply.errorString()))
     
     # Wait until the request is finished before continuing
     signals.wait_for_signal(reply.finished)
     
     # Strip the remaining data from the reply, then mark it for deletion
     r._from_reply(reply)
     
     reply.close()
     reply.deleteLater()
     
     # Return the object
     return r
예제 #14
0
 def sendingFinished(reply: QNetworkReply) -> None:
     if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) != 200:
         Logger.log("e", "Received error code from printer when syncing material: {code}, {text}".format(
             code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute),
             text = reply.errorString()
         ))
예제 #15
0
 def process_reply(self, reply: QNetworkReply) -> Tuple[List[str], str]:
     return [], reply.errorString()