mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 18:29:19 +02:00
address @flub's remarks -- strike myattr and use imported attr directly
This commit is contained in:
parent
a21dc8ab31
commit
4a377bff6a
2 changed files with 15 additions and 26 deletions
|
@ -10,12 +10,14 @@ except ImportError:
|
||||||
import deltachat
|
import deltachat
|
||||||
from . import capi
|
from . import capi
|
||||||
from .capi import ffi
|
from .capi import ffi
|
||||||
from .myattr import attrib_CData, attrs, attrib_int, cached_property
|
from .types import cached_property
|
||||||
|
import attr
|
||||||
|
from attr import validators as v
|
||||||
|
|
||||||
|
|
||||||
@attrs
|
@attr.s
|
||||||
class EventHandler(object):
|
class EventHandler(object):
|
||||||
dc_context = attrib_CData()
|
dc_context = attr.ib(validator=v.instance_of(ffi.CData))
|
||||||
|
|
||||||
def read_url(self, url):
|
def read_url(self, url):
|
||||||
try:
|
try:
|
||||||
|
@ -76,10 +78,10 @@ class EventLogger:
|
||||||
tname, self.logid, evt_name, data1, data2))
|
tname, self.logid, evt_name, data1, data2))
|
||||||
|
|
||||||
|
|
||||||
@attrs
|
@attr.s
|
||||||
class Contact(object):
|
class Contact(object):
|
||||||
dc_context = attrib_CData()
|
dc_context = attr.ib(validator=v.instance_of(ffi.CData))
|
||||||
id = attrib_int()
|
id = attr.ib(validator=v.instance_of(int))
|
||||||
|
|
||||||
@cached_property # only get it once because we only free it once
|
@cached_property # only get it once because we only free it once
|
||||||
def dc_contact_t(self):
|
def dc_contact_t(self):
|
||||||
|
@ -105,10 +107,10 @@ class Contact(object):
|
||||||
return capi.lib.dc_contact_is_verified(self.dc_contact_t)
|
return capi.lib.dc_contact_is_verified(self.dc_contact_t)
|
||||||
|
|
||||||
|
|
||||||
@attrs
|
@attr.s
|
||||||
class Chat(object):
|
class Chat(object):
|
||||||
dc_context = attrib_CData()
|
dc_context = attr.ib(validator=v.instance_of(ffi.CData))
|
||||||
id = attrib_int()
|
id = attr.ib(validator=v.instance_of(int))
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def dc_chat_t(self):
|
def dc_chat_t(self):
|
||||||
|
@ -125,10 +127,10 @@ class Chat(object):
|
||||||
return Message(self.dc_context, msg_id)
|
return Message(self.dc_context, msg_id)
|
||||||
|
|
||||||
|
|
||||||
@attrs
|
@attr.s
|
||||||
class Message(object):
|
class Message(object):
|
||||||
dc_context = attrib_CData()
|
dc_context = attr.ib(validator=v.instance_of(ffi.CData))
|
||||||
id = attrib_int()
|
id = attr.ib(validator=v.instance_of(int))
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def dc_msg_t(self):
|
def dc_msg_t(self):
|
||||||
|
|
|
@ -1,19 +1,6 @@
|
||||||
from attr import attrs, attrib # noqa
|
|
||||||
from attr import validators as v
|
|
||||||
|
|
||||||
|
|
||||||
def attrib_int():
|
|
||||||
return attrib(validator=v.instance_of(int))
|
|
||||||
|
|
||||||
|
|
||||||
def attrib_CData():
|
|
||||||
from deltachat.capi import ffi
|
|
||||||
return attrib(validator=v.instance_of(ffi.CData))
|
|
||||||
|
|
||||||
|
|
||||||
# copied over unmodified from
|
# copied over unmodified from
|
||||||
# https://github.com/devpi/devpi/blob/master/common/devpi_common/types.py
|
# https://github.com/devpi/devpi/blob/master/common/devpi_common/types.py
|
||||||
# where it's also tested
|
|
||||||
|
|
||||||
def cached_property(f):
|
def cached_property(f):
|
||||||
"""returns a cached property that is calculated by function f"""
|
"""returns a cached property that is calculated by function f"""
|
Loading…
Add table
Add a link
Reference in a new issue