~ubuntu-branches/ubuntu/lucid/gajim/lucid-security

« back to all changes in this revision

Viewing changes to src/common/xmpp/c14n.py

  • Committer: Maia Kozheva
  • Date: 2009-11-25 08:32:36 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: sikon@maia-desktop-20091125083236-hkxrujhn3amehuve
Merged new upstream release 0.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding:utf-8 -*-
 
2
## c14n.py
 
3
##
 
4
## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
 
5
##
 
6
## This file is part of Gajim.
 
7
##
 
8
## Gajim is free software; you can redistribute it and/or modify
 
9
## it under the terms of the GNU General Public License as published
 
10
## by the Free Software Foundation; version 3 only.
 
11
##
 
12
## Gajim is distributed in the hope that it will be useful,
 
13
## but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
## GNU General Public License for more details.
 
16
##
 
17
## You should have received a copy of the GNU General Public License
 
18
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
 
19
##
 
20
 
 
21
''' XML canonicalisation methods (for XEP-0116) '''
1
22
from simplexml import ustr
2
23
 
3
 
# XML canonicalisation methods (for XEP-0116)
4
 
def c14n(node):
 
24
def c14n(node, is_buggy):
5
25
        s = "<" + node.name
6
26
        if node.namespace:
7
27
                if not node.parent or node.parent.namespace != node.namespace:
9
29
 
10
30
        sorted_attrs = sorted(node.attrs.keys())
11
31
        for key in sorted_attrs:
 
32
                if not is_buggy and key == 'xmlns':
 
33
                        continue
12
34
                val = ustr(node.attrs[key])
13
35
                # like XMLescape() but with whitespace and without &gt;
14
36
                s = s + ' %s="%s"' % ( key, normalise_attr(val) )
18
40
                for a in node.kids:
19
41
                        if (len(node.data)-1) >= cnt:
20
42
                                s = s + normalise_text(node.data[cnt])
21
 
                        s = s + c14n(a)
 
43
                        s = s + c14n(a, is_buggy)
22
44
                        cnt=cnt+1
23
45
        if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt])
24
46
        if not node.kids and s.endswith('>'):
34
56
        return val.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('\r', '&#xD;')
35
57
 
36
58
 
37
 
# vim: se ts=3:
 
 
b'\\ No newline at end of file'
 
59
# vim: se ts=3: