]>
code.delx.au - pymsnt/blob - src/utils.py
1 # Copyright 2004-2005 James Bunton <james@delx.cjb.net>
2 # Licensed for distribution under the GPL version 2, check COPYING for details
7 return el
.getAttribute((u
'http://www.w3.org/XML/1998/namespace', u
'lang'))
11 def socks5Hash(sid
, initiator
, target
):
12 return sha
.new("%s%s%s" % (sid
, initiator
, target
)).hexdigest()
17 def getURLBits(url
, assumedType
=None):
18 type, rest
= urllib
.splittype(url
)
19 if assumedType
and type != assumedType
:
21 hostport
, path
= urllib
.splithost(rest
)
22 host
, port
= urllib
.splitnport(hostport
, 80)
23 filename
= os
.path
.basename(path
)
24 return host
, port
, path
, filename
31 def convertToPNG(imageData
):
32 inbuff
= StringIO
.StringIO(imageData
)
33 outbuff
= StringIO
.StringIO()
34 Image
.open(inbuff
).save(outbuff
, "PNG")
36 imageData
= outbuff
.read()
39 print "WARNING! Only PNG avatars will be understood by this transport. Please install the Python Imaging Library."
41 def convertToPNG(imageData
):
48 "feature-not-implemented" : 501,
51 "internal-server-error" : 500,
52 "item-not-found" : 404,
53 "jid-malformed" : 400,
54 "not-acceptable" : 406,
56 "not-authorized" : 401,
57 "payment-required" : 402,
58 "recipient-unavailable" : 404,
60 "registration-required" : 407,
61 "remote-server-not-found" : 404,
62 "remote-server-timeout" : 504,
63 "resource-constraint" : 500,
64 "service-unavailable" : 503,
65 "subscription-required" : 407,
66 "undefined-condition" : 500,
67 "unexpected-request" : 400
72 checkTwistedCached
= None
74 """ Returns False if we're using an old version that needs tlib, otherwise returns True """
75 global checkTwistedCached
76 if checkTwistedCached
== None:
77 import twisted
.copyright
78 checkTwistedCached
= (VersionNumber(twisted
.copyright
.version
) >= VersionNumber("2.0.0"))
79 return checkTwistedCached
82 def __init__(self
, vstring
):
91 elif c
.isdigit() and flag
:
92 self
.varray
[index
] *= 10
93 self
.varray
[index
] += int(c
)
97 def __cmp__(self
, other
):
100 if i
== len(other
.varray
):
101 if i
< len(self
.varray
):
105 if i
== len(self
.varray
):
106 if i
< len(other
.varray
):
111 if self
.varray
[i
] > other
.varray
[i
]:
113 elif self
.varray
[i
] < other
.varray
[i
]: