]> code.delx.au - pymsnt/blob - src/utils.py
Fixed jid.internJID that somehow slipped through
[pymsnt] / 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
3
4
5
6 def getLang(el):
7 return el.getAttribute((u'http://www.w3.org/XML/1998/namespace', u'lang'))
8
9
10 import sha
11 def socks5Hash(sid, initiator, target):
12 return sha.new("%s%s%s" % (sid, initiator, target)).hexdigest()
13
14
15 import urllib
16 import os.path
17 def getURLBits(url, assumedType=None):
18 type, rest = urllib.splittype(url)
19 if assumedType and type != assumedType:
20 return
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
25
26
27 try:
28 import Image
29 import StringIO
30
31 def convertToPNG(imageData):
32 inbuff = StringIO.StringIO(imageData)
33 outbuff = StringIO.StringIO()
34 Image.open(inbuff).save(outbuff, "PNG")
35 outbuff.seek(0)
36 imageData = outbuff.read()
37 return imageData
38 except ImportError:
39 print "WARNING! Only PNG avatars will be understood by this transport. Please install the Python Imaging Library."
40
41 def convertToPNG(imageData):
42 return ""
43
44
45 errorCodeMap = {
46 "bad-request" : 400,
47 "conflict" : 409,
48 "feature-not-implemented" : 501,
49 "forbidden" : 403,
50 "gone" : 302,
51 "internal-server-error" : 500,
52 "item-not-found" : 404,
53 "jid-malformed" : 400,
54 "not-acceptable" : 406,
55 "not-allowed" : 405,
56 "not-authorized" : 401,
57 "payment-required" : 402,
58 "recipient-unavailable" : 404,
59 "redirect" : 302,
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
68 }
69
70
71