<commit_before>'''
Created on 16.11.2011

@author: michi
'''
from ems.qt4.location.maps.tiled.geotiledmapreply import GeoTiledMapReply

class GeoMapReplyNokia(GeoTiledMapReply):
    pass<commit_msg>#199: GraphicsItem für Kartenfunktionen in Detailansicht schreiben  geomapreply eingebaut<commit_after>'''
Created on 16.11.2011

@author: michi
'''
from PyQt4.QtCore import pyqtSlot, QDateTime
from PyQt4.QtNetwork import QNetworkReply, QNetworkRequest

from ems.qt4.location.maps.tiled.geotiledmapreply import GeoTiledMapReply

class GeoMapReplyNokia(GeoTiledMapReply):
    
    _m_reply = QNetworkReply
    
    def __init__(self, reply, request, parent=None):
        '''
        @param reply: QNetworkReply
        @type reply: QNetworkReply
        @param request: GeoTiledMapRequest
        @type request: GeoTiledMapRequest
        @param parent: Parent QObject
        @type parent: QObject
        '''
        GeoTiledMapReply.__init__(self, request, parent=parent)
        
        self._m_reply = reply
        self._m_reply.setParent(self)
        self._m_reply.finished.connect(self._networkFinished)
        self._m_reply.error.connect(self._networkError)
        self._m_reply.destroyed.connect(self._replyDestroyed)
    
    def networkReply(self):
        '''
        @rtype: QNetworkReply
        '''
        return self._m_reply
    
    def abort(self):
        if not self._m_reply:
            return
        self._m_reply.abort()
    
    @pyqtSlot()
    def _replyDestroyed(self):
        self._m_reply = None
    
    @pyqtSlot()
    def _networkFinished(self):
        if not self._m_reply:
            return
        
        if self._m_reply.error() != QNetworkReply.NoError:
            return
        
        fromCache = self._m_reply.attribute(QNetworkRequest.SourceIsFromCacheAttribute)
        self._setCached(fromCache.toBool)
        
        if not self.isChached():
            cache = self._m_reply.manager().cache()
            if cache:
                metaData = cache.metaData(self._m_reply.url())
                exp = QDateTime.currentDateTime()
                exp = exp.addDays(14)
                metaData.setExpirationDate(exp)
                cache.updateMetaData(metaData)
        
        self._setMapImageData(self._m_reply.readAll())
        self.setMapImageFormat("PNG")
        self._setFinished(True)
        
        self._m_reply.deleteLater()
        self._m_reply = None
    
    def _networkError(self, error):
        if not self._m_reply:
            return
        
        if error != QNetworkReply.OperationCanceledError:
            self._setError(GeoTiledMapReply.CommunicationError,
                           self._m_reply.errorString())
        self._setFinished(True)
        self._m_reply.deleteLater()
        self._m_reply = None
{'fraction_non_alphanumeric': 0.08669282911166608, 'fraction_numerical': 0.008919015340706386, 'mean_word_length': 2.2529002320185616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '406977', 'n_tokens_mistral': 867, 'n_tokens_neox': 837, 'n_words': 146}