Beispiel #1
0
def CheckHydrusVersion(service_key, service_type, response_headers):

    service_string = HC.service_string_lookup[service_type]

    if 'server' not in response_headers or service_string not in response_headers[
            'server']:

        HC.app.Write(
            'service_updates', {
                service_key: [
                    HC.ServiceUpdate(HC.SERVICE_UPDATE_ACCOUNT,
                                     HC.GetUnknownAccount())
                ]
            })

        raise HydrusExceptions.WrongServiceTypeException('Target was not a ' +
                                                         service_string + '!')

    server_header = response_headers['server']

    (service_string_gumpf, network_version) = server_header.split('/')

    network_version = int(network_version)

    if network_version != HC.NETWORK_VERSION:

        if network_version > HC.NETWORK_VERSION:
            message = 'Your client is out of date; please download the latest release.'
        else:
            message = 'The server is out of date; please ask its admin to update to the latest release.'

        raise HydrusExceptions.NetworkVersionException(
            'Network version mismatch! The server\'s network version was ' +
            u(network_version) + ', whereas your client\'s is ' +
            u(HC.NETWORK_VERSION) + '! ' + message)
Beispiel #2
0
    def test_news(self):

        result = self._read('news', HC.LOCAL_TAG_SERVICE_KEY)

        self.assertEqual(result, [])

        #

        news = []

        news.append(('hello', HC.GetNow() - 30000))
        news.append(('hello again', HC.GetNow() - 20000))

        service_updates = dict()

        service_updates[HC.LOCAL_TAG_SERVICE_KEY] = [
            HC.ServiceUpdate(HC.SERVICE_UPDATE_NEWS, news)
        ]

        self._write('service_updates', service_updates)

        #

        result = self._read('news', HC.LOCAL_TAG_SERVICE_KEY)

        self.assertItemsEqual(result, news)
Beispiel #3
0
def DoHydrusBandwidth(service_key, method, command, size):

    try:
        service = HC.app.GetManager('services').GetService(service_key)
    except:
        return

    service_type = service.GetServiceType()

    if (service_type, method, command) in HC.BANDWIDTH_CONSUMING_REQUESTS:
        HC.pubsub.pub('service_updates_delayed', {
            service_key:
            [HC.ServiceUpdate(HC.SERVICE_UPDATE_REQUEST_MADE, size)]
        })
Beispiel #4
0
    def _recordDataUsage(self, request):

        p1 = request.method == 'GET' and self.RECORD_GET_DATA_USAGE
        p2 = request.method == 'POST' and self.RECORD_POST_DATA_USAGE

        if p1 or p2:

            num_bytes = request.hydrus_request_data_usage

            HC.pubsub.pub(
                'service_updates_delayed', {
                    HC.LOCAL_BOORU_SERVICE_KEY: [
                        HC.ServiceUpdate(HC.SERVICE_UPDATE_REQUEST_MADE,
                                         num_bytes)
                    ]
                })