Browse Source

Bump holster, fix SimpleLimiter race error, fix to_dict recursion

feature/docs
Andrei 8 years ago
parent
commit
bef1492d54
  1. 26
      disco/types/base.py
  2. 2
      disco/types/user.py
  3. 1
      disco/util/limiter.py
  4. 2
      requirements.txt

26
disco/types/base.py

@ -34,10 +34,11 @@ class ConversionError(Exception):
class Field(object): class Field(object):
def __init__(self, value_type, alias=None, default=None, create=True, **kwargs): def __init__(self, value_type, alias=None, default=None, create=True, ignore_dump=None, **kwargs):
# TODO: fix default bullshit # TODO: fix default bullshit
self.src_name = alias self.src_name = alias
self.dst_name = None self.dst_name = None
self.ignore_dump = ignore_dump or []
self.metadata = kwargs self.metadata = kwargs
if default is not None: if default is not None:
@ -88,11 +89,11 @@ class Field(object):
return lambda raw, _: typ(raw) return lambda raw, _: typ(raw)
@staticmethod @staticmethod
def serialize(value): def serialize(value, inst=None):
if isinstance(value, EnumAttr): if isinstance(value, EnumAttr):
return value.value return value.value
elif isinstance(value, Model): elif isinstance(value, Model):
return value.to_dict() return value.to_dict(ignore=(inst.ignore_dump if inst else []))
else: else:
return value return value
@ -109,8 +110,11 @@ class DictField(Field):
self.value_de = self.type_to_deserializer(value_type or key_type) self.value_de = self.type_to_deserializer(value_type or key_type)
@staticmethod @staticmethod
def serialize(value): def serialize(value, inst=None):
return {Field.serialize(k): Field.serialize(v) for k, v in six.iteritems(value)} return {
Field.serialize(k): Field.serialize(v) for k, v in six.iteritems(value)
if k not in (inst.ignore_dump if inst else [])
}
def try_convert(self, raw, client): def try_convert(self, raw, client):
return HashMap({ return HashMap({
@ -122,7 +126,7 @@ class ListField(Field):
default = list default = list
@staticmethod @staticmethod
def serialize(value): def serialize(value, inst=None):
return list(map(Field.serialize, value)) return list(map(Field.serialize, value))
def try_convert(self, raw, client): def try_convert(self, raw, client):
@ -211,7 +215,10 @@ def binary(obj):
def with_equality(field): def with_equality(field):
class T(object): class T(object):
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, self.__class__):
return getattr(self, field) == getattr(other, field) return getattr(self, field) == getattr(other, field)
else:
return getattr(self, field) == other
return T return T
@ -321,12 +328,15 @@ class Model(six.with_metaclass(ModelMeta, AsyncChainable)):
except: except:
pass pass
def to_dict(self): def to_dict(self, ignore=None):
obj = {} obj = {}
for name, field in six.iteritems(self.__class__._fields): for name, field in six.iteritems(self.__class__._fields):
if ignore and name in ignore:
continue
if getattr(self, name) == UNSET: if getattr(self, name) == UNSET:
continue continue
obj[name] = field.serialize(getattr(self, name)) obj[name] = field.serialize(getattr(self, name), field)
return obj return obj
@classmethod @classmethod

2
disco/types/user.py

@ -55,6 +55,6 @@ class Game(SlottedModel):
class Presence(SlottedModel): class Presence(SlottedModel):
user = Field(User, alias='user') user = Field(User, alias='user', ignore_dump=['presence'])
game = Field(Game) game = Field(Game)
status = Field(Status) status = Field(Status)

1
disco/util/limiter.py

@ -17,6 +17,7 @@ class SimpleLimiter(object):
gevent.sleep(self.reset_at - time.time()) gevent.sleep(self.reset_at - time.time())
self.count = 0 self.count = 0
self.reset_at = 0 self.reset_at = 0
if self.event:
self.event.set() self.event.set()
self.event = None self.event = None

2
requirements.txt

@ -1,5 +1,5 @@
gevent==1.1.2 gevent==1.1.2
holster==1.0.9 holster==1.0.11
inflection==0.3.1 inflection==0.3.1
requests==2.11.1 requests==2.11.1
six==1.10.0 six==1.10.0

Loading…
Cancel
Save