Browse Source

Encoding str from utf-8 before sending to socket

Jadjay 8 years ago
parent
commit
85a90e47db
1 changed files with 7 additions and 4 deletions
  1. 7 4
      irclib.py

+ 7 - 4
irclib.py View File

780
         """Send raw string to the server.
780
         """Send raw string to the server.
781
 
781
 
782
         The string will be padded with appropriate CR LF.
782
         The string will be padded with appropriate CR LF.
783
+        From here everything need to be encoded in str from utf-8
783
         """
784
         """
785
+        string=string.encode('utf-8')
786
+
784
         if self.socket is None:
787
         if self.socket is None:
785
-            raise ServerNotConnectedError, u'Not connected.'
788
+            raise ServerNotConnectedError, "Not connected."
786
         try:
789
         try:
787
             if self.ssl:
790
             if self.ssl:
788
-                self.ssl.write(string + u'\r\n')
791
+                self.ssl.write(string + "\r\n")
789
             else:
792
             else:
790
-                self.socket.send(string + u'\r\n')
793
+                self.socket.send(string + "\r\n")
791
             if DEBUG:
794
             if DEBUG:
792
-                print u'TO SERVER:', string
795
+                print "TO SERVER:", string
793
         except socket.error, x:
796
         except socket.error, x:
794
             # Ouch!
797
             # Ouch!
795
             self.disconnect(u'Connection reset by peer.')
798
             self.disconnect(u'Connection reset by peer.')