コード例 #1
0
    def _make_decision(self, url):
        self.db_metainfo = self._get_metainfo_from_db(url)
        conn_proxy = _http._HTTPConnectionProxy(url,self._timeout)
        self.web_metainfo = conn_proxy.send_request("HEAD",url)

        store_decision = (0,"Store both header and content")

#?        print self.db_metainfo
#?        print self.web_metainfo

        if self.web_metainfo == None:
            store_decision = (3, "Timeouted")
            return store_decision

        try:
            if self.db_metainfo['etag'] == self.web_metainfo[1]['etag']:
                store_decision = (1, "Store only header (based on etags equality)")
        except KeyError:
            pass

        try:
            if self.web_metainfo[1]['content-md5'] == self.db_metainfo['content']['md5']:
                store_decision = (1, "Store only header (based on recieved content-md5 equality)")
        except KeyError:
            pass

        if store_decision[0] != 0:
            return store_decision

        # etag and content-md5 are the only authoritave evidents of 'it has not changed'
        # therefore, now is the time to download the content

        self._web_full_info = conn_proxy.send_request("GET",url)
        #print(self.web_full_info)
        if self._web_full_info == None:
            return "Pruuser, HEAD prosel, GET uz ne"

#?        print "header: " + self.web_full_info[1]['content-length'] + ", len(): " + str(len(self.web_full_info[2]))
#?        print self.web_full_info

        mdfiver = hashlib.md5()
        mdfiver.update(self._web_full_info[2])
        self._md5 = mdfiver.hexdigest()
#?        print "md5: " + self._md5

        shaoner = hashlib.sha1()
        shaoner.update(self._web_full_info[2])
        self._sha1 = shaoner.hexdigest()
#?        print "sha1: " + self._sha1

        if self._md5 == self.db_metainfo['content']['md5'] and self._sha1 == self.db_metainfo['content']['sha1']:
            store_decision(1, "Store only header (based on computed md5 and sha1 equality)")

        return store_decision
コード例 #2
0
    def _make_decision(self, url):
        self.db_metainfo = self._get_metainfo_from_db(url)
        conn_proxy = _http._HTTPConnectionProxy(url,self._timeout)
        self.web_metainfo = conn_proxy.send_request("HEAD",url)

        store_decision = (0,"Store both header and content")

#?        print self.db_metainfo
#?        print self.web_metainfo

        if self.web_metainfo == None:
            store_decision = (3, "Timeouted")
            return store_decision

        try:
            if self.db_metainfo['etag'] == self.web_metainfo[1]['etag']:
                store_decision = (1, "Store only header (based on etags equality)")
        except KeyError:
            pass

        try:
            if self.web_metainfo[1]['content-md5'] == self.db_metainfo['content']['md5']:
                store_decision = (1, "Store only header (based on recieved content-md5 equality)")
        except KeyError:
            pass

        if store_decision[0] != 0:
            return store_decision

        # etag and content-md5 are the only authoritave evidents of 'it has not changed'
        # therefore, now is the time to download the content

        self.web_full_info = conn_proxy.send_request("GET",url)
        if self.web_full_info == None:
            return "Pruuser, HEAD prosel, GET uz ne"

#?        print "header: " + self.web_full_info[1]['content-length'] + ", len(): " + str(len(self.web_full_info[2]))
#?        print self.web_full_info

        mdfiver = hashlib.md5()
        mdfiver.update(self.web_full_info[2])
        self._md5 = mdfiver.hexdigest()
#?        print "md5: " + self._md5

        shaoner = hashlib.sha1()
        shaoner.update(self.web_full_info[2])
        self._sha1 = shaoner.hexdigest()
#?        print "sha1: " + self._sha1

        if self._md5 == self.db_metainfo['content']['md5'] and self._sha1 == self.db_metainfo['content']['sha1']:
            store_decision(1, "Store only header (based on computed md5 and sha1 equality)")

        return store_decision
コード例 #3
0
ファイル: resolver.py プロジェクト: KNOT-GIT/mDeliverables
    def _make_decision(self, url):
        self.db_metainfo = self._get_metainfo_from_db(url)
        conn_proxy = _http._HTTPConnectionProxy(url,self._timeout)
        self.web_metainfo = conn_proxy.send_request("HEAD",url)
        
        store_decision = (0,"Store both header and content")

#?        print "Resolver: _make_decision: db_metainfo",self.db_metainfo
#?        print self.web_metainfo

        if self.db_metainfo == None:
            store_decision = (0,"Store both header and content")
            self._make_decision_2(url,conn_proxy)
            return store_decision

        if self.web_metainfo == None:
            store_decision = (3, "Timeouted")
            return store_decision

        try:
            if self.db_metainfo['etag'] == self.web_metainfo[1]['etag']:
                store_decision = (1, "Store only header (based on etags equality)")
                self._md5 = self.web_metainfo[1]['content-md5']
        except KeyError:
            pass

        try:
            if self.web_metainfo[1]['content-md5'] == self.db_metainfo['content']['md5']:
                store_decision = (1, "Store only header (based on recieved content-md5 equality)")
                self._md5 = self.web_metainfo[1]['content-md5']
        except KeyError:
            pass

        if store_decision[0] != 0:
            return store_decision
        else:
            return self._make_decision_2(url,conn_proxy)