git » msnlib » commit b2e4b6c

Quote nicks and groups properly.

author Alberto Bertogli
2005-05-15 15:00:24 UTC
committer Alberto Bertogli
2005-05-15 15:00:24 UTC
parent 2e1849f9d099824d6f9e83c4ec9714db1e687cdd

Quote nicks and groups properly.
The change implemented for renames needs to be extended to all user and group
names, since the server likes it better that way. So this change allows users
and groups to be named with spaces and extended characters.

msnlib.py +11 -7

diff --git a/msnlib.py b/msnlib.py
index fb3cdff..f10af26 100644
--- a/msnlib.py
+++ b/msnlib.py
@@ -47,6 +47,12 @@ def debug(s):
 	sys.stderr.write('\r' + str(s) + '\n')
 	sys.stderr.flush()
 
+def nickquote(nick):
+	"""Quotes a nick the way the server likes it: replacing spaces with
+	'%20' but leaving extender characters alone, as they get sent UTF-8
+	encoded."""
+	nick = nick.replace(' ', '%20')
+	return nick
 
 class user:
 	"""User class, used to store your 'friends'"""
@@ -360,7 +366,7 @@ class msnd:
 
 	def change_nick(self, nick):
 		"Changes our nick"
-		nick = urllib.quote(nick)
+		nick = nickquote(nick)
 		self._send('REA', self.email + ' ' + nick)
 		return 1
 
@@ -374,7 +380,7 @@ class msnd:
 	def useradd(self, email, nick = None, gid = '0'):
 		"Adds a user"
 		if not nick: nick = email
-		nick = urllib.quote(nick)
+		nick = nickquote(nick)
 		self._send('ADD', 'AL ' + email + ' ' + nick)
 		self._send('ADD', 'FL ' + email + ' ' + nick + ' ' + gid)
 		return 1
@@ -388,9 +394,7 @@ class msnd:
 
 	def userren(self, email, newnick):
 		"Renames a user"
-		# don't url-quote the newnick; the server has a bug and it
-		# won't store extended characters that way; send directly the
-		# UTF-8 encoded new nick
+		newnick = nickquote(newnick)
 		self._send('REA', email + ' ' + newnick)
 		return 1
 
@@ -408,7 +412,7 @@ class msnd:
 
 	def groupadd(self, name):
 		"Adds a group"
-		name = urllib.quote(name)
+		name = nickquote(name)
 		self._send('ADG', name + ' 0')
 		return 1
 
@@ -418,7 +422,7 @@ class msnd:
 		return 1
 
 	def groupren(self, gid, newname):
-		newname = urllib.quote(newname)
+		newname = nickquote(newname)
 		self._send('REG', gid + ' ' + newname)
 		return 1