summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxi <xi@18f92427-320e-0410-9341-c67f048884a3>2006-12-08 15:36:53 +0000
committerxi <xi@18f92427-320e-0410-9341-c67f048884a3>2006-12-08 15:36:53 +0000
commit096397f668ac0961db724bbc8cefbd480399a488 (patch)
treed600fe5a6e7edadc1800d17b7c584bffd5d0e622
parent30bb1a380c5d75b9c9dbc4e1b381405517480b70 (diff)
downloadpyyaml-096397f668ac0961db724bbc8cefbd480399a488.tar.gz
Use the types module instead of constructing type objects by hand. Fix #41. Thanks to v.haisman@sh.cvut.cz for the patch.
git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@235 18f92427-320e-0410-9341-c67f048884a3
-rw-r--r--lib/yaml/constructor.py8
-rw-r--r--lib/yaml/parser.py2
-rw-r--r--lib/yaml/representer.py26
3 files changed, 10 insertions, 26 deletions
diff --git a/lib/yaml/constructor.py b/lib/yaml/constructor.py
index c31c867..73fd4e3 100644
--- a/lib/yaml/constructor.py
+++ b/lib/yaml/constructor.py
@@ -12,7 +12,7 @@ try:
except NameError:
from sets import Set as set
-import binascii, re, sys
+import binascii, re, sys, types
class ConstructorError(MarkedYAMLError):
pass
@@ -37,10 +37,6 @@ class BaseConstructor(object):
if self.check_node():
return self.construct_document(self.get_node())
- def g(): yield None
- generator_type = type(g())
- del g
-
def construct_document(self, node):
data = self.construct_object(node)
while self.state_generators:
@@ -91,7 +87,7 @@ class BaseConstructor(object):
data = constructor(self, node)
else:
data = constructor(self, tag_suffix, node)
- if isinstance(data, self.generator_type):
+ if isinstance(data, types.GeneratorType):
generator = data
data = generator.next()
if self.deep_construct:
diff --git a/lib/yaml/parser.py b/lib/yaml/parser.py
index eef0882..3145d7e 100644
--- a/lib/yaml/parser.py
+++ b/lib/yaml/parser.py
@@ -291,7 +291,7 @@ class Parser(object):
token = self.get_token()
end_mark = token.end_mark
anchor = token.value
- if tag is not None and tag != u'!':
+ if tag is not None:
handle, suffix = tag
if handle is not None:
if handle not in self.tag_handles:
diff --git a/lib/yaml/representer.py b/lib/yaml/representer.py
index 3563a4c..072ed9b 100644
--- a/lib/yaml/representer.py
+++ b/lib/yaml/representer.py
@@ -12,7 +12,7 @@ try:
except NameError:
from sets import Set as set
-import sys, copy_reg
+import sys, copy_reg, types
class RepresenterError(YAMLError):
pass
@@ -36,18 +36,6 @@ class BaseRepresenter(object):
self.object_keeper = []
self.alias_key = None
- class C: pass
- c = C()
- def f(): pass
- def g(): yield None
- classobj_type = type(C)
- instance_type = type(c)
- function_type = type(f)
- generator_type = type(g())
- builtin_function_type = type(abs)
- module_type = type(sys)
- del C, c, f, g
-
def get_classobj_bases(self, cls):
bases = [cls]
for base in cls.__bases__:
@@ -68,7 +56,7 @@ class BaseRepresenter(object):
#self.represented_objects[alias_key] = None
self.object_keeper.append(data)
data_types = type(data).__mro__
- if type(data) is self.instance_type:
+ if type(data) is types.InstanceType:
data_types = self.get_classobj_bases(data.__class__)+list(data_types)
if data_types[0] in self.yaml_representers:
node = self.yaml_representers[data_types[0]](self, data)
@@ -471,19 +459,19 @@ Representer.add_representer(tuple,
Representer.add_representer(type,
Representer.represent_name)
-Representer.add_representer(Representer.classobj_type,
+Representer.add_representer(types.ClassType,
Representer.represent_name)
-Representer.add_representer(Representer.function_type,
+Representer.add_representer(types.FunctionType,
Representer.represent_name)
-Representer.add_representer(Representer.builtin_function_type,
+Representer.add_representer(types.BuiltinFunctionType,
Representer.represent_name)
-Representer.add_representer(Representer.module_type,
+Representer.add_representer(types.ModuleType,
Representer.represent_module)
-Representer.add_multi_representer(Representer.instance_type,
+Representer.add_multi_representer(types.InstanceType,
Representer.represent_instance)
Representer.add_multi_representer(object,