Fixed Python 3.1 incompatibility issues.
diff --git a/ext/_yaml.pyx b/ext/_yaml.pyx
index 3be0f4f..ac56b5f 100644
--- a/ext/_yaml.pyx
+++ b/ext/_yaml.pyx
@@ -954,11 +954,12 @@
             raise MemoryError
         self.stream = stream
         self.dump_unicode = 0
-        try:
-            if stream.encoding:
+        if PY_MAJOR_VERSION < 3:
+            if hasattr(stream, 'encoding'):
                 self.dump_unicode = 1
-        except AttributeError:
-            pass
+        else:
+            if hasattr(stream, u'encoding'):
+                self.dump_unicode = 1
         self.use_encoding = encoding
         yaml_emitter_set_output(&self.emitter, output_handler, <void *>self)    
         if canonical:
diff --git a/lib3/yaml/constructor.py b/lib3/yaml/constructor.py
index 5e23c20..bd25b79 100644
--- a/lib3/yaml/constructor.py
+++ b/lib3/yaml/constructor.py
@@ -285,7 +285,10 @@
                     "failed to convert base64 data into ascii: %s" % exc,
                     node.start_mark)
         try:
-            return base64.decodestring(value)
+            if hasattr(base64, 'decodebytes'):
+                return base64.decodebytes(value)
+            else:
+                return base64.decodestring(value)
         except binascii.Error as exc:
             raise ConstructorError(None, None,
                     "failed to decode base64 data: %s" % exc, node.start_mark)
@@ -477,7 +480,10 @@
                     "failed to convert base64 data into ascii: %s" % exc,
                     node.start_mark)
         try:
-            return base64.decodestring(value)
+            if hasattr(base64, 'decodebytes'):
+                return base64.decodebytes(value)
+            else:
+                return base64.decodestring(value)
         except binascii.Error as exc:
             raise ConstructorError(None, None,
                     "failed to decode base64 data: %s" % exc, node.start_mark)
diff --git a/lib3/yaml/reader.py b/lib3/yaml/reader.py
index f5fb924..f70e920 100644
--- a/lib3/yaml/reader.py
+++ b/lib3/yaml/reader.py
@@ -156,7 +156,7 @@
                     data, converted = self.raw_decode(self.raw_buffer,
                             'strict', self.eof)
                 except UnicodeDecodeError as exc:
-                    character = exc.object[exc.start]
+                    character = self.raw_buffer[exc.start]
                     if self.stream is not None:
                         position = self.stream_pointer-len(self.raw_buffer)+exc.start
                     else:
diff --git a/lib3/yaml/representer.py b/lib3/yaml/representer.py
index 1a9a574..67cd6fd 100644
--- a/lib3/yaml/representer.py
+++ b/lib3/yaml/representer.py
@@ -144,7 +144,10 @@
         return self.represent_scalar('tag:yaml.org,2002:str', data)
 
     def represent_binary(self, data):
-        data = base64.encodestring(data).decode('ascii')
+        if hasattr(base64, 'encodebytes'):
+            data = base64.encodebytes(data).decode('ascii')
+        else:
+            data = base64.encodestring(data).decode('ascii')
         return self.represent_scalar('tag:yaml.org,2002:binary', data, style='|')
 
     def represent_bool(self, data):