diff options
author | Jefry Lagrange <jefry.reyes@gmail.com> | 2012-12-24 22:55:21 +0400 |
---|---|---|
committer | Jefry Lagrange <jefry.reyes@gmail.com> | 2012-12-24 22:55:21 +0400 |
commit | 14db4017fe5a4a8b0ef1071612801079a2e661c4 (patch) | |
tree | 1940c9ac7b98c3ce1728ff0153204f33bfcc3aa5 | |
parent | 6d2282068b7d2657cb64a4904d1c9bedecbaad69 (diff) |
update xep-300 to the lastest version
-rw-r--r-- | nbxmpp/protocol.py | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/nbxmpp/protocol.py b/nbxmpp/protocol.py index e0bd794..d4c5fb2 100644 --- a/nbxmpp/protocol.py +++ b/nbxmpp/protocol.py @@ -162,12 +162,12 @@ NS_PUBKEY_PUBKEY = 'urn:xmpp:pubkey:2' NS_PUBKEY_REVOKE = 'urn:xmpp:revoke:2' NS_PUBKEY_ATTEST = 'urn:xmpp:attest:2' NS_STREAM_MGMT = 'urn:xmpp:sm:2' # XEP-198 -NS_HASHES = 'urn:xmpp:hashes:0' # XEP-300 +NS_HASHES = 'urn:xmpp:hashes:1' # XEP-300 NS_HASHES_MD5 = 'urn:xmpp:hash-function-textual-names:md5' NS_HASHES_SHA1 = 'urn:xmpp:hash-function-textual-names:sha-1' NS_HASHES_SHA256 = 'urn:xmpp:hash-function-textual-names:sha-256' NS_HASHES_SHA512 = 'urn:xmpp:hash-function-textual-names:sha-512' - + xmpp_stream_error_conditions = ''' bad-format -- -- -- The entity has sent XML that cannot be processed. bad-namespace-prefix -- -- -- The entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix. @@ -1037,12 +1037,12 @@ class Iq(Protocol): attrs={'id': self.getID()}) iq.setQuery(self.getQuery().getName()).setNamespace(self.getQueryNS()) return iq - -class Hashes(Node): + +class Hashes(Node): """ Hash elements for various XEPs as defined in XEP-300 """ - + """ RECOMENDED HASH USE: Algorithm Support @@ -1053,14 +1053,14 @@ class Hashes(Node): SHA-256 MUST SHA-512 SHOULD """ - + supported = ('md5', 'sha-1', 'sha-256', 'sha-512') - + def __init__(self, nsp=NS_HASHES): - Node.__init__(self, None, {}, [], None, None,False, None) + Node.__init__(self, None, {}, [], None, None, False, None) self.setNamespace(nsp) - self.setName('hashes') - + self.setName('hash') + def calculateHash(self, algo, file_string): """ Calculate the hash and add it. It is preferable doing it here @@ -1078,12 +1078,12 @@ class Hashes(Node): hl = hashlib.sha256() elif algo == 'sha-512': hl = hashlib.sha512() - + if hl: hl.update(file_string) hash_ = hl.hexdigest() else: # if it is a file - + if algo == 'md5': hl = hashlib.md5() elif algo == 'sha-1': @@ -1092,23 +1092,18 @@ class Hashes(Node): hl = hashlib.sha256() elif algo == 'sha-512': hl = hashlib.sha512() - + if hl: for line in file_string: hl.update(line) hash_ = hl.hexdigest() - - return hash_ - + + return hash_ + def addHash(self, hash_, algo): - """ - More than one hash can be added. Although it is permitted, it should - not be done for big files because it could slow down Gajim. - """ - attrs = {} - attrs['algo'] = algo - self.addChild('hash', attrs, [hash_]) - + self.setAttr('algo', algo) + self.setData(hash_) + class Acks(Node): """ Acknowledgement elements for Stream Management |