mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
python: add binding for PkId
This commit is contained in:
1 parent
31ddf3cc27
commit
c139fc9791
2 files changed
+56
No files matched your search
@@ -129,6 +129,44 @@ cdef class InfoHash(_WithID):
|
||||
h._infohash = cpp.InfoHash.getRandom()
|
||||
return h
|
||||
|
||||
cdef class PkId(_WithID):
|
||||
cdef cpp.PkId _pkid
|
||||
def __cinit__(self, bytes str=b''):
|
||||
self._pkid = cpp.PkId(str) if str else cpp.PkId()
|
||||
def __bool__(PkId self):
|
||||
return <bool>self._pkid
|
||||
def __richcmp__(PkId self, PkId other, int op):
|
||||
if op == 0:
|
||||
return self._pkid < other._pkid
|
||||
if op == 1:
|
||||
return self._pkid < other._pkid or self._pkid == other._pkid
|
||||
if op == 2:
|
||||
return self._pkid == other._pkid
|
||||
return NotImplemented
|
||||
def getBit(PkId self, bit):
|
||||
return self._pkid.getBit(bit)
|
||||
def setBit(PkId self, bit, b):
|
||||
self._pkid.setBit(bit, b)
|
||||
def getId(PkId self):
|
||||
return self
|
||||
def toString(PkId self):
|
||||
return self._pkid.toString()
|
||||
def toFloat(PkId self):
|
||||
return self._pkid.toFloat()
|
||||
@staticmethod
|
||||
def commonBits(PkId a, PkId b):
|
||||
return cpp.PkId.commonBits(a._pkid, b._pkid)
|
||||
@staticmethod
|
||||
def get(str key):
|
||||
h = PkId()
|
||||
h._pkid = cpp.PkId.get(key.encode())
|
||||
return h
|
||||
@staticmethod
|
||||
def getRandom():
|
||||
h = PkId()
|
||||
h._pkid = cpp.PkId.getRandom()
|
||||
return h
|
||||
|
||||
cdef class SockAddr(object):
|
||||
cdef cpp.SockAddr _addr
|
||||
def toString(SockAddr self):
|
||||
|
||||
@@ -72,6 +72,24 @@ cdef extern from "opendht/infohash.h" namespace "dht":
|
||||
bool operator==(InfoHash) const
|
||||
bool operator<(InfoHash) const
|
||||
bool operator bool() const
|
||||
|
||||
cdef cppclass PkId:
|
||||
PkId() except +
|
||||
PkId(string s) except +
|
||||
string toString() const
|
||||
bool getBit(unsigned bit) const
|
||||
void setBit(unsigned bit, bool b)
|
||||
double toFloat() const
|
||||
@staticmethod
|
||||
unsigned commonBits(PkId a, PkId b)
|
||||
@staticmethod
|
||||
PkId get(string s)
|
||||
@staticmethod
|
||||
PkId getRandom()
|
||||
bool operator==(PkId) const
|
||||
bool operator<(PkId) const
|
||||
bool operator bool() const
|
||||
|
||||
|
||||
cdef extern from "opendht/sockaddr.h" namespace "dht":
|
||||
cdef cppclass SockAddr:
|
||||
|
||||
Reference in new issue
Block a user