Пример #1
0
 def Update(self, drink, force=False):
   previous = None
   if not force and self.stats:
     previous = protoutil.DictToProtoMessage(self.stats, models_pb2.Stats())
   builder = self.STATS_BUILDER(drink, previous)
   self.stats = protoutil.ProtoMessageToDict(builder.Build())
   self.save()
Пример #2
0
 def GetStats(self):
   try:
     stats = UserStats.objects.get(user=self).stats
   except UserStats.DoesNotExist:
     stats = {}
   return protoutil.DictToProtoMessage(stats, models_pb2.Stats())
Пример #3
0
 def GetStats(self):
   try:
     stats = SystemStats.objects.get(site=self).stats
   except SystemStats.DoesNotExist:
     stats = {}
   return protoutil.DictToProtoMessage(stats, models_pb2.Stats())
Пример #4
0
        d = kbjson.loads(response_data)
    except ValueError, e:
        raise ServerError('Malformed response: %s' % e)

    if 'error' in d:
        # Response had an error: translate to exception.
        err = d.get('error', {})
        code = err.get('code', 'Unknown')
        message = err.get('message', None)
        e = ErrorCodeToException(code, message)
        raise e
    elif 'result' in d:
        # Response was OK, return the result.
        result = d.get('result')
        if out_msg:
            return protoutil.DictToProtoMessage(result, out_msg)
        else:
            return None
    else:
        # WTF?
        raise ValueError(
            'Invalid response from server: missing result or error')


### end common


class KrestClient:
    """Kegweb RESTful API client."""
    def __init__(self, api_url=None, api_key=None):
        if api_url is None: