Issue #2974 - Part 18: Use str instead of unicode.

The standard str is unicode now...

2to3 . --fix unicode -wpn

Ref:
https://docs.python.org/3/whatsnew/3.0.html
This commit is contained in:
Jeremy Andrews committed 2026-03-05 21:38:47 -06:00
1 parent af6ae6a1d3
commit 7abb343363
150 files changed
+1686 -1687

No files matched your search

+1 -1
View File
@@ -200,7 +200,7 @@ def format_manifest(manifest):
def write_zip(zip_path, prefix=None):
"""Write toolchain data to a zip file."""
if isinstance(prefix, unicode):
if isinstance(prefix, str):
prefix = prefix.encode('utf-8')
with JarWriter(file=zip_path, optimize=False, compress=5) as zip:
+3 -3
View File
@@ -149,7 +149,7 @@ def _nsinstall_internal(argv):
# nsinstall as a native command is always UTF-8
def nsinstall(argv):
return _nsinstall_internal([unicode(arg, "utf-8") for arg in argv])
return _nsinstall_internal([str(arg, "utf-8") for arg in argv])
if __name__ == '__main__':
# sys.argv corrupts characters outside the system code page on Windows
@@ -175,8 +175,8 @@ if __name__ == '__main__':
else:
# For consistency, do it on Unix as well
if sys.stdin.encoding is not None:
argv = [unicode(arg, sys.stdin.encoding) for arg in sys.argv]
argv = [str(arg, sys.stdin.encoding) for arg in sys.argv]
else:
argv = [unicode(arg) for arg in sys.argv]
argv = [str(arg) for arg in sys.argv]
sys.exit(_nsinstall_internal(argv[1:]))
+6 -6
View File
@@ -28,9 +28,9 @@ class TestNsinstall(unittest.TestCase):
# Unicode strings means non-ASCII children can be deleted properly on
# Windows
if sys.stdin.encoding is None:
tmpdir = unicode(self.tmpdir)
tmpdir = str(self.tmpdir)
else:
tmpdir = unicode(self.tmpdir, sys.stdin.encoding)
tmpdir = str(self.tmpdir, sys.stdin.encoding)
rmtree(tmpdir)
# utility methods for tests
@@ -141,9 +141,9 @@ class TestNsinstall(unittest.TestCase):
if RUN_NON_ASCII_TESTS:
def test_nsinstall_non_ascii(self):
"Test that nsinstall handles non-ASCII files"
filename = u"\u2325\u3452\u2415\u5081"
filename = "\u2325\u3452\u2415\u5081"
testfile = self.touch(filename)
testdir = self.mkdirs(u"\u4241\u1D04\u1414")
testdir = self.mkdirs("\u4241\u1D04\u1414")
self.assertEqual(nsinstall([testfile.encode("utf-8"),
testdir.encode("utf-8")]), 0)
@@ -152,9 +152,9 @@ class TestNsinstall(unittest.TestCase):
def test_nsinstall_non_ascii_subprocess(self):
"Test that nsinstall as a subprocess handles non-ASCII files"
filename = u"\u2325\u3452\u2415\u5081"
filename = "\u2325\u3452\u2415\u5081"
testfile = self.touch(filename)
testdir = self.mkdirs(u"\u4241\u1D04\u1414")
testdir = self.mkdirs("\u4241\u1D04\u1414")
# We don't use subprocess because it can't handle Unicode on
# Windows <http://bugs.python.org/issue1759845>. mozprocess calls
# CreateProcessW directly so it's perfect.
+1 -1
View File
@@ -72,7 +72,7 @@ def web_socket_transfer_data(request):
msgutil.send_message(request, resp.decode('utf-8'))
elif request.ws_protocol == "test-12":
msg = msgutil.receive_message(request)
if msg == u'a\ufffdb':
if msg == 'a\ufffdb':
# converted unpaired surrogate in UTF-16 to UTF-8 OK
msgutil.send_message(request, "SUCCESS")
else:
+9 -9
View File
@@ -48,18 +48,18 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'External Media Tests'
copyright = u'2015-2016, Mozilla, Inc.'
author = u'Syd Polk and Maja Frydrychowicz'
project = 'External Media Tests'
copyright = '2015-2016, Mozilla, Inc.'
author = 'Syd Polk and Maja Frydrychowicz'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'0.1'
version = '0.1'
# The full version, including alpha/beta/rc tags.
release = u'0.1'
release = '0.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@@ -235,8 +235,8 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'ExternalMediaTests.tex', u'External Media Tests Documentation',
u'Syd Polk and Maja Frydrychowicz', 'manual'),
(master_doc, 'ExternalMediaTests.tex', 'External Media Tests Documentation',
'Syd Polk and Maja Frydrychowicz', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -265,7 +265,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'externalmediatests', u'External Media Tests Documentation',
(master_doc, 'externalmediatests', 'External Media Tests Documentation',
[author], 1)
]
@@ -279,7 +279,7 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'ExternalMediaTests', u'External Media Tests Documentation',
(master_doc, 'ExternalMediaTests', 'External Media Tests Documentation',
author, 'ExternalMediaTests', 'One line description of project.',
'Miscellaneous'),
]
@@ -408,7 +408,7 @@ class VideoPuppeteer(object):
for field in self._last_seen_video_state._fields:
# For compatibility with different test environments we force ascii
field_ascii = (
unicode(getattr(self._last_seen_video_state, field))
str(getattr(self._last_seen_video_state, field))
.encode('ascii','replace'))
messages += [('\t{}: {}'.format(field, field_ascii))]
messages += '}'
@@ -489,7 +489,7 @@ class YouTubePuppeteer(VideoPuppeteer):
for field in self._last_seen_player_state._fields:
# For compatibility with different test environments we force ascii
field_ascii = (
unicode(getattr(self._last_seen_player_state, field))
str(getattr(self._last_seen_player_state, field))
.encode('ascii', 'replace'))
messages += [('\t{}: {}'.format(field, field_ascii))]
messages += '}'
+1 -1
View File
@@ -918,7 +918,7 @@ def get_variant_set (name):
Returns:
A set of normalized language names.
"""
return set (unicodedata.normalize ('NFD', n.replace ('\u2019', "'"))
return set (unicodedata.normalize ('NFD', n.replace ('\\u2019', "'"))
.encode ('ASCII', 'ignore')
.strip ()
for n in re.split ('[\n(),]', name) if n)
+151 -151
View File
@@ -50,9 +50,9 @@ def writeMappingHeader(println, description, source, url):
if type(description) is not list:
description = [description]
for desc in description:
println(u"// {0}".format(desc))
println(u"// Derived from {0}.".format(source))
println(u"// {0}".format(url))
println("// {0}".format(desc))
println("// Derived from {0}.".format(source))
println("// {0}".format(url))
def writeMappingsVar(println, mapping, name, description, source, url):
""" Writes a variable definition with a mapping table.
@@ -61,12 +61,12 @@ def writeMappingsVar(println, mapping, name, description, source, url):
function with the given variable name and a comment with description,
source, and URL.
"""
println(u"")
println("")
writeMappingHeader(println, description, source, url)
println(u"var {0} = {{".format(name))
println("var {0} = {{".format(name))
for (key, value) in sorted(list(mapping.items()), key=itemgetter(0)):
println(u' "{0}": "{1}",'.format(key, value))
println(u"};")
println(' "{0}": "{1}",'.format(key, value))
println("};")
def writeMappingsBinarySearch(println, fn_name, type_name, name, validate_fn, validate_case_fn,
mappings, tag_maxlength, description, source, url):
@@ -75,9 +75,9 @@ def writeMappingsBinarySearch(println, fn_name, type_name, name, validate_fn, va
Uses the contents of |mapping|, which can either be a dictionary or set,
to emit a mapping function to find subtag replacements.
"""
println(u"")
println("")
writeMappingHeader(println, description, source, url)
println(u"""
println("""
bool js::intl::LanguageTag::{0}({1} {2}) {{
MOZ_ASSERT({3}({2}.span()));
MOZ_ASSERT({4}({2}.span()));
@@ -85,18 +85,18 @@ bool js::intl::LanguageTag::{0}({1} {2}) {{
def write_array(subtags, name, length, fixed):
if fixed:
println(u" static const char {}[{}][{}] = {{".format(name, len(subtags),
println(" static const char {}[{}][{}] = {{".format(name, len(subtags),
length + 1))
else:
println(u" static const char* {}[{}] = {{".format(name, len(subtags)))
println(" static const char* {}[{}] = {{".format(name, len(subtags)))
# Group in pairs of ten to not exceed the 80 line column limit.
for entries in grouper(subtags, 10):
entries = (u"\"{}\"".format(tag).rjust(length + 2)
entries = ("\"{}\"".format(tag).rjust(length + 2)
for tag in entries if tag is not None)
println(u" {},".format(u", ".join(entries)))
println(" {},".format(", ".join(entries)))
println(u" };")
println(" };")
trailing_return = True
@@ -107,12 +107,12 @@ bool js::intl::LanguageTag::{0}({1} {2}) {{
for (length, subtags) in groupby(sorted(mappings_keys, key=len), len):
# Omit the length check if the current length is the maximum length.
if length != tag_maxlength:
println(u"""
println("""
if ({}.length() == {}) {{
""".format(name, length).rstrip("\n"))
else:
trailing_return = False
println(u"""
println("""
{
""".rstrip("\n"))
@@ -120,12 +120,12 @@ bool js::intl::LanguageTag::{0}({1} {2}) {{
subtags = sorted(subtags)
def equals(subtag):
return u"""{}.equalTo("{}")""".format(name, subtag)
return """{}.equalTo("{}")""".format(name, subtag)
# Don't emit a binary search for short lists.
if len(subtags) == 1:
if type(mappings) == dict:
println(u"""
println("""
if ({}) {{
{}.set("{}");
return true;
@@ -133,35 +133,35 @@ bool js::intl::LanguageTag::{0}({1} {2}) {{
return false;
""".format(equals(subtags[0]), name, mappings[subtags[0]]).strip("\n"))
else:
println(u"""
println("""
return {};
""".format(equals(subtags[0])).strip("\n"))
elif len(subtags) <= 4:
if type(mappings) == dict:
for subtag in subtags:
println(u"""
println("""
if ({}) {{
{}.set("{}");
return true;
}}
""".format(equals(subtag), name, mappings[subtag]).strip("\n"))
println(u"""
println("""
return false;
""".strip("\n"))
else:
cond = (equals(subtag) for subtag in subtags)
cond = (u" ||\n" + u" " * (4 + len("return "))).join(cond)
println(u"""
cond = (" ||\n" + " " * (4 + len("return "))).join(cond)
println("""
return {};
""".format(cond).strip("\n"))
else:
write_array(subtags, name + "s", length, True)
if type(mappings) == dict:
write_array([mappings[k] for k in subtags], u"aliases", length, False)
write_array([mappings[k] for k in subtags], "aliases", length, False)
println(u"""
println("""
if (const char* replacement = SearchReplacement({0}s, aliases, {0})) {{
{0}.set(mozilla::MakeCStringSpan(replacement));
return true;
@@ -169,27 +169,27 @@ bool js::intl::LanguageTag::{0}({1} {2}) {{
return false;
""".format(name).rstrip())
else:
println(u"""
println("""
return HasReplacement({0}s, {0});
""".format(name).rstrip())
println(u"""
println("""
}
""".strip("\n"))
if trailing_return:
println(u"""
println("""
return false;""")
println(u"""
println("""
}""".lstrip("\n"))
def writeComplexLanguageTagMappings(println, complex_language_mappings,
description, source, url):
println(u"")
println("")
writeMappingHeader(println, description, source, url)
println(u"""
println("""
void js::intl::LanguageTag::performComplexLanguageMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language().span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language().span()));
@@ -214,42 +214,42 @@ void js::intl::LanguageTag::performComplexLanguageMappings() {
if deprecated_language in language_aliases[key]:
continue
if_kind = u"if" if first_language else u"else if"
if_kind = "if" if first_language else "else if"
first_language = False
cond = (u"language().equalTo(\"{}\")".format(lang)
cond = ("language().equalTo(\"{}\")".format(lang)
for lang in [deprecated_language] + language_aliases[key])
cond = (u" ||\n" + u" " * (2 + len(if_kind) + 2)).join(cond)
cond = (" ||\n" + " " * (2 + len(if_kind) + 2)).join(cond)
println(u"""
println("""
{} ({}) {{""".format(if_kind, cond).strip("\n"))
println(u"""
println("""
setLanguage("{}");""".format(language).strip("\n"))
if script is not None:
println(u"""
println("""
if (script().missing()) {{
setScript("{}");
}}""".format(script).strip("\n"))
if region is not None:
println(u"""
println("""
if (region().missing()) {{
setRegion("{}");
}}""".format(region).strip("\n"))
println(u"""
println("""
}""".strip("\n"))
println(u"""
println("""
}
""".strip("\n"))
def writeComplexRegionTagMappings(println, complex_region_mappings,
description, source, url):
println(u"")
println("")
writeMappingHeader(println, description, source, url)
println(u"""
println("""
void js::intl::LanguageTag::performComplexRegionMappings() {
MOZ_ASSERT(IsStructurallyValidLanguageTag(language().span()));
MOZ_ASSERT(IsCanonicallyCasedLanguageTag(language().span()));
@@ -281,14 +281,14 @@ void js::intl::LanguageTag::performComplexRegionMappings() {
if deprecated_region in region_aliases[key]:
continue
if_kind = u"if" if first_region else u"else if"
if_kind = "if" if first_region else "else if"
first_region = False
cond = (u"region().equalTo(\"{}\")".format(region)
cond = ("region().equalTo(\"{}\")".format(region)
for region in [deprecated_region] + region_aliases[key])
cond = (u" ||\n" + u" " * (2 + len(if_kind) + 2)).join(cond)
cond = (" ||\n" + " " * (2 + len(if_kind) + 2)).join(cond)
println(u"""
println("""
{} ({}) {{""".format(if_kind, cond).strip("\n"))
replacement_regions = sorted({region for (_, _, region) in non_default_replacements})
@@ -301,31 +301,31 @@ void js::intl::LanguageTag::performComplexRegionMappings() {
)
if region == replacement_region)
if_kind = u"if" if first_case else u"else if"
if_kind = "if" if first_case else "else if"
first_case = False
def compare_tags(language, script):
if script is None:
return u"language().equalTo(\"{}\")".format(language)
return u"(language().equalTo(\"{}\") && script().equalTo(\"{}\"))".format(
return "language().equalTo(\"{}\")".format(language)
return "(language().equalTo(\"{}\") && script().equalTo(\"{}\"))".format(
language, script)
cond = (compare_tags(language, script)
for (language, script) in replacement_language_script)
cond = (u" ||\n" + u" " * (4 + len(if_kind) + 2)).join(cond)
cond = (" ||\n" + " " * (4 + len(if_kind) + 2)).join(cond)
println(u"""
println("""
{} ({}) {{
setRegion("{}");
}}""".format(if_kind, cond, replacement_region).rstrip().strip("\n"))
println(u"""
println("""
else {{
setRegion("{}");
}}
}}""".format(default).rstrip().strip("\n"))
println(u"""
println("""
}
""".strip("\n"))
@@ -333,7 +333,7 @@ void js::intl::LanguageTag::performComplexRegionMappings() {
def writeVariantTagMappings(println, variant_mappings, description, source,
url):
""" Writes a function definition that maps variant subtags. """
println(u"""
println("""
static const char* ToCharPointer(const char* str) {
return str;
}
@@ -348,7 +348,7 @@ static bool IsLessThan(const T& a, const U& b) {
}
""")
writeMappingHeader(println, description, source, url)
println(u"""
println("""
bool js::intl::LanguageTag::performVariantMappings(JSContext* cx) {
// The variant subtags need to be sorted for binary search.
MOZ_ASSERT(std::is_sorted(variants_.begin(), variants_.end(),
@@ -382,35 +382,35 @@ bool js::intl::LanguageTag::performVariantMappings(JSContext* cx) {
for (deprecated_variant, (type, replacement)) in (
sorted(list(variant_mappings.items()), key=itemgetter(0))
):
if_kind = u"if" if first_variant else u"else if"
if_kind = "if" if first_variant else "else if"
first_variant = False
println(u"""
println("""
{} (strcmp(variant.get(), "{}") == 0) {{
variants_.erase(variants_.begin() + i);
""".format(if_kind, deprecated_variant).strip("\n"))
if type == "language":
println(u"""
println("""
setLanguage("{}");
""".format(replacement).strip("\n"))
elif type == "region":
println(u"""
println("""
setRegion("{}");
""".format(replacement).strip("\n"))
else:
assert type == "variant"
println(u"""
println("""
if (!insertVariantSortedIfNotPresent("{}")) {{
return false;
}}
""".format(replacement).strip("\n"))
println(u"""
println("""
}
""".strip("\n"))
println(u"""
println("""
else {
i++;
}
@@ -423,9 +423,9 @@ bool js::intl::LanguageTag::performVariantMappings(JSContext* cx) {
def writeGrandfatheredMappingsFunction(println, grandfathered_mappings,
description, source, url):
""" Writes a function definition that maps grandfathered language tags. """
println(u"")
println("")
writeMappingHeader(println, description, source, url)
println(u"""\
println("""\
bool js::intl::LanguageTag::updateGrandfatheredMappings(JSContext* cx) {
// We're mapping regular grandfathered tags to non-grandfathered form here.
// Other tags remain unchanged.
@@ -526,11 +526,11 @@ bool js::intl::LanguageTag::updateGrandfatheredMappings(JSContext* cx) {
modern_variants = modern_match.group("variants")
modern_privateuse = modern_match.group("privateuse")
println(u"""
println("""
// {} -> {}
""".format(tag, modern).rstrip())
println(u"""
println("""
{}if (language().equalTo("{}") && variantEqualTo("{}")) {{
""".format("" if is_first else "else ",
tag_language,
@@ -538,29 +538,29 @@ bool js::intl::LanguageTag::updateGrandfatheredMappings(JSContext* cx) {
is_first = False
println(u"""
println("""
setLanguage("{}");
""".format(modern_language).rstrip().strip("\n"))
if modern_script is not None:
println(u"""
println("""
setScript("{}");
""".format(modern_script).rstrip().strip("\n"))
if modern_region is not None:
println(u"""
println("""
setRegion("{}");
""".format(modern_region).rstrip().strip("\n"))
assert modern_variants is None, (
"all regular grandfathered tags' modern forms do not contain variant subtags")
println(u"""
println("""
clearVariants();
""".rstrip().strip("\n"))
if modern_privateuse is not None:
println(u"""
println("""
auto privateuse = DuplicateString(cx, "{}");
if (!privateuse) {{
return false;
@@ -568,11 +568,11 @@ bool js::intl::LanguageTag::updateGrandfatheredMappings(JSContext* cx) {
setPrivateuse(std::move(privateuse));
""".format(modern_privateuse).rstrip().rstrip("\n"))
println(u"""
println("""
return true;
}""".rstrip().strip("\n"))
println(u"""
println("""
return true;
}""")
@@ -1022,10 +1022,10 @@ def writeCLDRLanguageTagData(println, data, url):
""" Writes the language tag data to the Intl data file. """
println(generatedFileWarning)
println(u"// Version: CLDR-{}".format(data["version"]))
println(u"// URL: {}".format(url))
println("// Version: CLDR-{}".format(data["version"]))
println("// URL: {}".format(url))
println(u"""
println("""
#include "mozilla/Assertions.h"
#include "mozilla/Span.h"
#include "mozilla/TextUtils.h"
@@ -1126,7 +1126,7 @@ static bool IsCanonicallyCasedTransformType(mozilla::Span<const char> type) {
#endif
""".rstrip())
source = u"CLDR Supplemental Data, version {}".format(data["version"])
source = "CLDR Supplemental Data, version {}".format(data["version"])
grandfathered_mappings = data["grandfatheredMappings"]
language_mappings = data["languageMappings"]
complex_language_mappings = data["complexLanguageMappings"]
@@ -1188,7 +1188,7 @@ def writeCLDRLanguageTagLikelySubtagsTest(println, data, url):
println(generatedFileWarning)
source = u"CLDR Supplemental Data, version {}".format(data["version"])
source = "CLDR Supplemental Data, version {}".format(data["version"])
language_mappings = data["languageMappings"]
complex_language_mappings = data["complexLanguageMappings"]
region_mappings = data["regionMappings"]
@@ -1295,17 +1295,17 @@ def writeCLDRLanguageTagLikelySubtagsTest(println, data, url):
writeMappingsVar(println, {bcp47(k): bcp47(v) for (k, v) in list(minimized.items())},
"minLikelySubtags", "Extracted from likelySubtags.xml.", source, url)
println(u"""
println("""
for (let [tag, maximal] of Object.entries(maxLikelySubtags)) {
assertEq(new Intl.Locale(tag).maximize().toString(), maximal);
}""")
println(u"""
println("""
for (let [tag, minimal] of Object.entries(minLikelySubtags)) {
assertEq(new Intl.Locale(tag).minimize().toString(), minimal);
}""")
println(u"""
println("""
if (typeof reportCompare === "function")
reportCompare(0, 0);""")
@@ -1375,7 +1375,7 @@ def updateCLDRLangTags(args):
with io.open(test_file, mode="w", encoding="utf-8", newline="") as f:
println = partial(print, file=f)
println(u"// |reftest| skip-if(!this.hasOwnProperty('Intl'))")
println("// |reftest| skip-if(!this.hasOwnProperty('Intl'))")
writeCLDRLanguageTagLikelySubtagsTest(println, data, url)
@@ -1838,8 +1838,8 @@ def findIncorrectICULinks(ianaZones, ianaLinks, icuZones, icuLinks):
return sorted(result, key=itemgetter(0))
generatedFileWarning = u"// Generated by make_intl_data.py. DO NOT EDIT."
tzdataVersionComment = u"// tzdata version = {0}"
generatedFileWarning = "// Generated by make_intl_data.py. DO NOT EDIT."
tzdataVersionComment = "// tzdata version = {0}"
def processTimeZones(tzdataDir, icuDir, icuTzDir, version, ignoreBackzone, ignoreFactory, out):
""" Read the time zone info and create a new time zone cpp file. """
@@ -1870,51 +1870,51 @@ def processTimeZones(tzdataDir, icuDir, icuTzDir, version, ignoreBackzone, ignor
println(generatedFileWarning)
println(tzdataVersionComment.format(version))
println(u"")
println("")
println(u"#ifndef builtin_intl_TimeZoneDataGenerated_h")
println(u"#define builtin_intl_TimeZoneDataGenerated_h")
println(u"")
println("#ifndef builtin_intl_TimeZoneDataGenerated_h")
println("#define builtin_intl_TimeZoneDataGenerated_h")
println("")
println(u"namespace js {")
println(u"namespace timezone {")
println(u"")
println("namespace js {")
println("namespace timezone {")
println("")
println(u"// Format:")
println(u'// "ZoneName" // ICU-Name [time zone file]')
println(u"const char* const ianaZonesTreatedAsLinksByICU[] = {")
println("// Format:")
println('// "ZoneName" // ICU-Name [time zone file]')
println("const char* const ianaZonesTreatedAsLinksByICU[] = {")
for (zone, icuZone) in incorrectZones:
println(u' "%s", // %s [%s]' % (zone, icuZone, zone.filename))
println(u"};")
println(u"")
println(' "%s", // %s [%s]' % (zone, icuZone, zone.filename))
println("};")
println("")
println(u"// Format:")
println(u'// "LinkName", "Target" // ICU-Target [time zone file]')
println(u"struct LinkAndTarget")
println(u"{")
println(u" const char* const link;")
println(u" const char* const target;")
println(u"};")
println(u"")
println(u"const LinkAndTarget ianaLinksCanonicalizedDifferentlyByICU[] = {")
println("// Format:")
println('// "LinkName", "Target" // ICU-Target [time zone file]')
println("struct LinkAndTarget")
println("{")
println(" const char* const link;")
println(" const char* const target;")
println("};")
println("")
println("const LinkAndTarget ianaLinksCanonicalizedDifferentlyByICU[] = {")
for (zone, target, icuTarget) in incorrectLinks:
println(u' { "%s", "%s" }, // %s [%s]' % (zone, target, icuTarget, zone.filename))
println(u"};")
println(u"")
println(' { "%s", "%s" }, // %s [%s]' % (zone, target, icuTarget, zone.filename))
println("};")
println("")
println(u"// Legacy ICU time zones, these are not valid IANA time zone names. We also")
println(u"// disallow the old and deprecated System V time zones.")
println(u"// https://ssl.icu-project.org/repos/icu/trunk/icu4c/source/tools/tzcode/icuzones")
println(u"const char* const legacyICUTimeZones[] = {")
println("// Legacy ICU time zones, these are not valid IANA time zone names. We also")
println("// disallow the old and deprecated System V time zones.")
println("// https://ssl.icu-project.org/repos/icu/trunk/icu4c/source/tools/tzcode/icuzones")
println("const char* const legacyICUTimeZones[] = {")
for zone in chain(sorted(legacyLinks.keys()), sorted(legacyZones)):
println(u' "%s",' % zone)
println(u"};")
println(u"")
println(' "%s",' % zone)
println("};")
println("")
println(u"} // namespace timezone")
println(u"} // namespace js")
println(u"")
println(u"#endif /* builtin_intl_TimeZoneDataGenerated_h */")
println("} // namespace timezone")
println("} // namespace js")
println("")
println("#endif /* builtin_intl_TimeZoneDataGenerated_h */")
def updateBackzoneLinks(tzdataDir, links):
(backzoneZones, backzoneLinks) = readIANAFiles(tzdataDir, ["backzone"])
@@ -1935,11 +1935,11 @@ def generateTzDataLinkTestContent(testDir, version, fileName, description, links
with io.open(os.path.join(testDir, fileName), mode="w", encoding="utf-8", newline="") as f:
println = partial(print, file=f)
println(u'// |reftest| skip-if(!this.hasOwnProperty("Intl"))')
println(u"")
println('// |reftest| skip-if(!this.hasOwnProperty("Intl"))')
println("")
println(generatedFileWarning)
println(tzdataVersionComment.format(version))
println(u"""
println("""
const tzMapper = [
x => x,
x => x.toUpperCase(),
@@ -1948,12 +1948,12 @@ const tzMapper = [
""")
println(description)
println(u"const links = {")
println("const links = {")
for (zone, target) in sorted(links, key=itemgetter(0)):
println(u' "%s": "%s",' % (zone, target))
println(u"};")
println(' "%s": "%s",' % (zone, target))
println("};")
println(u"""
println("""
for (let [linkName, target] of Object.entries(links)) {
if (target === "Etc/UTC" || target === "Etc/GMT")
target = "UTC";
@@ -1965,7 +1965,7 @@ for (let [linkName, target] of Object.entries(links)) {
}
}
""")
println(u"""
println("""
if (typeof reportCompare === "function")
reportCompare(0, 0, "ok");
""")
@@ -1980,7 +1980,7 @@ def generateTzDataTestBackwardLinks(tzdataDir, version, ignoreBackzone, testDir)
generateTzDataLinkTestContent(
testDir, version,
"timeZone_backward_links.js",
u"// Link names derived from IANA Time Zone Database, backward file.",
"// Link names derived from IANA Time Zone Database, backward file.",
iter(links.items())
)
@@ -1994,7 +1994,7 @@ def generateTzDataTestNotBackwardLinks(tzdataDir, version, ignoreBackzone, testD
generateTzDataLinkTestContent(
testDir, version,
"timeZone_notbackward_links.js",
u"// Link names derived from IANA Time Zone Database, excluding backward file.",
"// Link names derived from IANA Time Zone Database, excluding backward file.",
iter(links.items())
)
@@ -2007,14 +2007,14 @@ def generateTzDataTestBackzone(tzdataDir, version, ignoreBackzone, testDir):
(backzones, backlinks) = readIANAFiles(tzdataDir, bkfiles)
if not ignoreBackzone:
comment=u"""\
comment="""\
// This file was generated with historical, pre-1970 backzone information
// respected. Therefore, every zone key listed below is its own Zone, not
// a Link to a modern-day target as IANA ignoring backzones would say.
"""
else:
comment=u"""\
comment="""\
// This file was generated while ignoring historical, pre-1970 backzone
// information. Therefore, every zone key listed below is part of a Link
// whose target is the corresponding value.
@@ -2024,7 +2024,7 @@ def generateTzDataTestBackzone(tzdataDir, version, ignoreBackzone, testDir):
generateTzDataLinkTestContent(
testDir, version,
"timeZone_backzone.js",
comment + u"// Backzone zones derived from IANA Time Zone Database.",
comment + "// Backzone zones derived from IANA Time Zone Database.",
((zone, zone if not ignoreBackzone else links[zone]) for zone in backzones if zone in links)
)
@@ -2037,7 +2037,7 @@ def generateTzDataTestBackzoneLinks(tzdataDir, version, ignoreBackzone, testDir)
(backzones, backlinks) = readIANAFiles(tzdataDir, bkfiles)
if not ignoreBackzone:
comment=u"""\
comment="""\
// This file was generated with historical, pre-1970 backzone information
// respected. Therefore, every zone key listed below points to a target
// in the backzone file and not to its modern-day target as IANA ignoring
@@ -2045,7 +2045,7 @@ def generateTzDataTestBackzoneLinks(tzdataDir, version, ignoreBackzone, testDir)
"""
else:
comment=u"""\
comment="""\
// This file was generated while ignoring historical, pre-1970 backzone
// information. Therefore, every zone key listed below is part of a Link
// whose target is the corresponding value ignoring any backzone entries.
@@ -2055,7 +2055,7 @@ def generateTzDataTestBackzoneLinks(tzdataDir, version, ignoreBackzone, testDir)
generateTzDataLinkTestContent(
testDir, version,
"timeZone_backzone_links.js",
comment + u"// Backzone links derived from IANA Time Zone Database.",
comment + "// Backzone links derived from IANA Time Zone Database.",
((zone, target if not ignoreBackzone else links[zone]) for (zone, target) in backlinks.items())
)
@@ -2125,7 +2125,7 @@ def updateTzdata(topsrcdir, args):
updateFrom(tzDir)
def writeUnicodeExtensionsMappings(println, mapping, extension):
println(u"""
println("""
template <size_t Length>
static inline bool Is{0}Key(
mozilla::Span<const char> key, const char (&str)[Length]) {{
@@ -2150,7 +2150,7 @@ static inline bool Is{0}Type(
for replacements in list(mapping.values()))
if needs_binary_search:
println(u"""
println("""
static int32_t Compare{0}Type(const char* a, mozilla::Span<const char> b) {{
MOZ_ASSERT(!std::char_traits<char>::find(b.data(), b.size(), '\\0'),
"unexpected null-character in string");
@@ -2186,7 +2186,7 @@ static inline const char* Search{0}Replacement(
}}
""".format(extension).rstrip("\n"))
println(u"""
println("""
/**
* Mapping from deprecated BCP 47 {0} extension types to their preferred
* values.
@@ -2209,14 +2209,14 @@ const char* js::intl::LanguageTag::replace{0}ExtensionType(
def write_array(subtags, name, length):
max_entries = (80 - len(" ")) // (length + len('"", '))
println(u" static const char* {}[{}] = {{".format(name, len(subtags)))
println(" static const char* {}[{}] = {{".format(name, len(subtags)))
for entries in grouper(subtags, max_entries):
entries = (u"\"{}\"".format(tag).rjust(length + 2)
entries = ("\"{}\"".format(tag).rjust(length + 2)
for tag in entries if tag is not None)
println(u" {},".format(u", ".join(entries)))
println(" {},".format(", ".join(entries)))
println(u" };")
println(" };")
# Merge duplicate keys.
key_aliases = {}
@@ -2233,12 +2233,12 @@ const char* js::intl::LanguageTag::replace{0}ExtensionType(
if key in key_aliases[hash_key]:
continue
cond = (u"Is{}Key(key, \"{}\")".format(extension, k)
cond = ("Is{}Key(key, \"{}\")".format(extension, k)
for k in [key] + key_aliases[hash_key])
if_kind = u"if" if first_key else u"else if"
cond = (u" ||\n" + u" " * (2 + len(if_kind) + 2)).join(cond)
println(u"""
if_kind = "if" if first_key else "else if"
cond = (" ||\n" + " " * (2 + len(if_kind) + 2)).join(cond)
println("""
{} ({}) {{""".format(if_kind, cond).strip("\n"))
first_key = False
@@ -2251,20 +2251,20 @@ const char* js::intl::LanguageTag::replace{0}ExtensionType(
write_array(types, "types", max_len)
write_array(preferred, "aliases", max_len)
println(u"""
println("""
return Search{}Replacement(types, aliases, type);
""".format(extension).strip("\n"))
else:
for (type, replacement) in replacements:
println(u"""
println("""
if (Is{}Type(type, "{}")) {{
return "{}";
}}""".format(extension, type, replacement).strip("\n"))
println(u"""
println("""
}""".lstrip("\n"))
println(u"""
println("""
return nullptr;
}
""".strip("\n"))
+2 -2
View File
@@ -7,7 +7,7 @@ from mozilla.prettyprinters import pretty_printer, ptr_pretty_printer
try:
chr(10000) # UPPER RIGHT PENCIL
except ValueError as exc: # yuck, we are in Python 2.x, so chr() is 8-bit
chr = unichr # replace with teh unicodes
chr = chr # replace with teh unicodes
# Forget any printers from previous loads of this module.
mozilla.prettyprinters.clear_module_printers(__name__)
@@ -61,7 +61,7 @@ class JSStringPtr(Common):
yield chars[i]
def to_string(self):
s = u''
s = ''
for c in self.chars():
s += chr(c)
return s
+8 -8
View File
@@ -46,23 +46,23 @@ whitespace = [
0x9, # CHARACTER TABULATION
0xb, # LINE TABULATION
0xc, # FORM FEED
ord(u'\N{SPACE}'),
ord(u'\N{NO-BREAK SPACE}'),
ord(u'\N{ZERO WIDTH NO-BREAK SPACE}'), # also BOM
ord('\N{SPACE}'),
ord('\N{NO-BREAK SPACE}'),
ord('\N{ZERO WIDTH NO-BREAK SPACE}'), # also BOM
]
# §11.3 Line Terminators
line_terminator = [
0xa, # LINE FEED
0xd, # CARRIAGE RETURN
ord(u'\N{LINE SEPARATOR}'),
ord(u'\N{PARAGRAPH SEPARATOR}'),
ord('\N{LINE SEPARATOR}'),
ord('\N{PARAGRAPH SEPARATOR}'),
]
# These are also part of IdentifierPart §11.6 Names and Keywords
compatibility_identifier_part = [
ord(u'\N{ZERO WIDTH NON-JOINER}'),
ord(u'\N{ZERO WIDTH JOINER}'),
ord('\N{ZERO WIDTH NON-JOINER}'),
ord('\N{ZERO WIDTH JOINER}'),
]
FLAG_SPACE = 1 << 0
@@ -825,7 +825,7 @@ def write_special_casing_methods(unconditional_toupper, codepoint_table, println
def make_bmp_mapping_test(version, codepoint_table, unconditional_tolower, unconditional_toupper):
def unicodeEsc(n):
return '\u{:04X}'.format(n)
return '\\u{:04X}'.format(n)
file_name = '../tests/ecma_5/String/string-upper-lower-mapping.js'
with io.open(file_name, mode='wb') as output:
+2 -2
View File
@@ -231,7 +231,7 @@ class DataTable(object):
raise DataTableException("Wrong type %s when expected number" % t_value)
elif value_type == "string":
if isinstance(value, unicode):
if isinstance(value, str):
return value
else:
return str(value).decode("utf-8")
@@ -296,7 +296,7 @@ class DataTable(object):
datetime.date,
datetime.time)):
return str(value)
elif isinstance(value, unicode):
elif isinstance(value, str):
return value
elif isinstance(value, bool):
return str(value).lower()
+2 -2
View File
@@ -2023,7 +2023,7 @@ def CheckForBadCharacters(filename, lines, error):
error: The function to call with any errors found.
"""
for linenum, line in enumerate(lines):
if u'\ufffd' in line:
if '\ufffd' in line:
error(filename, linenum, 'readability/utf8', 5,
'Line contains invalid UTF-8 (or Unicode replacement character).')
if '\0' in line:
@@ -4286,7 +4286,7 @@ def GetLineWidth(line):
The width of the line in column positions, accounting for Unicode
combining characters and wide characters.
"""
if isinstance(line, unicode):
if isinstance(line, str):
width = 0
for uc in unicodedata.normalize('NFC', line):
if unicodedata.east_asian_width(uc) in ('W', 'F'):
+2 -2
View File
@@ -2023,7 +2023,7 @@ def CheckForBadCharacters(filename, lines, error):
error: The function to call with any errors found.
"""
for linenum, line in enumerate(lines):
if u'\ufffd' in line:
if '\ufffd' in line:
error(filename, linenum, 'readability/utf8', 5,
'Line contains invalid UTF-8 (or Unicode replacement character).')
if '\0' in line:
@@ -4286,7 +4286,7 @@ def GetLineWidth(line):
The width of the line in column positions, accounting for Unicode
combining characters and wide characters.
"""
if isinstance(line, unicode):
if isinstance(line, str):
width = 0
for uc in unicodedata.normalize('NFC', line):
if unicodedata.east_asian_width(uc) in ('W', 'F'):
@@ -29,7 +29,7 @@ def _deepcopy_atomic(x):
return x
for x in (type(None), int, int, float,
bool, str, unicode, type):
bool, str, str, type):
d[x] = _deepcopy_atomic
def _deepcopy_list(x):
@@ -324,7 +324,7 @@ class XCObject(object):
that._properties[key] = new_value
else:
that._properties[key] = value
elif isinstance(value, str) or isinstance(value, unicode) or \
elif isinstance(value, str) or isinstance(value, str) or \
isinstance(value, int):
that._properties[key] = value
elif isinstance(value, list):
@@ -603,7 +603,7 @@ class XCObject(object):
comment = value.Comment()
elif isinstance(value, str):
printable += self._EncodeString(value)
elif isinstance(value, unicode):
elif isinstance(value, str):
printable += self._EncodeString(value.encode('utf-8'))
elif isinstance(value, int):
printable += str(value)
@@ -766,7 +766,7 @@ class XCObject(object):
' must be list, not ' + value.__class__.__name__)
for item in value:
if not isinstance(item, property_type) and \
not (item.__class__ == unicode and property_type == str):
not (item.__class__ == str and property_type == str):
# Accept unicode where str is specified. str is treated as
# UTF-8-encoded.
raise TypeError(
@@ -774,7 +774,7 @@ class XCObject(object):
' must be ' + property_type.__name__ + ', not ' + \
item.__class__.__name__)
elif not isinstance(value, property_type) and \
not (value.__class__ == unicode and property_type == str):
not (value.__class__ == str and property_type == str):
# Accept unicode where str is specified. str is treated as
# UTF-8-encoded.
raise TypeError(
@@ -788,7 +788,7 @@ class XCObject(object):
self._properties[property] = value.Copy()
else:
self._properties[property] = value
elif isinstance(value, str) or isinstance(value, unicode) or \
elif isinstance(value, str) or isinstance(value, str) or \
isinstance(value, int):
self._properties[property] = value
elif isinstance(value, list):
@@ -821,13 +821,12 @@ def recv_some(p, t=.1, e=1, tr=5, stderr=0):
time.sleep(max((x-time.time())/tr, 0))
return ''.join(y)
# TODO(3.0: rewrite to use memoryview()
def send_all(p, data):
while len(data):
sent = p.send(data)
if sent is None:
raise Exception(disconnect_message)
data = buffer(data, sent)
data = memoryview(data)[sent:]
@@ -887,9 +887,9 @@ class TestGypMSVS(TestGypOnMSToolchain):
Verifies that a build of the specified Visual Studio target is up to date.
Beware that VS2010 will behave strangely if you build under
C:\USERS\yourname\AppData\Local. It will cause needless work. The ouptut
C:\\USERS\yourname\AppData\Local. It will cause needless work. The ouptut
will be "1 succeeded and 0 up to date". MSBuild tracing reveals that:
"Project 'C:\Users\...\AppData\Local\...vcxproj' not up to date because
"Project 'C:\\Users\...\AppData\Local\...vcxproj' not up to date because
'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 10.0\VC\BIN\1033\CLUI.DLL'
was modified at 02/21/2011 17:03:30, which is newer than '' which was
modified at 01/01/0001 00:00:00.
@@ -33,13 +33,13 @@ class Label:
# non-generated decoder implementation class. Otherwise, the JDK default
# decoder is used as a placeholder.
MULTI_BYTE_DECODER_IMPLEMENTED = [
u"x-user-defined",
u"replacement",
u"big5",
"x-user-defined",
"replacement",
"big5",
]
MULTI_BYTE_ENCODER_IMPLEMENTED = [
u"big5",
"big5",
]
preferred = []
@@ -55,14 +55,14 @@ single_byte = []
multi_byte = []
def to_camel_name(name):
if name == u"iso-8859-8-i":
return u"Iso8I"
if name.startswith(u"iso-8859-"):
return name.replace(u"iso-8859-", u"Iso")
return name.title().replace(u"X-", u"").replace(u"-", u"").replace(u"_", u"")
if name == "iso-8859-8-i":
return "Iso8I"
if name.startswith("iso-8859-"):
return name.replace("iso-8859-", "Iso")
return name.title().replace("X-", "").replace("-", "").replace("_", "")
def to_constant_name(name):
return name.replace(u"-", u"_").upper()
return name.replace("-", "_").upper()
# Encoding.java
@@ -328,8 +328,8 @@ for encoding in single_byte:
labels.sort()
class_name = to_camel_name(name)
mapping_name = name
if mapping_name == u"iso-8859-8-i":
mapping_name = u"iso-8859-8"
if mapping_name == "iso-8859-8-i":
mapping_name = "iso-8859-8"
mapping = indexes[mapping_name]
class_file = open("src/nu/validator/encoding/%s.java" % class_name, "w")
class_file.write('''/*
@@ -377,7 +377,7 @@ class ''')
fallible = True
if comma:
class_file.write(",")
class_file.write("\n '\u%04x'" % code_point);
class_file.write("\n '\\u%04x'" % code_point);
comma = True
class_file.write('''
};
+4 -4
View File
@@ -48,8 +48,8 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'altgraph'
copyright = u'2010-2011, Ronald Oussoren, Bob Ippolito, 2004 Istvan Albert'
project = 'altgraph'
copyright = '2010-2011, Ronald Oussoren, Bob Ippolito, 2004 Istvan Albert'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -183,8 +183,8 @@ htmlhelp_basename = 'altgraphdoc'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'altgraph.tex', u'altgraph Documentation',
u'Ronald Oussoren', 'manual'),
('index', 'altgraph.tex', 'altgraph Documentation',
'Ronald Oussoren', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
+1 -1
View File
@@ -1905,7 +1905,7 @@ class Bits(object):
data = bytearray.fromhex(hexstring)
except TypeError:
# Python 2.6 needs a unicode string (a bug). 2.7 and 3.x work fine.
data = bytearray.fromhex(unicode(hexstring))
data = bytearray.fromhex(str(hexstring))
except ValueError:
raise CreationError("Invalid symbol in hex initialiser.")
self._setbytes_unsafe(data, length * 4, 0)
+10 -10
View File
@@ -272,7 +272,7 @@ class Terminal(object):
# optimization: combine all formatting into a single escape
# sequence.
return self._formatting_string(
u''.join(self._resolve_formatter(s) for s in formatters))
''.join(self._resolve_formatter(s) for s in formatters))
else:
return ParametrizingString(self._resolve_capability(attr))
@@ -289,7 +289,7 @@ class Terminal(object):
# contain chars > 127, and UTF-8 never changes anything within that
# range..
return code.decode('utf-8')
return u''
return ''
def _resolve_color(self, color):
"""Resolve a color like red or on_bright_green into a callable capability."""
@@ -333,7 +333,7 @@ COMPOUNDABLES = (COLORS |
'shadow', 'standout', 'subscript', 'superscript']))
class ParametrizingString(unicode):
class ParametrizingString(str):
"""A Unicode string which can be called to parametrize it as a terminal capability"""
def __new__(cls, formatting, normal=None):
"""Instantiate.
@@ -343,7 +343,7 @@ class ParametrizingString(unicode):
"normal" capability.
"""
new = unicode.__new__(cls, formatting)
new = str.__new__(cls, formatting)
new._normal = normal
return new
@@ -360,7 +360,7 @@ class ParametrizingString(unicode):
# running simply `nosetests` (without progressive) on nose-
# progressive. Perhaps the terminal has gone away between calling
# tigetstr and calling tparm.
return u''
return ''
except TypeError:
# If the first non-int (i.e. incorrect) arg was a string, suggest
# something intelligent:
@@ -375,10 +375,10 @@ class ParametrizingString(unicode):
raise
class FormattingString(unicode):
class FormattingString(str):
"""A Unicode string which can be called upon a piece of text to wrap it in formatting"""
def __new__(cls, formatting, normal):
new = unicode.__new__(cls, formatting)
new = str.__new__(cls, formatting)
new._normal = normal
return new
@@ -393,7 +393,7 @@ class FormattingString(unicode):
return self + text + self._normal
class NullCallableString(unicode):
class NullCallableString(str):
"""A dummy class to stand in for ``FormattingString`` and ``ParametrizingString``
A callable bytestring that returns an empty Unicode when called with an int
@@ -402,12 +402,12 @@ class NullCallableString(unicode):
"""
def __new__(cls):
new = unicode.__new__(cls, u'')
new = str.__new__(cls, '')
return new
def __call__(self, arg):
if isinstance(arg, int):
return u''
return ''
return arg # TODO: Force even strs in Python 2.x to be unicodes? Nah. How would I know what encoding to use to convert it?
+16 -16
View File
@@ -52,8 +52,8 @@ def test_capability():
def test_capability_without_tty():
"""Assert capability templates are '' when stream is not a tty."""
t = TestTerminal(stream=StringIO())
eq_(t.save, u'')
eq_(t.red, u'')
eq_(t.save, '')
eq_(t.red, '')
def test_capability_with_forced_tty():
@@ -84,11 +84,11 @@ def test_location():
t = TestTerminal(stream=StringIO(), force_styling=True)
with t.location(3, 4):
t.stream.write(u'hi')
t.stream.write('hi')
eq_(t.stream.getvalue(), unicode_cap('sc') +
unicode_parm('cup', 4, 3) +
u'hi' +
'hi' +
unicode_cap('rc'))
@@ -111,7 +111,7 @@ def test_null_fileno():
out = StringIO()
out.fileno = None
t = TestTerminal(stream=out)
eq_(t.save, u'')
eq_(t.save, '')
def test_mnemonic_colors():
@@ -179,26 +179,26 @@ def test_formatting_functions():
"""Test crazy-ass formatting wrappers, both simple and compound."""
t = TestTerminal()
# By now, it should be safe to use sugared attributes. Other tests test those.
eq_(t.bold(u'hi'), t.bold + u'hi' + t.normal)
eq_(t.green('hi'), t.green + u'hi' + t.normal) # Plain strs for Python 2.x
eq_(t.bold('hi'), t.bold + 'hi' + t.normal)
eq_(t.green('hi'), t.green + 'hi' + t.normal) # Plain strs for Python 2.x
# Test some non-ASCII chars, probably not necessary:
eq_(t.bold_green(u'boö'), t.bold + t.green + u'boö' + t.normal)
eq_(t.bold_green('boö'), t.bold + t.green + 'boö' + t.normal)
eq_(t.bold_underline_green_on_red('boo'),
t.bold + t.underline + t.green + t.on_red + u'boo' + t.normal)
t.bold + t.underline + t.green + t.on_red + 'boo' + t.normal)
# Don't spell things like this:
eq_(t.on_bright_red_bold_bright_green_underline('meh'),
t.on_bright_red + t.bold + t.bright_green + t.underline + u'meh' + t.normal)
t.on_bright_red + t.bold + t.bright_green + t.underline + 'meh' + t.normal)
def test_formatting_functions_without_tty():
"""Test crazy-ass formatting wrappers when there's no tty."""
t = TestTerminal(stream=StringIO())
eq_(t.bold(u'hi'), u'hi')
eq_(t.green('hi'), u'hi')
eq_(t.bold('hi'), 'hi')
eq_(t.green('hi'), 'hi')
# Test non-ASCII chars, no longer really necessary:
eq_(t.bold_green(u'boö'), u'boö')
eq_(t.bold_underline_green_on_red('loo'), u'loo')
eq_(t.on_bright_red_bold_bright_green_underline('meh'), u'meh')
eq_(t.bold_green('boö'), 'boö')
eq_(t.bold_underline_green_on_red('loo'), 'loo')
eq_(t.on_bright_red_bold_bright_green_underline('meh'), 'meh')
def test_nice_formatting_errors():
@@ -210,7 +210,7 @@ def test_nice_formatting_errors():
assert 'probably misspelled' in e.args[0]
try:
t.bold_misspelled(u'hey') # unicode
t.bold_misspelled('hey') # unicode
except TypeError as e:
assert 'probably misspelled' in e.args[0]
@@ -293,7 +293,7 @@ class DTDChecker(Checker):
col -= len("<!DOCTYPE elem [") # first line is DOCTYPE
yield ('error', (lnr, col), ' '.join(e.args), 'xmlparse')
warntmpl = u'Referencing unknown entity `%s`'
warntmpl = 'Referencing unknown entity `%s`'
if reflist:
if inContext:
elsewhere = reflist - inContext
@@ -542,7 +542,7 @@ class ContentComparer:
if tp == 'error' and self.merge_stage is not None:
skips.append(l10nent)
self.notify(tp, l10n,
u"%s at line %d, column %d for %s" %
"%s at line %d, column %d for %s" %
(msg, _l, col, refent.key))
pass
if missing:
@@ -125,7 +125,7 @@ class Parser:
except UnicodeDecodeError as e:
(logging.getLogger('locales')
.error("Can't read file: " + file + '; ' + str(e)))
self.contents = u''
self.contents = ''
f.close()
def readContents(self, contents):
@@ -219,16 +219,16 @@ class DTDParser(Parser):
# | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] |
# [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] |
# [#x10000-#xEFFFF]
CharMinusDash = u'\x09\x0A\x0D\u0020-\u002C\u002E-\uD7FF\uE000-\uFFFD'
CharMinusDash = '\x09\x0A\x0D\u0020-\u002C\u002E-\uD7FF\uE000-\uFFFD'
XmlComment = '<!--(?:-?[%s])*?-->' % CharMinusDash
NameStartChar = u':A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF' + \
u'\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F' + \
u'\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD'
NameStartChar = ':A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF' + \
'\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F' + \
'\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD'
# + \U00010000-\U000EFFFF seems to be unsupported in python
# NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 |
# [#x0300-#x036F] | [#x203F-#x2040]
NameChar = NameStartChar + ur'\-\.0-9' + u'\xB7\u0300-\u036F\u203F-\u2040'
NameChar = NameStartChar + r'\-\.0-9' + '\xB7\u0300-\u036F\u203F-\u2040'
Name = '[' + NameStartChar + '][' + NameChar + ']*'
reKey = re.compile('(?:(?P<pre>\s*)(?P<precomment>(?:' + XmlComment +
'\s*)*)(?P<entity><!ENTITY\s+(?P<key>' + Name +
@@ -236,9 +236,9 @@ class DTDParser(Parser):
'(?P<post>[ \t]*(?:' + XmlComment + '\s*)*\n?)?)',
re.DOTALL)
# add BOM to DTDs, details in bug 435002
reHeader = re.compile(u'^\ufeff?'
u'(\s*<!--.*(http://mozilla.org/MPL/2.0/|'
u'LICENSE BLOCK)([^-]+-)*[^-]+-->)?', re.S)
reHeader = re.compile('^\ufeff?'
'(\s*<!--.*(http://mozilla.org/MPL/2.0/|'
'LICENSE BLOCK)([^-]+-)*[^-]+-->)?', re.S)
reFooter = re.compile('\s*(<!--([^-]+-)*[^-]+-->\s*)*$')
rePE = re.compile('(?:(\s*)((?:' + XmlComment + '\s*)*)'
'(<!ENTITY\s+%\s+(' + Name +
@@ -341,7 +341,7 @@ class PropertiesParser(Parser):
def unescape(m):
found = m.groupdict()
if found['uni']:
return unichr(int(found['uni'][1:], 16))
return chr(int(found['uni'][1:], 16))
if found['nl']:
return ''
return self.known_escapes.get(found['single'], found['single'])
@@ -111,9 +111,9 @@ class TestDTDs(BaseHelper):
(('warning', (0, 0), 'Referencing unknown entity `not`',
'xmlparse'),))
# make sure we only handle translated entity references
self._test(u'''<!ENTITY foo "This is &ƞǿŧ; good">
self._test('''<!ENTITY foo "This is &ƞǿŧ; good">
'''.encode('utf-8'),
(('warning', (0, 0), u'Referencing unknown entity `ƞǿŧ`',
(('warning', (0, 0), 'Referencing unknown entity `ƞǿŧ`',
'xmlparse'),))
def testErrorFirstLine(self):
@@ -233,10 +233,10 @@ class TestAndroid(unittest.TestCase):
Make sure we're hitting our extra rules only if
we're passing in a DTD file in the embedding/android module.
"""
apos_msg = u"Apostrophes in Android DTDs need escaping with \\' or " + \
u"\\u0027, or use \u2019, or put string in quotes."
quot_msg = u"Quotes in Android DTDs need escaping with \\\" or " + \
u"\\u0022, or put string in apostrophes."
apos_msg = "Apostrophes in Android DTDs need escaping with \\' or " + \
"\\u0027, or use \u2019, or put string in quotes."
quot_msg = "Quotes in Android DTDs need escaping with \\\" or " + \
"\\u0022, or put string in apostrophes."
def getEntity(self, v):
return Entity(v, lambda s: s, (0, len(v)), (), (0, 0), (), (),
@@ -318,12 +318,12 @@ class TestAndroid(unittest.TestCase):
(('error', 2, self.quot_msg, 'android'),))
# broken unicode escape
l10n = self.getDTDEntity("Some broken \u098 unicode")
l10n = self.getDTDEntity("Some broken \\u098 unicode")
self.assertEqual(tuple(checker.check(ref, l10n)),
(('error', 12, 'truncated \\uXXXX escape',
'android'),))
# broken unicode escape, try to set the error off
l10n = self.getDTDEntity(u"\u9690"*14+"\u006"+" "+"\u0064")
l10n = self.getDTDEntity("\u9690"*14+"\\u006"+" "+"\\u0064")
self.assertEqual(tuple(checker.check(ref, l10n)),
(('error', 14, 'truncated \\uXXXX escape',
'android'),))
@@ -81,7 +81,7 @@ eff = effVal""")
'details': {
'children': [
('l10n.properties',
{'value': {'missingEntity': [u'eff', u'foo']}}
{'value': {'missingEntity': ['eff', 'foo']}}
)
]}
}
@@ -115,9 +115,9 @@ eff = leffVal
'children': [
('l10n.properties',
{'value': {
'error': [u'argument 1 `S` should be `d` '
u'at line 1, column 6 for bar'],
'missingEntity': [u'foo']}}
'error': ['argument 1 `S` should be `d` '
'at line 1, column 6 for bar'],
'missingEntity': ['foo']}}
)
]}
}
@@ -151,7 +151,7 @@ eff = leffVal
'details': {
'children': [
('l10n.properties',
{'value': {'obsoleteEntity': [u'other']}})]},
{'value': {'obsoleteEntity': ['other']}})]},
}
)
@@ -212,7 +212,7 @@ class TestDTD(unittest.TestCase, ContentMixin):
'details': {
'children': [
('l10n.dtd',
{'value': {'missingEntity': [u'eff', u'foo']}}
{'value': {'missingEntity': ['eff', 'foo']}}
)
]}
}
@@ -247,9 +247,9 @@ class TestDTD(unittest.TestCase, ContentMixin):
'children': [
('l10n.dtd',
{'value': {
'error': [u'Unparsed content "<!ENTY bar '
u'\'gimmick\'>" at 23-44'],
'missingEntity': [u'bar']}}
'error': ['Unparsed content "<!ENTY bar '
'\'gimmick\'>" at 23-44'],
'missingEntity': ['bar']}}
)
]}
}
@@ -22,8 +22,8 @@ two_lines_triple = This line is one of two and ends in \\\
and still has another line coming
''', (
('one_line', 'This is one line'),
('two_line', u'This is the first of two lines'),
('one_line_trailing', u'This line ends in \\'),
('two_line', 'This is the first of two lines'),
('one_line_trailing', 'This line ends in \\'),
('_junk_\\d+_113-126$', 'and has junk\n'),
('two_lines_triple', 'This line is one of two and ends in \\'
'and still has another line coming')))
@@ -41,11 +41,11 @@ and still has another line coming
def test_bug121341(self):
# port of xpcom/tests/unit/test_bug121341.js
self.parser.readContents(self.resource('bug121341.properties'))
ref = ['abc', 'xy', u"\u1234\t\r\n\u00AB\u0001\n",
ref = ['abc', 'xy', "\u1234\t\r\n\u00AB\u0001\n",
"this is multiline property",
"this is another multiline property", u"test\u0036",
"yet another multiline propery", u"\ttest5\u0020", " test6\t",
u"c\uCDEFd", u"\uABCD"]
"this is another multiline property", "test\u0036",
"yet another multiline propery", "\ttest5\u0020", " test6\t",
"c\uCDEFd", "\uABCD"]
i = iter(self.parser)
for r, e in zip(ref, i):
self.assertEqual(e.val, r)
+1 -1
View File
@@ -1502,7 +1502,7 @@ class ConfigObj(Section):
# NOTE: Could raise a ``UnicodeDecodeError``
return infile.decode(encoding).splitlines(True)
for i, line in enumerate(infile):
if not isinstance(line, unicode):
if not isinstance(line, str):
# NOTE: The isinstance test here handles mixed lists of unicode/string
# NOTE: But the decode will break on any non-string values
# NOTE: Or could raise a ``UnicodeDecodeError``
+4 -4
View File
@@ -37,8 +37,8 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'futures'
copyright = u'2009-2011, Brian Quinlan'
project = 'futures'
copyright = '2009-2011, Brian Quinlan'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -172,8 +172,8 @@ htmlhelp_basename = 'futuresdoc'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'futures.tex', u'futures Documentation',
u'Brian Quinlan', 'manual'),
('index', 'futures.tex', 'futures Documentation',
'Brian Quinlan', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
+1 -1
View File
@@ -45,7 +45,7 @@ def jsmin(js, **kwargs):
returns a minified version of the javascript string
"""
if not is_3:
if cStringIO and not isinstance(js, unicode):
if cStringIO and not isinstance(js, str):
# strings can use cStringIO for a 3x performance
# improvement, but unicode (in python2) cannot
klass = io.StringIO
+2 -2
View File
@@ -260,8 +260,8 @@ var foo = "hey";
assert output == "function foo(''){}"
def testUnicode(self):
instr = u'\u4000 //foo'
expected = u'\u4000'
instr = '\u4000 //foo'
expected = '\u4000'
output = jsmin.jsmin(instr)
self.assertEqual(output, expected)
+2 -2
View File
@@ -109,10 +109,10 @@ class ProcessExecutionMixin(LoggingMixin):
# want UTF-8, they shouldn't pass in a unicode instance.
normalized_env = {}
for k, v in list(use_env.items()):
if isinstance(k, unicode):
if isinstance(k, str):
k = k.encode('utf-8', 'strict')
if isinstance(v, unicode):
if isinstance(v, str):
v = v.encode('utf-8', 'strict')
normalized_env[k] = v
+10 -10
View File
@@ -52,8 +52,8 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'macholib'
copyright = u'2010-2011, Ronald Oussoren'
project = 'macholib'
copyright = '2010-2011, Ronald Oussoren'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -190,8 +190,8 @@ htmlhelp_basename = 'macholibdoc'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'macholib.tex', u'macholib Documentation',
u'Ronald Oussoren', 'manual'),
('index', 'macholib.tex', 'macholib Documentation',
'Ronald Oussoren', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -223,18 +223,18 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'macholib', u'macholib Documentation',
[u'Ronald Oussoren'], 1)
('index', 'macholib', 'macholib Documentation',
['Ronald Oussoren'], 1)
]
# -- Options for Epub output ---------------------------------------------------
# Bibliographic Dublin Core info.
epub_title = u'macholib'
epub_author = u'Ronald Oussoren'
epub_publisher = u'Ronald Oussoren'
epub_copyright = u'2010, Ronald Oussoren'
epub_title = 'macholib'
epub_author = 'Ronald Oussoren'
epub_publisher = 'Ronald Oussoren'
epub_copyright = '2010, Ronald Oussoren'
# The language of the text. It defaults to the language option
# or en if the language is not set.
+3 -3
View File
@@ -15,9 +15,9 @@ except ImportError:
pass
try:
unicode
str
except NameError:
unicode = str
str = str
__all__ = ['MachO']
@@ -338,7 +338,7 @@ class MachOHeader(object):
cmd.to_fileobj(fileobj)
if sys.version_info[0] == 2:
if isinstance(data, unicode):
if isinstance(data, str):
fileobj.write(data.encode(sys.getfilesystemencoding()))
elif isinstance(data, (bytes, str)):
+8 -8
View File
@@ -16,9 +16,9 @@ from macholib.itergraphreport import itergraphreport
__all__ = ['MachOGraph']
try:
unicode
str
except NameError:
unicode = str
str = str
class MissingMachO(object):
def __init__(self, filename):
@@ -39,7 +39,7 @@ class MachOGraph(ObjectGraph):
self.executable_path = executable_path
def locate(self, filename, loader=None):
assert isinstance(filename, (str, unicode))
assert isinstance(filename, (str, str))
if filename.startswith('@loader_path/') and loader is not None:
fn = self.trans_table.get((loader.filename, filename))
if fn is None:
@@ -63,7 +63,7 @@ class MachOGraph(ObjectGraph):
return fn
def findNode(self, name, loader=None):
assert isinstance(name, (str, unicode))
assert isinstance(name, (str, str))
data = super(MachOGraph, self).findNode(name)
if data is not None:
return data
@@ -73,7 +73,7 @@ class MachOGraph(ObjectGraph):
return None
def run_file(self, pathname, caller=None):
assert isinstance(pathname, (str, unicode))
assert isinstance(pathname, (str, str))
self.msgin(2, "run_file", pathname)
m = self.findNode(pathname, loader=caller)
if m is None:
@@ -86,7 +86,7 @@ class MachOGraph(ObjectGraph):
return m
def load_file(self, name, caller=None):
assert isinstance(name, (str, unicode))
assert isinstance(name, (str, str))
self.msgin(2, "load_file", name)
m = self.findNode(name)
if m is None:
@@ -105,8 +105,8 @@ class MachOGraph(ObjectGraph):
self.msgin(2, 'scan_node', node)
for header in node.headers:
for idx, name, filename in header.walkRelocatables():
assert isinstance(name, (str, unicode))
assert isinstance(filename, (str, unicode))
assert isinstance(name, (str, str))
assert isinstance(filename, (str, str))
m = self.load_file(filename, caller=node)
self.createReference(node, m, edge_data=name)
self.msgout(2, '', node)
+1 -1
View File
@@ -34,7 +34,7 @@ _DEFAULT_LIBRARY_FALLBACK = [
if sys.version_info[0] == 2:
def _ensure_utf8(s):
"""Not all of PyObjC and Python understand unicode paths very well yet"""
if isinstance(s, unicode):
if isinstance(s, str):
return s.encode('utf8')
return s
else:
+3 -3
View File
@@ -18,16 +18,16 @@ MAGIC_LEN = 4
STRIPCMD = ['/usr/bin/strip', '-x', '-S', '-']
try:
unicode
str
except NameError:
unicode = str
str = str
def fsencoding(s, encoding=sys.getfilesystemencoding()):
"""
Ensure the given argument is in filesystem encoding (not unicode)
"""
if isinstance(s, unicode):
if isinstance(s, str):
s = s.encode(encoding)
return s
+4 -4
View File
@@ -65,8 +65,8 @@ source_suffix = '.txt'
master_doc = 'index'
# General substitutions.
project = u'Mock'
copyright = u'2007-2012, Michael Foord & the mock team'
project = 'Mock'
copyright = '2007-2012, Michael Foord & the mock team'
# The default replacements for |version| and |release|, also used in various
# other places throughout the built documents.
@@ -187,8 +187,8 @@ latex_font_size = '12pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, document class [howto/manual]).
latex_documents = [
('index', 'Mock.tex', u'Mock Documentation',
u'Michael Foord', 'manual'),
('index', 'Mock.tex', 'Mock Documentation',
'Michael Foord', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
+4 -4
View File
@@ -56,10 +56,10 @@ except ImportError:
return inner
try:
unicode
str
except NameError:
# Python 3
basestring = unicode = str
basestring = str = str
try:
int
@@ -1454,7 +1454,7 @@ def _patch_multiple(target, spec=None, create=False, spec_set=None,
When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
for choosing which methods to wrap.
"""
if type(target) in (unicode, str):
if type(target) in (str, str):
getter = lambda: _importer(target)
else:
getter = lambda: target
@@ -1755,7 +1755,7 @@ _calculate_return_value = {
'__hash__': lambda self: object.__hash__(self),
'__str__': lambda self: object.__str__(self),
'__sizeof__': lambda self: object.__sizeof__(self),
'__unicode__': lambda self: unicode(object.__str__(self)),
'__unicode__': lambda self: str(object.__str__(self)),
}
_return_values = {
+7 -7
View File
@@ -5,10 +5,10 @@
from tests.support import unittest2, inPy3k
try:
unicode
str
except NameError:
# Python 3
unicode = str
str = str
long = int
import inspect
@@ -83,10 +83,10 @@ class TestMockingMagicMethods(unittest2.TestCase):
@unittest2.skipIf(inPy3k, "no unicode in Python 3")
def test_unicode(self):
mock = Mock()
self.assertEqual(unicode(mock), unicode(str(mock)))
self.assertEqual(str(mock), str(str(mock)))
mock.__unicode__ = lambda s: unicode('foo')
self.assertEqual(unicode(mock), unicode('foo'))
mock.__unicode__ = lambda s: str('foo')
self.assertEqual(str(mock), str('foo'))
def test_dict_methods(self):
@@ -321,8 +321,8 @@ class TestMockingMagicMethods(unittest2.TestCase):
self.assertEqual(list(mock), [])
self.assertEqual(hash(mock), object.__hash__(mock))
self.assertEqual(str(mock), object.__str__(mock))
self.assertEqual(unicode(mock), object.__str__(mock))
self.assertIsInstance(unicode(mock), unicode)
self.assertEqual(str(mock), object.__str__(mock))
self.assertIsInstance(str(mock), str)
self.assertTrue(bool(mock))
if not inPy3k:
self.assertEqual(oct(mock), '1')
+3 -3
View File
@@ -20,9 +20,9 @@ from mock import (
try:
unicode
str
except NameError:
unicode = str
str = str
class Iter(object):
@@ -87,7 +87,7 @@ class MockTest(unittest2.TestCase):
def test_unicode_not_broken(self):
# This used to raise an exception with Python 2.5 and Mock 0.4
unicode(Mock())
str(Mock())
def test_return_value_in_constructor(self):
+2 -2
View File
@@ -17,7 +17,7 @@ from mock import (
builtin_string = '__builtin__'
if inPy3k:
builtin_string = 'builtins'
unicode = str
str = str
PTModule = sys.modules[__name__]
MODNAME = '%s.PTModule' % __name__
@@ -1528,7 +1528,7 @@ class PatchTest(unittest2.TestCase):
def test_patch_multiple_string_subclasses(self):
for base in (str, unicode):
for base in (str, str):
Foo = type('Foo', (base,), {'fish': 'tasty'})
foo = Foo()
@patch.multiple(foo, fish='nearly gone')
@@ -17,7 +17,7 @@ from mozbuild.shellutil import quote as shell_quote
if sys.version_info.major == 2:
text_type = unicode
text_type = str
else:
text_type = str
@@ -201,7 +201,7 @@ class BackendMakeFile(object):
self.fh.write(buf)
def write_once(self, buf):
if isinstance(buf, unicode):
if isinstance(buf, str):
buf = buf.encode('utf-8')
if b'\n' + buf not in self.fh.getvalue():
self.write(buf)
@@ -194,7 +194,7 @@ class ConfigureSandbox(dict):
'list', 'tuple', 'set', 'dict', 'isinstance', 'getattr',
'hasattr', 'enumerate', 'range', 'zip', '__build_class__')
if b in __builtins__},
__import__=forbidden_import, str=unicode)
__import__=forbidden_import, str=str)
# Expose a limited set of functions from os.path
OS = ReadOnlyNamespace(path=ReadOnlyNamespace(**{
+1 -1
View File
@@ -52,7 +52,7 @@ class Version(LooseVersion):
def __cmp__(self, other):
# LooseVersion checks isinstance(StringType), so work around it.
if isinstance(other, unicode):
if isinstance(other, str):
other = other.encode('ascii')
return LooseVersion.__cmp__(self, other)
+28 -28
View File
@@ -297,7 +297,7 @@ class InitializedDefines(ContextDerivedValue, OrderedDict):
self.update(value)
class FinalTargetValue(ContextDerivedValue, unicode):
class FinalTargetValue(ContextDerivedValue, str):
def __new__(cls, context, value=""):
if not value:
value = 'dist/'
@@ -307,7 +307,7 @@ class FinalTargetValue(ContextDerivedValue, unicode):
value += 'bin'
if context['DIST_SUBDIR']:
value += '/' + context['DIST_SUBDIR']
return unicode.__new__(cls, value)
return str.__new__(cls, value)
def Enum(*values):
@@ -355,7 +355,7 @@ class PathMeta(type):
cls = SourcePath
return super(PathMeta, cls).__call__(context, value)
class Path(ContextDerivedValue, unicode, metaclass=PathMeta):
class Path(ContextDerivedValue, str, metaclass=PathMeta):
"""Stores and resolves a source path relative to a given context
This class is used as a backing type for some of the sandbox variables.
@@ -385,7 +385,7 @@ class Path(ContextDerivedValue, unicode, metaclass=PathMeta):
def __cmp__(self, other):
if isinstance(other, Path) and self.srcdir != other.srcdir:
return cmp(self.full_path, other.full_path)
return cmp(unicode(self), other)
return cmp(str(self), other)
# __cmp__ is not enough because unicode has __eq__, __ne__, etc. defined
# and __cmp__ is only used for those when they don't exist.
@@ -613,8 +613,8 @@ def TypedListWithAction(typ, action):
return _TypedListWithAction
WebPlatformTestManifest = TypedNamedTuple("WebPlatformTestManifest",
[("manifest_path", unicode),
("test_root", unicode)])
[("manifest_path", str),
("test_root", str)])
ManifestparserManifestList = OrderedListWithAction(read_manifestparser_manifest)
ReftestManifestList = OrderedListWithAction(read_reftest_manifest)
WptManifestList = TypedListWithAction(WebPlatformTestManifest, read_wpt_manifest)
@@ -622,12 +622,12 @@ WptManifestList = TypedListWithAction(WebPlatformTestManifest, read_wpt_manifest
OrderedSourceList = ContextDerivedTypedList(SourcePath, StrictOrderingOnAppendList)
OrderedTestFlavorList = TypedList(Enum(*all_test_flavors()),
StrictOrderingOnAppendList)
OrderedStringList = TypedList(unicode, StrictOrderingOnAppendList)
OrderedStringList = TypedList(str, StrictOrderingOnAppendList)
DependentTestsEntry = ContextDerivedTypedRecord(('files', OrderedSourceList),
('tags', OrderedStringList),
('flavors', OrderedTestFlavorList))
BugzillaComponent = TypedNamedTuple('BugzillaComponent',
[('product', unicode), ('component', unicode)])
[('product', str), ('component', str)])
class Files(SubContext):
@@ -908,7 +908,7 @@ VARIABLES = {
"""),
'GENERATED_FILES': (StrictOrderingOnAppendListWithFlagsFactory({
'script': unicode,
'script': str,
'inputs': list }), list,
"""Generic generated files.
@@ -1053,7 +1053,7 @@ VARIABLES = {
"""Like ``OBJDIR_FILES``, with preprocessing. Use sparingly.
"""),
'FINAL_LIBRARY': (unicode, unicode,
'FINAL_LIBRARY': (str, str,
"""Library in which the objects of the current directory will be linked.
This variable contains the name of a library, defined elsewhere with
@@ -1104,7 +1104,7 @@ VARIABLES = {
"""A list of python unit tests.
"""),
'HOST_LIBRARY_NAME': (unicode, unicode,
'HOST_LIBRARY_NAME': (str, str,
"""Name of target library generated when cross compiling.
"""),
@@ -1122,7 +1122,7 @@ VARIABLES = {
libraries that link into this library via FINAL_LIBRARY.
"""),
'LIBRARY_NAME': (unicode, unicode,
'LIBRARY_NAME': (str, str,
"""The code name of the library generated for a directory.
By default STATIC_LIBRARY_NAME and SHARED_LIBRARY_NAME take this name.
@@ -1134,7 +1134,7 @@ VARIABLES = {
``example/components/xpcomsample.lib`` on Windows.
"""),
'SHARED_LIBRARY_NAME': (unicode, unicode,
'SHARED_LIBRARY_NAME': (str, str,
"""The name of the static library generated for a directory, if it needs to
differ from the library code name.
@@ -1148,7 +1148,7 @@ VARIABLES = {
Implies FORCE_SHARED_LIB.
"""),
'STATIC_LIBRARY_NAME': (unicode, unicode,
'STATIC_LIBRARY_NAME': (str, str,
"""The name of the static library generated for a directory, if it needs to
differ from the library code name.
@@ -1184,37 +1184,37 @@ VARIABLES = {
This variable contains a list of system libaries to link against.
"""),
'RCFILE': (unicode, unicode,
'RCFILE': (str, str,
"""The program .rc file.
This variable can only be used on Windows.
"""),
'RESFILE': (unicode, unicode,
'RESFILE': (str, str,
"""The program .res file.
This variable can only be used on Windows.
"""),
'RCINCLUDE': (unicode, unicode,
'RCINCLUDE': (str, str,
"""The resource script file to be included in the default .res file.
This variable can only be used on Windows.
"""),
'DEFFILE': (unicode, unicode,
'DEFFILE': (str, str,
"""The program .def (module definition) file.
This variable can only be used on Windows.
"""),
'LD_VERSION_SCRIPT': (unicode, unicode,
'LD_VERSION_SCRIPT': (str, str,
"""The linker version script for shared libraries.
This variable can only be used on Linux.
"""),
'SYMBOLS_FILE': (Path, unicode,
'SYMBOLS_FILE': (Path, str,
"""A file containing a list of symbols to export from a shared library.
The given file contains a list of symbols to be exported, and is
@@ -1269,7 +1269,7 @@ VARIABLES = {
``BIN_SUFFIX``, the name will remain unchanged.
"""),
'SONAME': (unicode, unicode,
'SONAME': (str, str,
"""The soname of the shared object currently being linked
soname is the "logical name" of a shared object, often used to provide
@@ -1325,7 +1325,7 @@ VARIABLES = {
``GENERATED_FILES``.
"""),
'PROGRAM' : (unicode, unicode,
'PROGRAM' : (str, str,
"""Compiled executable name.
If the configuration token ``BIN_SUFFIX`` is set, its value will be
@@ -1333,7 +1333,7 @@ VARIABLES = {
``BIN_SUFFIX``, ``PROGRAM`` will remain unchanged.
"""),
'HOST_PROGRAM' : (unicode, unicode,
'HOST_PROGRAM' : (str, str,
"""Compiled host executable name.
If the configuration token ``HOST_BIN_SUFFIX`` is set, its value will be
@@ -1371,7 +1371,7 @@ VARIABLES = {
files.
"""),
'XPIDL_MODULE': (unicode, unicode,
'XPIDL_MODULE': (str, str,
"""XPCOM Interface Definition Module Name.
This is the name of the ``.xpt`` file that is created by linking
@@ -1525,14 +1525,14 @@ VARIABLES = {
"""),
# The following variables are used to control the target of installed files.
'XPI_NAME': (unicode, unicode,
'XPI_NAME': (str, str,
"""The name of an extension XPI to generate.
When this variable is present, the results of this directory will end up
being packaged into an extension instead of the main dist/bin results.
"""),
'DIST_SUBDIR': (unicode, unicode,
'DIST_SUBDIR': (str, str,
"""The name of an alternate directory to install files to.
When this variable is present, the results of this directory will end up
@@ -1540,7 +1540,7 @@ VARIABLES = {
otherwise be placed.
"""),
'FINAL_TARGET': (FinalTargetValue, unicode,
'FINAL_TARGET': (FinalTargetValue, str,
"""The name of the directory to install targets to.
The directory is relative to the top of the object directory. The
@@ -1571,7 +1571,7 @@ VARIABLES = {
'GYP_DIRS': (StrictOrderingOnAppendListWithFlagsFactory({
'variables': dict,
'input': unicode,
'input': str,
'sandbox_vars': dict,
'no_chromium': bool,
'no_unified': bool,
+3 -3
View File
@@ -117,7 +117,7 @@ class TreeMetadataEmitter(LoggingMixin):
# rid ourselves of 2.6.
self.info = {}
for k, v in list(mozinfo.info.items()):
if isinstance(k, unicode):
if isinstance(k, str):
k = k.encode('ascii')
self.info[k] = v
@@ -378,7 +378,7 @@ class TreeMetadataEmitter(LoggingMixin):
"""Verify that a crate's dependencies all specify local paths."""
for dep_crate_name, values in dependencies.items():
# A simple version number.
if isinstance(values, (str, unicode)):
if isinstance(values, (str, str)):
raise SandboxValidationError(
'%s %s of crate %s does not list a path' % (description, dep_crate_name, crate_name),
context)
@@ -1033,7 +1033,7 @@ class TreeMetadataEmitter(LoggingMixin):
script = mozpath.join(mozpath.dirname(mozpath.dirname(__file__)),
'action', 'process_define_files.py')
yield GeneratedFile(context, script, 'process_define_file',
unicode(path),
str(path),
[Path(context, path + '.in')])
generated_files = context.get('GENERATED_FILES')
@@ -42,7 +42,7 @@ script_dir = mozpath.join(chrome_src, 'build')
def encode(value):
if isinstance(value, unicode):
if isinstance(value, str):
return value.encode('utf-8')
return value
+3 -3
View File
@@ -83,7 +83,7 @@ from functools import reduce
if sys.version_info.major == 2:
text_type = unicode
text_type = str
type_type = types.TypeType
else:
text_type = str
@@ -483,7 +483,7 @@ class TemplateFunction(object):
def visit_Str(self, node):
# String nodes we got from the AST parser are str, but we want
# unicode literals everywhere, so transform them.
node.s = unicode(node.s)
node.s = str(node.s)
return node
def visit_Name(self, node):
@@ -616,7 +616,7 @@ class BuildReaderError(Exception):
for l in traceback.format_exception(type(self.other), self.other,
self.trace):
s.write(unicode(l))
s.write(str(l))
return s.getvalue()
+1 -1
View File
@@ -733,7 +733,7 @@ class Preprocessor:
args can either be a file name, or a file-like object.
Files should be opened, and will be closed after processing.
"""
isName = type(args) == str or type(args) == unicode
isName = type(args) == str or type(args) == str
oldCheckLineNumbers = self.checkLineNumbers
self.checkLineNumbers = False
if isName:
@@ -29,7 +29,7 @@ class ConfigEnvironment(ConfigStatus.ConfigEnvironment):
self.substs = ReadOnlyDict(d)
d = dict(self.substs_unicode)
d[u'top_srcdir'] = top_srcdir.decode('utf-8')
d['top_srcdir'] = top_srcdir.decode('utf-8')
self.substs_unicode = ReadOnlyDict(d)
@@ -631,7 +631,7 @@ class TestPaths(unittest.TestCase):
class TestTypedRecord(unittest.TestCase):
def test_fields(self):
T = ContextDerivedTypedRecord(('field1', unicode),
T = ContextDerivedTypedRecord(('field1', str),
('field2', list))
inst = T(None)
self.assertEqual(inst.field1, '')
@@ -647,7 +647,7 @@ class TestTypedRecord(unittest.TestCase):
inst.field3 = []
def test_coercion(self):
T = ContextDerivedTypedRecord(('field1', unicode),
T = ContextDerivedTypedRecord(('field1', str),
('field2', list))
inst = T(None)
inst.field1 = 3
@@ -673,45 +673,45 @@ class TestFiles(unittest.TestCase):
def test_single_bug_component(self):
c = Context({})
f = Files(c, pattern='**')
f['BUG_COMPONENT'] = (u'Product1', u'Component1')
f['BUG_COMPONENT'] = ('Product1', 'Component1')
files = {'moz.build': f}
self.assertEqual(Files.aggregate(files), {
'bug_component_counts': [((u'Product1', u'Component1'), 1)],
'recommended_bug_component': (u'Product1', u'Component1'),
'bug_component_counts': [(('Product1', 'Component1'), 1)],
'recommended_bug_component': ('Product1', 'Component1'),
})
def test_multiple_bug_components(self):
c = Context({})
f1 = Files(c, pattern='**')
f1['BUG_COMPONENT'] = (u'Product1', u'Component1')
f1['BUG_COMPONENT'] = ('Product1', 'Component1')
f2 = Files(c, pattern='**')
f2['BUG_COMPONENT'] = (u'Product2', u'Component2')
f2['BUG_COMPONENT'] = ('Product2', 'Component2')
files = {'a': f1, 'b': f2, 'c': f1}
self.assertEqual(Files.aggregate(files), {
'bug_component_counts': [
((u'Product1', u'Component1'), 2),
((u'Product2', u'Component2'), 1),
(('Product1', 'Component1'), 2),
(('Product2', 'Component2'), 1),
],
'recommended_bug_component': (u'Product1', u'Component1'),
'recommended_bug_component': ('Product1', 'Component1'),
})
def test_no_recommended_bug_component(self):
"""If there is no clear count winner, we don't recommend a bug component."""
c = Context({})
f1 = Files(c, pattern='**')
f1['BUG_COMPONENT'] = (u'Product1', u'Component1')
f1['BUG_COMPONENT'] = ('Product1', 'Component1')
f2 = Files(c, pattern='**')
f2['BUG_COMPONENT'] = (u'Product2', u'Component2')
f2['BUG_COMPONENT'] = ('Product2', 'Component2')
files = {'a': f1, 'b': f2}
self.assertEqual(Files.aggregate(files), {
'bug_component_counts': [
((u'Product1', u'Component1'), 1),
((u'Product2', u'Component2'), 1),
(('Product1', 'Component1'), 1),
(('Product2', 'Component2'), 1),
],
'recommended_bug_component': None,
})
@@ -1013,7 +1013,7 @@ class TestEmitterBasic(unittest.TestCase):
expected = {'install.rdf', 'main.js'}
for f in files:
self.assertTrue(unicode(f) in expected)
self.assertTrue(str(f) in expected)
def test_missing_final_target_pp_files(self):
"""Test that FINAL_TARGET_PP_FILES with missing files throws errors."""
@@ -29,7 +29,7 @@ class Fuga(object):
class Piyo(ContextDerivedValue):
def __init__(self, context, value):
if not isinstance(value, unicode):
if not isinstance(value, str):
raise ValueError
self.context = context
self.value = value
@@ -48,9 +48,9 @@ class Piyo(ContextDerivedValue):
VARIABLES = {
'HOGE': (unicode, unicode, None),
'FUGA': (Fuga, unicode, None),
'PIYO': (Piyo, unicode, None),
'HOGE': (str, str, None),
'FUGA': (Fuga, str, None),
'PIYO': (Piyo, str, None),
'HOGERA': (ContextDerivedTypedList(Piyo, StrictOrderingOnAppendList),
list, None),
'HOGEHOGE': (ContextDerivedTypedListWithItems(
@@ -104,7 +104,7 @@ class TestContext(unittest.TestCase):
self.assertEqual(e[1], 'set_type')
self.assertEqual(e[2], 'HOGE')
self.assertEqual(e[3], True)
self.assertEqual(e[4], unicode)
self.assertEqual(e[4], str)
def test_key_checking(self):
# Checking for existence of a key should not populate the key if it
@@ -127,7 +127,7 @@ class TestContext(unittest.TestCase):
self.assertEqual(e[1], 'set_type')
self.assertEqual(e[2], 'FUGA')
self.assertEqual(e[3], False)
self.assertEqual(e[4], unicode)
self.assertEqual(e[4], str)
ns['FUGA'] = 'fuga'
self.assertIsInstance(ns['FUGA'], Fuga)
@@ -150,7 +150,7 @@ class TestContext(unittest.TestCase):
self.assertEqual(e[1], 'set_type')
self.assertEqual(e[2], 'PIYO')
self.assertEqual(e[3], False)
self.assertEqual(e[4], unicode)
self.assertEqual(e[4], str)
ns['PIYO'] = 'piyo'
self.assertIsInstance(ns['PIYO'], Piyo)
@@ -345,7 +345,7 @@ class TestMozbuildSandbox(unittest.TestCase):
sandbox = MozbuildSandbox(Context(VARIABLES, config))
self.assertEqual(sandbox['CONFIG']['BAD_UTF8'],
u'\ufffd\ufffd\ufffd\ufffd:')
'\ufffd\ufffd\ufffd\ufffd:')
def test_invalid_exports_set_base(self):
sandbox = self.sandbox()
+5 -5
View File
@@ -524,7 +524,7 @@ class TestStrictOrderingOnAppendListWithFlagsFactory(unittest.TestCase):
def test_strict_ordering_on_append_list_with_flags_factory_extend(self):
FooList = StrictOrderingOnAppendListWithFlagsFactory({
'foo': bool, 'bar': unicode
'foo': bool, 'bar': str
})
foo = FooList(['a', 'b', 'c'])
foo['a'].foo = True
@@ -532,7 +532,7 @@ class TestStrictOrderingOnAppendListWithFlagsFactory(unittest.TestCase):
# Don't allow extending lists with different flag definitions.
BarList = StrictOrderingOnAppendListWithFlagsFactory({
'foo': unicode, 'baz': bool
'foo': str, 'baz': bool
})
bar = BarList(['d', 'e', 'f'])
bar['d'].foo = 'foo'
@@ -752,9 +752,9 @@ class TestTypedList(unittest.TestCase):
class TypedTestStrictOrderingOnAppendList(unittest.TestCase):
def test_init(self):
class Unicode(unicode):
class Unicode(str):
def __init__(self, other):
if not isinstance(other, unicode):
if not isinstance(other, str):
raise ValueError()
super(Unicode, self).__init__(other)
@@ -776,7 +776,7 @@ class TypedTestStrictOrderingOnAppendList(unittest.TestCase):
class TestTypedNamedTuple(unittest.TestCase):
def test_simple(self):
FooBar = TypedNamedTuple('FooBar', [('foo', unicode), ('bar', int)])
FooBar = TypedNamedTuple('FooBar', [('foo', str), ('bar', int)])
t = FooBar(foo='foo', bar=2)
self.assertEqual(type(t), FooBar)
+7 -7
View File
@@ -78,7 +78,7 @@ def hash_file(path, hasher=None):
return h.hexdigest()
class EmptyValue(unicode):
class EmptyValue(str):
"""A dummy type that behaves like an empty string and sequence.
This type exists in order to support
@@ -224,7 +224,7 @@ class FileAvoidWrite(BytesIO):
self.mode = mode
def write(self, buf):
if isinstance(buf, unicode):
if isinstance(buf, str):
buf = buf.encode('utf-8')
BytesIO.write(self, buf)
@@ -1149,7 +1149,7 @@ class EnumStringComparisonError(Exception):
pass
class EnumString(unicode):
class EnumString(str):
'''A string type that only can have a limited set of values, similarly to
an Enum, and can only be compared against that set of values.
@@ -1185,13 +1185,13 @@ def _escape_char(c):
# quoting could be done with either ' or ".
if c == "'":
return "\\'"
return unicode(c.encode('unicode_escape'))
return str(c.encode('unicode_escape'))
# Mapping table between raw characters below \x80 and their escaped
# counterpart, when they differ
_INDENTED_REPR_TABLE = {
c: e
for c, e in [(x, _escape_char(x)) for x in list(map(unichr, list(range(128))))]
for c, e in [(x, _escape_char(x)) for x in list(map(chr, list(range(128))))]
if c != e
}
# Regexp matching all characters to escape.
@@ -1222,7 +1222,7 @@ def indented_repr(o, indent=4):
elif isinstance(o, bytes):
yield 'b'
yield repr(o)
elif isinstance(o, unicode):
elif isinstance(o, str):
yield "'"
# We want a readable string (non escaped unicode), but some
# special characters need escaping (e.g. \n, \t, etc.)
@@ -1256,7 +1256,7 @@ def encode(obj, encoding='utf-8'):
}
if isinstance(obj, bytes):
return obj
if isinstance(obj, unicode):
if isinstance(obj, str):
return obj.encode(encoding)
if isinstance(obj, Iterable):
return [encode(i, encoding) for i in obj]
+1 -1
View File
@@ -462,7 +462,7 @@ class VirtualenvManager(object):
"""
execfile(self.activate_path, dict(__file__=self.activate_path))
if isinstance(os.environ['PATH'], unicode):
if isinstance(os.environ['PATH'], str):
os.environ['PATH'] = os.environ['PATH'].encode('utf-8')
def install_pip_package(self, package):
+1 -1
View File
@@ -57,7 +57,7 @@ else:
def _copyfile(src, dest):
# False indicates `dest` should be overwritten if it exists already.
if isinstance(src, unicode) and isinstance(dest, unicode):
if isinstance(src, str) and isinstance(dest, str):
_CopyFileW(src, dest, False)
elif isinstance(src, str) and isinstance(dest, str):
_CopyFileA(src, dest, False)
+2 -2
View File
@@ -56,7 +56,7 @@ class MercurialNativeRevisionFinder(BaseFinder):
Accepts a Mercurial localrepo and changectx instance.
"""
if isinstance(repo, (str, unicode)):
if isinstance(repo, (str, str)):
path = repo
repo = hg.repository(hgui.ui(), repo)
else:
@@ -85,7 +85,7 @@ class MercurialNativeRevisionFinder(BaseFinder):
return self._get(path)
def _get(self, path):
if isinstance(path, unicode):
if isinstance(path, str):
path = path.encode('utf-8', 'replace')
try:
+3 -3
View File
@@ -14,15 +14,15 @@ except ImportError:
class NullTerminal(object):
"""Replacement for `blessings.Terminal()` that does no formatting."""
class NullCallableString(unicode):
class NullCallableString(str):
"""A dummy callable Unicode stolen from blessings"""
def __new__(cls):
new = unicode.__new__(cls, u'')
new = str.__new__(cls, '')
return new
def __call__(self, *args):
if len(args) != 1 or isinstance(args[0], int):
return u''
return ''
return args[0]
def __getattr__(self, attr):
+3 -3
View File
@@ -17,17 +17,17 @@ PY3 = sys.version_info[0] == 3
if PY3:
long = int
xrange = range
unicode = str
str = str
def u(s):
return s
else:
long = int
xrange = xrange
unicode = unicode
str = str
def u(s):
return unicode(s, "unicode_escape")
return str(s, "unicode_escape")
# removed in 3.0, reintroduced in 3.2
+2 -2
View File
@@ -13,7 +13,7 @@ import sys
import time
from ._common import sdiskusage, usage_percent, memoize
from ._compat import PY3, unicode
from ._compat import PY3, str
class TimeoutExpired(Exception):
@@ -120,7 +120,7 @@ def disk_usage(path):
try:
st = os.statvfs(path)
except UnicodeEncodeError:
if not PY3 and isinstance(path, unicode):
if not PY3 and isinstance(path, str):
# this is a bug with os.statvfs() and unicode on
# Python 2, see:
# - https://github.com/giampaolo/psutil/issues/416
+5 -5
View File
@@ -53,7 +53,7 @@ except ImportError:
import mock # requires "pip install mock"
import psutil
from psutil._compat import PY3, callable, int, unicode
from psutil._compat import PY3, callable, int, str
if sys.version_info < (2, 7):
import unittest2 as unittest # https://pypi.python.org/pypi/unittest2
@@ -85,7 +85,7 @@ TESTFN_UNICODE = TESTFN + "ƒőő"
TESTFILE_PREFIX = 'psutil-test-suite-'
if not PY3:
try:
TESTFN_UNICODE = unicode(TESTFN_UNICODE, sys.getfilesystemencoding())
TESTFN_UNICODE = str(TESTFN_UNICODE, sys.getfilesystemencoding())
except UnicodeDecodeError:
TESTFN_UNICODE = TESTFN + "???"
@@ -325,13 +325,13 @@ def check_ip_address(addr, family):
assert 0 <= num <= 255, addr
if ipaddress:
if not PY3:
addr = unicode(addr)
addr = str(addr)
ipaddress.IPv4Address(addr)
elif family == AF_INET6:
assert isinstance(addr, str), addr
if ipaddress:
if not PY3:
addr = unicode(addr)
addr = str(addr)
ipaddress.IPv6Address(addr)
elif family == psutil.AF_LINK:
assert re.match('([a-fA-F0-9]{2}[:|\-]?){6}', addr) is not None, addr
@@ -2434,7 +2434,7 @@ class TestFetchAllProcesses(unittest.TestCase):
self.assertTrue(ret >= 0)
def name(self, ret):
self.assertIsInstance(ret, (str, unicode))
self.assertIsInstance(ret, (str, str))
self.assertTrue(ret)
def create_time(self, ret):
+3 -3
View File
@@ -165,16 +165,16 @@ if sys.version_info >= (3, 0):
else:
import builtins as builtins
_totext = unicode
_totext = str
_basestring = basestring
text = unicode
text = str
bytes = str
execfile = execfile
callable = callable
def _isbytes(x):
return isinstance(x, str)
def _istext(x):
return isinstance(x, unicode)
return isinstance(x, str)
def _getimself(function):
return getattr(function, 'im_self', None)
+1 -1
View File
@@ -70,7 +70,7 @@ def _format_final_exc_line(etype, value):
def _some_str(value):
try:
return unicode(value)
return str(value)
except Exception:
try:
return str(value)
+1 -1
View File
@@ -419,7 +419,7 @@ class ExceptionInfo(object):
def __unicode__(self):
entry = self.traceback[-1]
loc = ReprFileLocation(entry.path, entry.lineno + 1, self.exconly())
return unicode(loc)
return str(loc)
class FormattedExcinfo(object):
+4 -4
View File
@@ -11,8 +11,8 @@ except ImportError:
if sys.version_info < (3,0):
class TextIO(StringIO):
def write(self, data):
if not isinstance(data, unicode):
data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
if not isinstance(data, str):
data = str(data, getattr(self, '_encoding', 'UTF-8'), 'replace')
StringIO.write(self, data)
else:
TextIO = StringIO
@@ -22,7 +22,7 @@ try:
except ImportError:
class BytesIO(StringIO):
def write(self, data):
if isinstance(data, unicode):
if isinstance(data, str):
raise TypeError("not a byte value: %r" %(data,))
StringIO.write(self, data)
@@ -122,7 +122,7 @@ class EncodedFile(object):
self.encoding = encoding
def write(self, obj):
if isinstance(obj, unicode):
if isinstance(obj, str):
obj = obj.encode(self.encoding)
elif isinstance(obj, str):
pass
+2 -2
View File
@@ -21,8 +21,8 @@ def cmdexec(cmd):
default_encoding = sys.getdefaultencoding() # jython may not have it
except AttributeError:
default_encoding = sys.stdout.encoding or 'UTF-8'
out = unicode(out, process.stdout.encoding or default_encoding)
err = unicode(err, process.stderr.encoding or default_encoding)
out = str(out, process.stdout.encoding or default_encoding)
err = str(err, process.stderr.encoding or default_encoding)
status = process.poll()
if status:
raise ExecutionFailed(status, status, cmd, out, err)
+10 -10
View File
@@ -9,14 +9,14 @@ import sys, re
if sys.version_info >= (3,0):
def u(s):
return s
def unicode(x, errors=None):
def str(x, errors=None):
if hasattr(x, '__unicode__'):
return x.__unicode__()
return str(x)
else:
def u(s):
return unicode(s)
unicode = unicode
return str(s)
str = str
class NamespaceMetaclass(type):
@@ -45,10 +45,10 @@ class Tag(list):
self.attr = self.Attr(**kwargs)
def __unicode__(self):
return self.unicode(indent=0)
return self.str(indent=0)
__str__ = __unicode__
def unicode(self, indent=2):
def str(self, indent=2):
l = []
SimpleUnicodeVisitor(l.append, indent).visit(self)
return u("").join(l)
@@ -64,7 +64,7 @@ Namespace = NamespaceMetaclass('Namespace', (object, ), {
})
class HtmlTag(Tag):
def unicode(self, indent=2):
def str(self, indent=2):
l = []
HtmlVisitor(l.append, indent, shortempty=False).visit(self)
return u("").join(l)
@@ -129,7 +129,7 @@ class SimpleUnicodeVisitor(object):
# to avoid clashes with the tag name object
def __object(self, obj):
#self.write(obj)
self.write(escape(unicode(obj)))
self.write(escape(str(obj)))
def raw(self, obj):
self.write(obj.uniobj)
@@ -186,7 +186,7 @@ class SimpleUnicodeVisitor(object):
if isinstance(value, raw):
insert = value.uniobj
else:
insert = escape(unicode(value))
insert = escape(str(value))
return ' %s="%s"' % (name, insert)
def getstyle(self, tag):
@@ -245,9 +245,9 @@ class _escape:
def __call__(self, ustring):
""" xml-escape the given unicode string. """
try:
ustring = unicode(ustring)
ustring = str(ustring)
except UnicodeDecodeError:
ustring = unicode(ustring, 'utf-8', errors='replace')
ustring = str(ustring, 'utf-8', errors='replace')
return self.charef_rex.sub(self._replacer, ustring)
escape = _escape()
+1 -1
View File
@@ -15,7 +15,7 @@ def _get_string_types():
if version_info < (3, ):
return basestring
# The latter evaluates to "bytes" in Python 3 -- even after conversion by 2to3.
return (unicode, type(u"a".encode('utf-8')))
return (str, type("a".encode('utf-8')))
_STRING_TYPES = _get_string_types()
+1 -1
View File
@@ -39,7 +39,7 @@ STRING_ENCODING = sys.getdefaultencoding()
FILE_ENCODING = sys.getdefaultencoding()
# The delimiters to start with when parsing.
DELIMITERS = (u'{{', u'}}')
DELIMITERS = ('{{', '}}')
# How to handle missing tags when rendering a template.
MISSING_TAGS = MissingTags.ignore
+5 -5
View File
@@ -24,7 +24,7 @@ def _make_to_unicode():
"""
if encoding is None:
encoding = defaults.STRING_ENCODING
return unicode(s, encoding, defaults.DECODE_ERRORS)
return str(s, encoding, defaults.DECODE_ERRORS)
return to_unicode
@@ -86,7 +86,7 @@ class Loader(object):
def _make_locator(self):
return Locator(extension=self.extension)
def unicode(self, s, encoding=None):
def str(self, s, encoding=None):
"""
Convert a string to unicode using the given encoding, and return it.
@@ -104,8 +104,8 @@ class Loader(object):
Defaults to None.
"""
if isinstance(s, unicode):
return unicode(s)
if isinstance(s, str):
return str(s)
return self.to_unicode(s, encoding)
@@ -119,7 +119,7 @@ class Loader(object):
if encoding is None:
encoding = self.file_encoding
return self.unicode(b, encoding)
return self.str(b, encoding)
def load_file(self, file_name):
"""
+2 -2
View File
@@ -41,10 +41,10 @@ class ParsedTemplate(object):
"""
# We avoid use of the ternary operator for Python 2.4 support.
def get_unicode(node):
if type(node) is unicode:
if type(node) is str:
return node
return node.render(engine, context)
parts = list(map(get_unicode, self._parse_tree))
s = ''.join(parts)
return unicode(s)
return str(s)
+8 -8
View File
@@ -11,8 +11,8 @@ from pystache import defaults
from pystache.parsed import ParsedTemplate
END_OF_LINE_CHARACTERS = [u'\r', u'\n']
NON_BLANK_RE = re.compile(ur'^(.)', re.M)
END_OF_LINE_CHARACTERS = ['\r', '\n']
NON_BLANK_RE = re.compile(r'^(.)', re.M)
# TODO: add some unit tests for this.
@@ -35,7 +35,7 @@ def parse(template, delimiters=None):
['Hey ', _SectionNode(key='who', index_begin=12, index_end=21, parsed=[_EscapeNode(key='name'), '!'])]
"""
if type(template) is not unicode:
if type(template) is not str:
raise Exception("Template is not unicode: %s" % type(template))
parser = _Parser(delimiters)
return parser.parse(template)
@@ -94,7 +94,7 @@ class _CommentNode(object):
return _format(self)
def render(self, engine, context):
return u''
return ''
class _ChangeNode(object):
@@ -106,7 +106,7 @@ class _ChangeNode(object):
return _format(self)
def render(self, engine, context):
return u''
return ''
class _EscapeNode(object):
@@ -147,7 +147,7 @@ class _PartialNode(object):
def render(self, engine, context):
template = engine.resolve_partial(self.key)
# Indent before rendering.
template = re.sub(NON_BLANK_RE, self.indent + ur'\1', template)
template = re.sub(NON_BLANK_RE, self.indent + r'\1', template)
return engine.render(template, context)
@@ -168,7 +168,7 @@ class _InvertedNode(object):
# Note that lambdas are considered truthy for inverted sections
# per the spec.
if data:
return u''
return ''
return self.parsed_section.render(engine, context)
@@ -218,7 +218,7 @@ class _SectionNode(object):
parts.append(self.parsed.render(engine, context))
context.pop()
return unicode(''.join(parts))
return str(''.join(parts))
class _Parser(object):
+1 -1
View File
@@ -160,7 +160,7 @@ class RenderEngine(object):
if not is_string(val):
# In case the template is an integer, for example.
val = self.to_str(val)
if type(val) is not unicode:
if type(val) is not str:
val = self.literal(val)
return self.render(val, context, delimiters)
+9 -9
View File
@@ -177,16 +177,16 @@ class Renderer(object):
"""
# We type-check to avoid "TypeError: decoding Unicode is not supported".
# We avoid the Python ternary operator for Python 2.4 support.
if isinstance(s, unicode):
if isinstance(s, str):
return s
return self.unicode(s)
return self.str(s)
def _to_unicode_hard(self, s):
"""
Convert a basestring to a string with type unicode (not subclass).
"""
return unicode(self._to_unicode_soft(s))
return str(self._to_unicode_soft(s))
def _escape_to_unicode(self, s):
"""
@@ -195,9 +195,9 @@ class Renderer(object):
Returns a unicode string (not subclass).
"""
return unicode(self.escape(self._to_unicode_soft(s)))
return str(self.escape(self._to_unicode_soft(s)))
def unicode(self, b, encoding=None):
def str(self, b, encoding=None):
"""
Convert a byte string to unicode, using string_encoding and decode_errors.
@@ -222,7 +222,7 @@ class Renderer(object):
# TODO: Wrap UnicodeDecodeErrors with a message about setting
# the string_encoding and decode_errors attributes.
return unicode(b, encoding, self.decode_errors)
return str(b, encoding, self.decode_errors)
def _make_loader(self):
"""
@@ -230,7 +230,7 @@ class Renderer(object):
"""
return Loader(file_encoding=self.file_encoding, extension=self.file_extension,
to_unicode=self.unicode, search_dirs=self.search_dirs)
to_unicode=self.str, search_dirs=self.search_dirs)
def _make_load_template(self):
"""
@@ -299,7 +299,7 @@ class Renderer(object):
try:
return load_partial(name)
except TemplateNotFoundError:
return u''
return ''
return resolve_partial
@@ -316,7 +316,7 @@ class Renderer(object):
try:
return context_get(stack, name)
except KeyNotFoundError:
return u''
return ''
return resolve_context
+1 -1
View File
@@ -83,7 +83,7 @@ class SpecLoader(object):
"""
if spec.template is not None:
return self.loader.unicode(spec.template, spec.template_encoding)
return self.loader.str(spec.template, spec.template_encoding)
path = self._find(spec)
+2 -2
View File
@@ -49,7 +49,7 @@ def format_exception_only(etype, value):
if badline is not None:
if isinstance(badline, bytes): # python 2 only
badline = badline.decode('utf-8', 'replace')
lines.append(u' %s\n' % badline.strip())
lines.append(' %s\n' % badline.strip())
if offset is not None:
caretspace = badline.rstrip('\n')[:offset].lstrip()
# non-space whitespace (likes tabs) must be kept for alignment
@@ -72,7 +72,7 @@ def _format_final_exc_line(etype, value):
def _some_str(value):
try:
return unicode(value)
return str(value)
except Exception:
try:
return str(value)
+1 -1
View File
@@ -425,7 +425,7 @@ class ExceptionInfo(object):
def __unicode__(self):
entry = self.traceback[-1]
loc = ReprFileLocation(entry.path, entry.lineno + 1, self.exconly())
return unicode(loc)
return str(loc)
class FormattedExcinfo(object):
+2 -2
View File
@@ -12,7 +12,7 @@ import py
import pytest
from py.io import TextIO
unicode = py.builtin.text
str = py.builtin.text
patchsysdict = {0: 'stdin', 1: 'stdout', 2: 'stderr'}
@@ -227,7 +227,7 @@ class EncodedFile(object):
self.encoding = encoding
def write(self, obj):
if isinstance(obj, unicode):
if isinstance(obj, str):
obj = obj.encode(self.encoding, "replace")
self.buffer.write(obj)
+10 -10
View File
@@ -19,8 +19,8 @@ import pytest
if sys.version_info[0] < 3:
from codecs import open
else:
unichr = chr
unicode = str
chr = chr
str = str
long = int
@@ -37,11 +37,11 @@ _legal_ranges = (
(0x20, 0x7E), (0x80, 0xD7FF), (0xE000, 0xFFFD), (0x10000, 0x10FFFF),
)
_legal_xml_re = [
unicode("%s-%s") % (unichr(low), unichr(high))
str("%s-%s") % (chr(low), chr(high))
for (low, high) in _legal_ranges if low < sys.maxunicode
]
_legal_xml_re = [unichr(x) for x in _legal_chars] + _legal_xml_re
illegal_xml_re = re.compile(unicode('[^%s]') % unicode('').join(_legal_xml_re))
_legal_xml_re = [chr(x) for x in _legal_chars] + _legal_xml_re
illegal_xml_re = re.compile(str('[^%s]') % str('').join(_legal_xml_re))
del _legal_chars
del _legal_ranges
del _legal_xml_re
@@ -53,9 +53,9 @@ def bin_xml_escape(arg):
def repl(matchobj):
i = ord(matchobj.group())
if i <= 0xFF:
return unicode('#x%02X') % i
return str('#x%02X') % i
else:
return unicode('#x%04X') % i
return str('#x%04X') % i
return py.xml.raw(illegal_xml_re.sub(repl, py.xml.escape(arg)))
@@ -139,7 +139,7 @@ class _NodeReporter(object):
else:
if hasattr(report.longrepr, "reprcrash"):
message = report.longrepr.reprcrash.message
elif isinstance(report.longrepr, (unicode, str)):
elif isinstance(report.longrepr, (str, str)):
message = report.longrepr
else:
message = str(report.longrepr)
@@ -179,7 +179,7 @@ class _NodeReporter(object):
self._write_captured_output(report)
def finalize(self):
data = self.to_xml().unicode(indent=0)
data = self.to_xml().str(indent=0)
self.__dict__.clear()
self.to_xml = lambda: py.xml.raw(data)
@@ -379,7 +379,7 @@ class LogXML(object):
failures=self.stats['failure'],
skips=self.stats['skipped'],
tests=numtests,
time="%.3f" % suite_time_delta, ).unicode(indent=0))
time="%.3f" % suite_time_delta, ).str(indent=0))
logfile.close()
def pytest_terminal_summary(self, terminalreporter):
+1 -1
View File
@@ -1127,7 +1127,7 @@ def _idval(val, argname, idx, idfn):
return str(val)
elif isclass(val) and hasattr(val, '__name__'):
return val.__name__
elif _PY2 and isinstance(val, unicode):
elif _PY2 and isinstance(val, str):
# special case for python 2: if a unicode string is
# convertible to ascii, return it as an str() object instead
try:
+1 -1
View File
@@ -2,7 +2,7 @@ import string, re, sys, datetime
from .core import TomlError
if sys.version_info[0] == 2:
_chr = unichr
_chr = chr
else:
_chr = chr
+3 -3
View File
@@ -3,7 +3,7 @@ import io, datetime, sys
if sys.version_info[0] == 3:
long = int
unicode = str
str = str
def dumps(obj, sort_keys=False):
@@ -59,10 +59,10 @@ def _format_value(v):
if isinstance(v, bool):
return 'true' if v else 'false'
if isinstance(v, int) or isinstance(v, int):
return unicode(v)
return str(v)
if isinstance(v, float):
return '{0:.17f}'.format(v)
elif isinstance(v, unicode) or isinstance(v, bytes):
elif isinstance(v, str) or isinstance(v, bytes):
return _escape_string(v)
elif isinstance(v, datetime.datetime):
offs = v.utcoffset()
@@ -29,10 +29,10 @@ class Style:
def __setstate__(self, state):
self.__init__(**state)
yaml.add_path_resolver(u'tag:yaml.org,2002:python/object:__main__.Style',
yaml.add_path_resolver('tag:yaml.org,2002:python/object:__main__.Style',
[None], dict)
yaml.add_path_resolver(u'tag:yaml.org,2002:pairs',
[None, u'replaces'], list)
yaml.add_path_resolver('tag:yaml.org,2002:pairs',
[None, 'replaces'], list)
class YAMLHighlight:
@@ -51,11 +51,11 @@ class YAMLHighlight:
def highlight(self):
input = self.input.read()
if input.startswith(codecs.BOM_UTF16_LE):
input = unicode(input, 'utf-16-le')
input = str(input, 'utf-16-le')
elif input.startswith(codecs.BOM_UTF16_BE):
input = unicode(input, 'utf-16-be')
input = str(input, 'utf-16-be')
else:
input = unicode(input, 'utf-8')
input = str(input, 'utf-8')
substitutions = self.style.substitutions
tokens = yaml.scan(input)
events = yaml.parse(input)
@@ -90,7 +90,7 @@ class YAMLHighlight:
position = index
chunks.append(substitution)
chunks.reverse()
result = u''.join(chunks)
result = ''.join(chunks)
if self.style.header:
self.output.write(self.style.header)
self.output.write(result.encode('utf-8'))
+3 -3
View File
@@ -88,7 +88,7 @@ class Composer(object):
def compose_scalar_node(self, anchor):
event = self.get_event()
tag = event.tag
if tag is None or tag == u'!':
if tag is None or tag == '!':
tag = self.resolve(ScalarNode, event.value, event.implicit)
node = ScalarNode(tag, event.value,
event.start_mark, event.end_mark, style=event.style)
@@ -99,7 +99,7 @@ class Composer(object):
def compose_sequence_node(self, anchor):
start_event = self.get_event()
tag = start_event.tag
if tag is None or tag == u'!':
if tag is None or tag == '!':
tag = self.resolve(SequenceNode, None, start_event.implicit)
node = SequenceNode(tag, [],
start_event.start_mark, None,
@@ -117,7 +117,7 @@ class Composer(object):
def compose_mapping_node(self, anchor):
start_event = self.get_event()
tag = start_event.tag
if tag is None or tag == u'!':
if tag is None or tag == '!':
tag = self.resolve(MappingNode, None, start_event.implicit)
node = MappingNode(tag, [],
start_event.start_mark, None,
+40 -40
View File
@@ -163,7 +163,7 @@ class SafeConstructor(BaseConstructor):
def construct_scalar(self, node):
if isinstance(node, MappingNode):
for key_node, value_node in node.value:
if key_node.tag == u'tag:yaml.org,2002:value':
if key_node.tag == 'tag:yaml.org,2002:value':
return self.construct_scalar(value_node)
return BaseConstructor.construct_scalar(self, node)
@@ -172,7 +172,7 @@ class SafeConstructor(BaseConstructor):
index = 0
while index < len(node.value):
key_node, value_node = node.value[index]
if key_node.tag == u'tag:yaml.org,2002:merge':
if key_node.tag == 'tag:yaml.org,2002:merge':
del node.value[index]
if isinstance(value_node, MappingNode):
self.flatten_mapping(value_node)
@@ -194,8 +194,8 @@ class SafeConstructor(BaseConstructor):
raise ConstructorError("while constructing a mapping", node.start_mark,
"expected a mapping or list of mappings for merging, but found %s"
% value_node.id, value_node.start_mark)
elif key_node.tag == u'tag:yaml.org,2002:value':
key_node.tag = u'tag:yaml.org,2002:str'
elif key_node.tag == 'tag:yaml.org,2002:value':
key_node.tag = 'tag:yaml.org,2002:str'
index += 1
else:
index += 1
@@ -212,12 +212,12 @@ class SafeConstructor(BaseConstructor):
return None
bool_values = {
u'yes': True,
u'no': False,
u'true': True,
u'false': False,
u'on': True,
u'off': False,
'yes': True,
'no': False,
'true': True,
'false': False,
'on': True,
'off': False,
}
def construct_yaml_bool(self, node):
@@ -290,7 +290,7 @@ class SafeConstructor(BaseConstructor):
"failed to decode base64 data: %s" % exc, node.start_mark)
timestamp_regexp = re.compile(
ur'''^(?P<year>[0-9][0-9][0-9][0-9])
r'''^(?P<year>[0-9][0-9][0-9][0-9])
-(?P<month>[0-9][0-9]?)
-(?P<day>[0-9][0-9]?)
(?:(?:[Tt]|[ \t]+)
@@ -414,51 +414,51 @@ class SafeConstructor(BaseConstructor):
node.start_mark)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:null',
'tag:yaml.org,2002:null',
SafeConstructor.construct_yaml_null)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:bool',
'tag:yaml.org,2002:bool',
SafeConstructor.construct_yaml_bool)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:int',
'tag:yaml.org,2002:int',
SafeConstructor.construct_yaml_int)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:float',
'tag:yaml.org,2002:float',
SafeConstructor.construct_yaml_float)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:binary',
'tag:yaml.org,2002:binary',
SafeConstructor.construct_yaml_binary)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:timestamp',
'tag:yaml.org,2002:timestamp',
SafeConstructor.construct_yaml_timestamp)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:omap',
'tag:yaml.org,2002:omap',
SafeConstructor.construct_yaml_omap)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:pairs',
'tag:yaml.org,2002:pairs',
SafeConstructor.construct_yaml_pairs)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:set',
'tag:yaml.org,2002:set',
SafeConstructor.construct_yaml_set)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:str',
'tag:yaml.org,2002:str',
SafeConstructor.construct_yaml_str)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:seq',
'tag:yaml.org,2002:seq',
SafeConstructor.construct_yaml_seq)
SafeConstructor.add_constructor(
u'tag:yaml.org,2002:map',
'tag:yaml.org,2002:map',
SafeConstructor.construct_yaml_map)
SafeConstructor.add_constructor(None,
@@ -496,7 +496,7 @@ class Constructor(SafeConstructor):
if not name:
raise ConstructorError("while constructing a Python object", mark,
"expected non-empty name appended to the tag", mark)
if u'.' in name:
if '.' in name:
module_name, object_name = name.rsplit('.', 1)
else:
module_name = '__builtin__'
@@ -610,66 +610,66 @@ class Constructor(SafeConstructor):
return self.construct_python_object_apply(suffix, node, newobj=True)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/none',
'tag:yaml.org,2002:python/none',
Constructor.construct_yaml_null)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/bool',
'tag:yaml.org,2002:python/bool',
Constructor.construct_yaml_bool)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/str',
'tag:yaml.org,2002:python/str',
Constructor.construct_python_str)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/unicode',
'tag:yaml.org,2002:python/unicode',
Constructor.construct_python_unicode)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/int',
'tag:yaml.org,2002:python/int',
Constructor.construct_yaml_int)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/long',
'tag:yaml.org,2002:python/long',
Constructor.construct_python_long)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/float',
'tag:yaml.org,2002:python/float',
Constructor.construct_yaml_float)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/complex',
'tag:yaml.org,2002:python/complex',
Constructor.construct_python_complex)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/list',
'tag:yaml.org,2002:python/list',
Constructor.construct_yaml_seq)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/tuple',
'tag:yaml.org,2002:python/tuple',
Constructor.construct_python_tuple)
Constructor.add_constructor(
u'tag:yaml.org,2002:python/dict',
'tag:yaml.org,2002:python/dict',
Constructor.construct_yaml_map)
Constructor.add_multi_constructor(
u'tag:yaml.org,2002:python/name:',
'tag:yaml.org,2002:python/name:',
Constructor.construct_python_name)
Constructor.add_multi_constructor(
u'tag:yaml.org,2002:python/module:',
'tag:yaml.org,2002:python/module:',
Constructor.construct_python_module)
Constructor.add_multi_constructor(
u'tag:yaml.org,2002:python/object:',
'tag:yaml.org,2002:python/object:',
Constructor.construct_python_object)
Constructor.add_multi_constructor(
u'tag:yaml.org,2002:python/object/apply:',
'tag:yaml.org,2002:python/object/apply:',
Constructor.construct_python_object_apply)
Constructor.add_multi_constructor(
u'tag:yaml.org,2002:python/object/new:',
'tag:yaml.org,2002:python/object/new:',
Constructor.construct_python_object_new)
+145 -145
View File
@@ -31,8 +31,8 @@ class ScalarAnalysis(object):
class Emitter(object):
DEFAULT_TAG_PREFIXES = {
u'!' : u'!',
u'tag:yaml.org,2002:' : u'!!',
'!' : '!',
'tag:yaml.org,2002:' : '!!',
}
def __init__(self, stream, canonical=None, indent=None, width=None,
@@ -88,8 +88,8 @@ class Emitter(object):
self.best_width = 80
if width and width > self.best_indent*2:
self.best_width = width
self.best_line_break = u'\n'
if line_break in [u'\r', u'\n', u'\r\n']:
self.best_line_break = '\n'
if line_break in ['\r', '\n', '\r\n']:
self.best_line_break = line_break
# Tag prefixes.
@@ -178,7 +178,7 @@ class Emitter(object):
def expect_document_start(self, first=False):
if isinstance(self.event, DocumentStartEvent):
if (self.event.version or self.event.tags) and self.open_ended:
self.write_indicator(u'...', True)
self.write_indicator('...', True)
self.write_indent()
if self.event.version:
version_text = self.prepare_version(self.event.version)
@@ -198,13 +198,13 @@ class Emitter(object):
and not self.check_empty_document())
if not implicit:
self.write_indent()
self.write_indicator(u'---', True)
self.write_indicator('---', True)
if self.canonical:
self.write_indent()
self.state = self.expect_document_root
elif isinstance(self.event, StreamEndEvent):
if self.open_ended:
self.write_indicator(u'...', True)
self.write_indicator('...', True)
self.write_indent()
self.write_stream_end()
self.state = self.expect_nothing
@@ -216,7 +216,7 @@ class Emitter(object):
if isinstance(self.event, DocumentEndEvent):
self.write_indent()
if self.event.explicit:
self.write_indicator(u'...', True)
self.write_indicator('...', True)
self.write_indent()
self.flush_stream()
self.state = self.expect_document_start
@@ -239,7 +239,7 @@ class Emitter(object):
if isinstance(self.event, AliasEvent):
self.expect_alias()
elif isinstance(self.event, (ScalarEvent, CollectionStartEvent)):
self.process_anchor(u'&')
self.process_anchor('&')
self.process_tag()
if isinstance(self.event, ScalarEvent):
self.expect_scalar()
@@ -261,7 +261,7 @@ class Emitter(object):
def expect_alias(self):
if self.event.anchor is None:
raise EmitterError("anchor is not specified for alias")
self.process_anchor(u'*')
self.process_anchor('*')
self.state = self.states.pop()
def expect_scalar(self):
@@ -273,7 +273,7 @@ class Emitter(object):
# Flow sequence handlers.
def expect_flow_sequence(self):
self.write_indicator(u'[', True, whitespace=True)
self.write_indicator('[', True, whitespace=True)
self.flow_level += 1
self.increase_indent(flow=True)
self.state = self.expect_first_flow_sequence_item
@@ -282,7 +282,7 @@ class Emitter(object):
if isinstance(self.event, SequenceEndEvent):
self.indent = self.indents.pop()
self.flow_level -= 1
self.write_indicator(u']', False)
self.write_indicator(']', False)
self.state = self.states.pop()
else:
if self.canonical or self.column > self.best_width:
@@ -295,12 +295,12 @@ class Emitter(object):
self.indent = self.indents.pop()
self.flow_level -= 1
if self.canonical:
self.write_indicator(u',', False)
self.write_indicator(',', False)
self.write_indent()
self.write_indicator(u']', False)
self.write_indicator(']', False)
self.state = self.states.pop()
else:
self.write_indicator(u',', False)
self.write_indicator(',', False)
if self.canonical or self.column > self.best_width:
self.write_indent()
self.states.append(self.expect_flow_sequence_item)
@@ -309,7 +309,7 @@ class Emitter(object):
# Flow mapping handlers.
def expect_flow_mapping(self):
self.write_indicator(u'{', True, whitespace=True)
self.write_indicator('{', True, whitespace=True)
self.flow_level += 1
self.increase_indent(flow=True)
self.state = self.expect_first_flow_mapping_key
@@ -318,7 +318,7 @@ class Emitter(object):
if isinstance(self.event, MappingEndEvent):
self.indent = self.indents.pop()
self.flow_level -= 1
self.write_indicator(u'}', False)
self.write_indicator('}', False)
self.state = self.states.pop()
else:
if self.canonical or self.column > self.best_width:
@@ -327,7 +327,7 @@ class Emitter(object):
self.states.append(self.expect_flow_mapping_simple_value)
self.expect_node(mapping=True, simple_key=True)
else:
self.write_indicator(u'?', True)
self.write_indicator('?', True)
self.states.append(self.expect_flow_mapping_value)
self.expect_node(mapping=True)
@@ -336,31 +336,31 @@ class Emitter(object):
self.indent = self.indents.pop()
self.flow_level -= 1
if self.canonical:
self.write_indicator(u',', False)
self.write_indicator(',', False)
self.write_indent()
self.write_indicator(u'}', False)
self.write_indicator('}', False)
self.state = self.states.pop()
else:
self.write_indicator(u',', False)
self.write_indicator(',', False)
if self.canonical or self.column > self.best_width:
self.write_indent()
if not self.canonical and self.check_simple_key():
self.states.append(self.expect_flow_mapping_simple_value)
self.expect_node(mapping=True, simple_key=True)
else:
self.write_indicator(u'?', True)
self.write_indicator('?', True)
self.states.append(self.expect_flow_mapping_value)
self.expect_node(mapping=True)
def expect_flow_mapping_simple_value(self):
self.write_indicator(u':', False)
self.write_indicator(':', False)
self.states.append(self.expect_flow_mapping_key)
self.expect_node(mapping=True)
def expect_flow_mapping_value(self):
if self.canonical or self.column > self.best_width:
self.write_indent()
self.write_indicator(u':', True)
self.write_indicator(':', True)
self.states.append(self.expect_flow_mapping_key)
self.expect_node(mapping=True)
@@ -380,7 +380,7 @@ class Emitter(object):
self.state = self.states.pop()
else:
self.write_indent()
self.write_indicator(u'-', True, indention=True)
self.write_indicator('-', True, indention=True)
self.states.append(self.expect_block_sequence_item)
self.expect_node(sequence=True)
@@ -403,18 +403,18 @@ class Emitter(object):
self.states.append(self.expect_block_mapping_simple_value)
self.expect_node(mapping=True, simple_key=True)
else:
self.write_indicator(u'?', True, indention=True)
self.write_indicator('?', True, indention=True)
self.states.append(self.expect_block_mapping_value)
self.expect_node(mapping=True)
def expect_block_mapping_simple_value(self):
self.write_indicator(u':', False)
self.write_indicator(':', False)
self.states.append(self.expect_block_mapping_key)
self.expect_node(mapping=True)
def expect_block_mapping_value(self):
self.write_indent()
self.write_indicator(u':', True, indention=True)
self.write_indicator(':', True, indention=True)
self.states.append(self.expect_block_mapping_key)
self.expect_node(mapping=True)
@@ -433,7 +433,7 @@ class Emitter(object):
return False
event = self.events[0]
return (isinstance(event, ScalarEvent) and event.anchor is None
and event.tag is None and event.implicit and event.value == u'')
and event.tag is None and event.implicit and event.value == '')
def check_simple_key(self):
length = 0
@@ -478,7 +478,7 @@ class Emitter(object):
self.prepared_tag = None
return
if self.event.implicit[0] and tag is None:
tag = u'!'
tag = '!'
self.prepared_tag = None
else:
if (not self.canonical or tag is None) and self.event.implicit:
@@ -541,17 +541,17 @@ class Emitter(object):
major, minor = version
if major != 1:
raise EmitterError("unsupported YAML version: %d.%d" % (major, minor))
return u'%d.%d' % (major, minor)
return '%d.%d' % (major, minor)
def prepare_tag_handle(self, handle):
if not handle:
raise EmitterError("tag handle must not be empty")
if handle[0] != u'!' or handle[-1] != u'!':
if handle[0] != '!' or handle[-1] != '!':
raise EmitterError("tag handle must start and end with '!': %r"
% (handle.encode('utf-8')))
for ch in handle[1:-1]:
if not (u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' \
or ch in u'-_'):
if not ('0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \
or ch in '-_'):
raise EmitterError("invalid character %r in the tag handle: %r"
% (ch.encode('utf-8'), handle.encode('utf-8')))
return handle
@@ -561,12 +561,12 @@ class Emitter(object):
raise EmitterError("tag prefix must not be empty")
chunks = []
start = end = 0
if prefix[0] == u'!':
if prefix[0] == '!':
end = 1
while end < len(prefix):
ch = prefix[end]
if u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' \
or ch in u'-;/?!:@&=+$,_.~*\'()[]':
if '0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \
or ch in '-;/?!:@&=+$,_.~*\'()[]':
end += 1
else:
if start < end:
@@ -574,15 +574,15 @@ class Emitter(object):
start = end = end+1
data = ch.encode('utf-8')
for ch in data:
chunks.append(u'%%%02X' % ord(ch))
chunks.append('%%%02X' % ord(ch))
if start < end:
chunks.append(prefix[start:end])
return u''.join(chunks)
return ''.join(chunks)
def prepare_tag(self, tag):
if not tag:
raise EmitterError("tag must not be empty")
if tag == u'!':
if tag == '!':
return tag
handle = None
suffix = tag
@@ -590,16 +590,16 @@ class Emitter(object):
prefixes.sort()
for prefix in prefixes:
if tag.startswith(prefix) \
and (prefix == u'!' or len(prefix) < len(tag)):
and (prefix == '!' or len(prefix) < len(tag)):
handle = self.tag_prefixes[prefix]
suffix = tag[len(prefix):]
chunks = []
start = end = 0
while end < len(suffix):
ch = suffix[end]
if u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' \
or ch in u'-;/?:@&=+$,_.~*\'()[]' \
or (ch == u'!' and handle != u'!'):
if '0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \
or ch in '-;/?:@&=+$,_.~*\'()[]' \
or (ch == '!' and handle != '!'):
end += 1
else:
if start < end:
@@ -607,21 +607,21 @@ class Emitter(object):
start = end = end+1
data = ch.encode('utf-8')
for ch in data:
chunks.append(u'%%%02X' % ord(ch))
chunks.append('%%%02X' % ord(ch))
if start < end:
chunks.append(suffix[start:end])
suffix_text = u''.join(chunks)
suffix_text = ''.join(chunks)
if handle:
return u'%s%s' % (handle, suffix_text)
return '%s%s' % (handle, suffix_text)
else:
return u'!<%s>' % suffix_text
return '!<%s>' % suffix_text
def prepare_anchor(self, anchor):
if not anchor:
raise EmitterError("anchor must not be empty")
for ch in anchor:
if not (u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' \
or ch in u'-_'):
if not ('0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \
or ch in '-_'):
raise EmitterError("invalid character %r in the anchor: %r"
% (ch.encode('utf-8'), anchor.encode('utf-8')))
return anchor
@@ -650,7 +650,7 @@ class Emitter(object):
space_break = False
# Check document indicators.
if scalar.startswith(u'---') or scalar.startswith(u'...'):
if scalar.startswith('---') or scalar.startswith('...'):
block_indicators = True
flow_indicators = True
@@ -659,7 +659,7 @@ class Emitter(object):
# Last character or followed by a whitespace.
followed_by_whitespace = (len(scalar) == 1 or
scalar[1] in u'\0 \t\r\n\x85\u2028\u2029')
scalar[1] in '\0 \t\r\n\x85\u2028\u2029')
# The previous character is a space.
previous_space = False
@@ -674,34 +674,34 @@ class Emitter(object):
# Check for indicators.
if index == 0:
# Leading indicators are special characters.
if ch in u'#,[]{}&*!|>\'\"%@`':
if ch in '#,[]{}&*!|>\'\"%@`':
flow_indicators = True
block_indicators = True
if ch in u'?:':
if ch in '?:':
flow_indicators = True
if followed_by_whitespace:
block_indicators = True
if ch == u'-' and followed_by_whitespace:
if ch == '-' and followed_by_whitespace:
flow_indicators = True
block_indicators = True
else:
# Some indicators cannot appear within a scalar as well.
if ch in u',?[]{}':
if ch in ',?[]{}':
flow_indicators = True
if ch == u':':
if ch == ':':
flow_indicators = True
if followed_by_whitespace:
block_indicators = True
if ch == u'#' and preceeded_by_whitespace:
if ch == '#' and preceeded_by_whitespace:
flow_indicators = True
block_indicators = True
# Check for line breaks, special, and unicode characters.
if ch in u'\n\x85\u2028\u2029':
if ch in '\n\x85\u2028\u2029':
line_breaks = True
if not (ch == u'\n' or u'\x20' <= ch <= u'\x7E'):
if (ch == u'\x85' or u'\xA0' <= ch <= u'\uD7FF'
or u'\uE000' <= ch <= u'\uFFFD') and ch != u'\uFEFF':
if not (ch == '\n' or '\x20' <= ch <= '\x7E'):
if (ch == '\x85' or '\xA0' <= ch <= '\uD7FF'
or '\uE000' <= ch <= '\uFFFD') and ch != '\uFEFF':
unicode_characters = True
if not self.allow_unicode:
special_characters = True
@@ -709,7 +709,7 @@ class Emitter(object):
special_characters = True
# Detect important whitespace combinations.
if ch == u' ':
if ch == ' ':
if index == 0:
leading_space = True
if index == len(scalar)-1:
@@ -718,7 +718,7 @@ class Emitter(object):
break_space = True
previous_space = True
previous_break = False
elif ch in u'\n\x85\u2028\u2029':
elif ch in '\n\x85\u2028\u2029':
if index == 0:
leading_break = True
if index == len(scalar)-1:
@@ -733,9 +733,9 @@ class Emitter(object):
# Prepare for the next character.
index += 1
preceeded_by_whitespace = (ch in u'\0 \t\r\n\x85\u2028\u2029')
preceeded_by_whitespace = (ch in '\0 \t\r\n\x85\u2028\u2029')
followed_by_whitespace = (index+1 >= len(scalar) or
scalar[index+1] in u'\0 \t\r\n\x85\u2028\u2029')
scalar[index+1] in '\0 \t\r\n\x85\u2028\u2029')
# Let's decide what styles are allowed.
allow_flow_plain = True
@@ -794,7 +794,7 @@ class Emitter(object):
def write_stream_start(self):
# Write BOM if needed.
if self.encoding and self.encoding.startswith('utf-16'):
self.stream.write(u'\uFEFF'.encode(self.encoding))
self.stream.write('\uFEFF'.encode(self.encoding))
def write_stream_end(self):
self.flush_stream()
@@ -804,7 +804,7 @@ class Emitter(object):
if self.whitespace or not need_whitespace:
data = indicator
else:
data = u' '+indicator
data = ' '+indicator
self.whitespace = whitespace
self.indention = self.indention and indention
self.column += len(data)
@@ -820,7 +820,7 @@ class Emitter(object):
self.write_line_break()
if self.column < indent:
self.whitespace = True
data = u' '*(indent-self.column)
data = ' '*(indent-self.column)
self.column = indent
if self.encoding:
data = data.encode(self.encoding)
@@ -838,14 +838,14 @@ class Emitter(object):
self.stream.write(data)
def write_version_directive(self, version_text):
data = u'%%YAML %s' % version_text
data = '%%YAML %s' % version_text
if self.encoding:
data = data.encode(self.encoding)
self.stream.write(data)
self.write_line_break()
def write_tag_directive(self, handle_text, prefix_text):
data = u'%%TAG %s %s' % (handle_text, prefix_text)
data = '%%TAG %s %s' % (handle_text, prefix_text)
if self.encoding:
data = data.encode(self.encoding)
self.stream.write(data)
@@ -854,7 +854,7 @@ class Emitter(object):
# Scalar streams.
def write_single_quoted(self, text, split=True):
self.write_indicator(u'\'', True)
self.write_indicator('\'', True)
spaces = False
breaks = False
start = end = 0
@@ -863,7 +863,7 @@ class Emitter(object):
if end < len(text):
ch = text[end]
if spaces:
if ch is None or ch != u' ':
if ch is None or ch != ' ':
if start+1 == end and self.column > self.best_width and split \
and start != 0 and end != len(text):
self.write_indent()
@@ -875,18 +875,18 @@ class Emitter(object):
self.stream.write(data)
start = end
elif breaks:
if ch is None or ch not in u'\n\x85\u2028\u2029':
if text[start] == u'\n':
if ch is None or ch not in '\n\x85\u2028\u2029':
if text[start] == '\n':
self.write_line_break()
for br in text[start:end]:
if br == u'\n':
if br == '\n':
self.write_line_break()
else:
self.write_line_break(br)
self.write_indent()
start = end
else:
if ch is None or ch in u' \n\x85\u2028\u2029' or ch == u'\'':
if ch is None or ch in ' \n\x85\u2028\u2029' or ch == '\'':
if start < end:
data = text[start:end]
self.column += len(data)
@@ -894,49 +894,49 @@ class Emitter(object):
data = data.encode(self.encoding)
self.stream.write(data)
start = end
if ch == u'\'':
data = u'\'\''
if ch == '\'':
data = '\'\''
self.column += 2
if self.encoding:
data = data.encode(self.encoding)
self.stream.write(data)
start = end + 1
if ch is not None:
spaces = (ch == u' ')
breaks = (ch in u'\n\x85\u2028\u2029')
spaces = (ch == ' ')
breaks = (ch in '\n\x85\u2028\u2029')
end += 1
self.write_indicator(u'\'', False)
self.write_indicator('\'', False)
ESCAPE_REPLACEMENTS = {
u'\0': u'0',
u'\x07': u'a',
u'\x08': u'b',
u'\x09': u't',
u'\x0A': u'n',
u'\x0B': u'v',
u'\x0C': u'f',
u'\x0D': u'r',
u'\x1B': u'e',
u'\"': u'\"',
u'\\': u'\\',
u'\x85': u'N',
u'\xA0': u'_',
u'\u2028': u'L',
u'\u2029': u'P',
'\0': '0',
'\x07': 'a',
'\x08': 'b',
'\x09': 't',
'\x0A': 'n',
'\x0B': 'v',
'\x0C': 'f',
'\x0D': 'r',
'\x1B': 'e',
'\"': '\"',
'\\': '\\',
'\x85': 'N',
'\xA0': '_',
'\u2028': 'L',
'\u2029': 'P',
}
def write_double_quoted(self, text, split=True):
self.write_indicator(u'"', True)
self.write_indicator('"', True)
start = end = 0
while end <= len(text):
ch = None
if end < len(text):
ch = text[end]
if ch is None or ch in u'"\\\x85\u2028\u2029\uFEFF' \
or not (u'\x20' <= ch <= u'\x7E'
if ch is None or ch in '"\\\x85\u2028\u2029\uFEFF' \
or not ('\x20' <= ch <= '\x7E'
or (self.allow_unicode
and (u'\xA0' <= ch <= u'\uD7FF'
or u'\uE000' <= ch <= u'\uFFFD'))):
and ('\xA0' <= ch <= '\uD7FF'
or '\uE000' <= ch <= '\uFFFD'))):
if start < end:
data = text[start:end]
self.column += len(data)
@@ -946,21 +946,21 @@ class Emitter(object):
start = end
if ch is not None:
if ch in self.ESCAPE_REPLACEMENTS:
data = u'\\'+self.ESCAPE_REPLACEMENTS[ch]
elif ch <= u'\xFF':
data = u'\\x%02X' % ord(ch)
elif ch <= u'\uFFFF':
data = u'\\u%04X' % ord(ch)
data = '\\'+self.ESCAPE_REPLACEMENTS[ch]
elif ch <= '\xFF':
data = '\\x%02X' % ord(ch)
elif ch <= '\uFFFF':
data = '\\u%04X' % ord(ch)
else:
data = u'\\U%08X' % ord(ch)
data = '\\U%08X' % ord(ch)
self.column += len(data)
if self.encoding:
data = data.encode(self.encoding)
self.stream.write(data)
start = end+1
if 0 < end < len(text)-1 and (ch == u' ' or start >= end) \
if 0 < end < len(text)-1 and (ch == ' ' or start >= end) \
and self.column+(end-start) > self.best_width and split:
data = text[start:end]+u'\\'
data = text[start:end]+'\\'
if start < end:
start = end
self.column += len(data)
@@ -970,30 +970,30 @@ class Emitter(object):
self.write_indent()
self.whitespace = False
self.indention = False
if text[start] == u' ':
data = u'\\'
if text[start] == ' ':
data = '\\'
self.column += len(data)
if self.encoding:
data = data.encode(self.encoding)
self.stream.write(data)
end += 1
self.write_indicator(u'"', False)
self.write_indicator('"', False)
def determine_block_hints(self, text):
hints = u''
hints = ''
if text:
if text[0] in u' \n\x85\u2028\u2029':
hints += unicode(self.best_indent)
if text[-1] not in u'\n\x85\u2028\u2029':
hints += u'-'
elif len(text) == 1 or text[-2] in u'\n\x85\u2028\u2029':
hints += u'+'
if text[0] in ' \n\x85\u2028\u2029':
hints += str(self.best_indent)
if text[-1] not in '\n\x85\u2028\u2029':
hints += '-'
elif len(text) == 1 or text[-2] in '\n\x85\u2028\u2029':
hints += '+'
return hints
def write_folded(self, text):
hints = self.determine_block_hints(text)
self.write_indicator(u'>'+hints, True)
if hints[-1:] == u'+':
self.write_indicator('>'+hints, True)
if hints[-1:] == '+':
self.open_ended = True
self.write_line_break()
leading_space = True
@@ -1005,13 +1005,13 @@ class Emitter(object):
if end < len(text):
ch = text[end]
if breaks:
if ch is None or ch not in u'\n\x85\u2028\u2029':
if not leading_space and ch is not None and ch != u' ' \
and text[start] == u'\n':
if ch is None or ch not in '\n\x85\u2028\u2029':
if not leading_space and ch is not None and ch != ' ' \
and text[start] == '\n':
self.write_line_break()
leading_space = (ch == u' ')
leading_space = (ch == ' ')
for br in text[start:end]:
if br == u'\n':
if br == '\n':
self.write_line_break()
else:
self.write_line_break(br)
@@ -1019,7 +1019,7 @@ class Emitter(object):
self.write_indent()
start = end
elif spaces:
if ch != u' ':
if ch != ' ':
if start+1 == end and self.column > self.best_width:
self.write_indent()
else:
@@ -1030,7 +1030,7 @@ class Emitter(object):
self.stream.write(data)
start = end
else:
if ch is None or ch in u' \n\x85\u2028\u2029':
if ch is None or ch in ' \n\x85\u2028\u2029':
data = text[start:end]
self.column += len(data)
if self.encoding:
@@ -1040,14 +1040,14 @@ class Emitter(object):
self.write_line_break()
start = end
if ch is not None:
breaks = (ch in u'\n\x85\u2028\u2029')
spaces = (ch == u' ')
breaks = (ch in '\n\x85\u2028\u2029')
spaces = (ch == ' ')
end += 1
def write_literal(self, text):
hints = self.determine_block_hints(text)
self.write_indicator(u'|'+hints, True)
if hints[-1:] == u'+':
self.write_indicator('|'+hints, True)
if hints[-1:] == '+':
self.open_ended = True
self.write_line_break()
breaks = True
@@ -1057,9 +1057,9 @@ class Emitter(object):
if end < len(text):
ch = text[end]
if breaks:
if ch is None or ch not in u'\n\x85\u2028\u2029':
if ch is None or ch not in '\n\x85\u2028\u2029':
for br in text[start:end]:
if br == u'\n':
if br == '\n':
self.write_line_break()
else:
self.write_line_break(br)
@@ -1067,7 +1067,7 @@ class Emitter(object):
self.write_indent()
start = end
else:
if ch is None or ch in u'\n\x85\u2028\u2029':
if ch is None or ch in '\n\x85\u2028\u2029':
data = text[start:end]
if self.encoding:
data = data.encode(self.encoding)
@@ -1076,7 +1076,7 @@ class Emitter(object):
self.write_line_break()
start = end
if ch is not None:
breaks = (ch in u'\n\x85\u2028\u2029')
breaks = (ch in '\n\x85\u2028\u2029')
end += 1
def write_plain(self, text, split=True):
@@ -1085,7 +1085,7 @@ class Emitter(object):
if not text:
return
if not self.whitespace:
data = u' '
data = ' '
self.column += len(data)
if self.encoding:
data = data.encode(self.encoding)
@@ -1100,7 +1100,7 @@ class Emitter(object):
if end < len(text):
ch = text[end]
if spaces:
if ch != u' ':
if ch != ' ':
if start+1 == end and self.column > self.best_width and split:
self.write_indent()
self.whitespace = False
@@ -1113,11 +1113,11 @@ class Emitter(object):
self.stream.write(data)
start = end
elif breaks:
if ch not in u'\n\x85\u2028\u2029':
if text[start] == u'\n':
if ch not in '\n\x85\u2028\u2029':
if text[start] == '\n':
self.write_line_break()
for br in text[start:end]:
if br == u'\n':
if br == '\n':
self.write_line_break()
else:
self.write_line_break(br)
@@ -1126,7 +1126,7 @@ class Emitter(object):
self.indention = False
start = end
else:
if ch is None or ch in u' \n\x85\u2028\u2029':
if ch is None or ch in ' \n\x85\u2028\u2029':
data = text[start:end]
self.column += len(data)
if self.encoding:
@@ -1134,7 +1134,7 @@ class Emitter(object):
self.stream.write(data)
start = end
if ch is not None:
spaces = (ch == u' ')
breaks = (ch in u'\n\x85\u2028\u2029')
spaces = (ch == ' ')
breaks = (ch in '\n\x85\u2028\u2029')
end += 1
+2 -2
View File
@@ -16,7 +16,7 @@ class Mark(object):
return None
head = ''
start = self.pointer
while start > 0 and self.buffer[start-1] not in u'\0\r\n\x85\u2028\u2029':
while start > 0 and self.buffer[start-1] not in '\0\r\n\x85\u2028\u2029':
start -= 1
if self.pointer-start > max_length/2-1:
head = ' ... '
@@ -24,7 +24,7 @@ class Mark(object):
break
tail = ''
end = self.pointer
while end < len(self.buffer) and self.buffer[end] not in u'\0\r\n\x85\u2028\u2029':
while end < len(self.buffer) and self.buffer[end] not in '\0\r\n\x85\u2028\u2029':
end += 1
if end-self.pointer > max_length/2-1:
tail = ' ... '
+8 -8
View File
@@ -74,8 +74,8 @@ class Parser(object):
# do not give many comments here.
DEFAULT_TAGS = {
u'!': u'!',
u'!!': u'tag:yaml.org,2002:',
'!': '!',
'!!': 'tag:yaml.org,2002:',
}
def __init__(self):
@@ -219,7 +219,7 @@ class Parser(object):
self.tag_handles = {}
while self.check_token(DirectiveToken):
token = self.get_token()
if token.name == u'YAML':
if token.name == 'YAML':
if self.yaml_version is not None:
raise ParserError(None, None,
"found duplicate YAML directive", token.start_mark)
@@ -229,7 +229,7 @@ class Parser(object):
"found incompatible YAML document (version 1.* is required)",
token.start_mark)
self.yaml_version = token.value
elif token.name == u'TAG':
elif token.name == 'TAG':
handle, prefix = token.value
if handle in self.tag_handles:
raise ParserError(None, None,
@@ -315,7 +315,7 @@ class Parser(object):
if start_mark is None:
start_mark = end_mark = self.peek_token().start_mark
event = None
implicit = (tag is None or tag == u'!')
implicit = (tag is None or tag == '!')
if indentless_sequence and self.check_token(BlockEntryToken):
end_mark = self.peek_token().end_mark
event = SequenceStartEvent(anchor, tag, implicit,
@@ -325,7 +325,7 @@ class Parser(object):
if self.check_token(ScalarToken):
token = self.get_token()
end_mark = token.end_mark
if (token.plain and tag is None) or tag == u'!':
if (token.plain and tag is None) or tag == '!':
implicit = (True, False)
elif tag is None:
implicit = (False, True)
@@ -357,7 +357,7 @@ class Parser(object):
elif anchor is not None or tag is not None:
# Empty scalars are allowed even if a tag or an anchor is
# specified.
event = ScalarEvent(anchor, tag, (implicit, False), u'',
event = ScalarEvent(anchor, tag, (implicit, False), '',
start_mark, end_mark)
self.state = self.states.pop()
else:
@@ -585,5 +585,5 @@ class Parser(object):
return self.process_empty_scalar(self.peek_token().start_mark)
def process_empty_scalar(self, mark):
return ScalarEvent(None, None, (True, False), u'', mark, mark)
return ScalarEvent(None, None, (True, False), '', mark, mark)
+9 -9
View File
@@ -61,7 +61,7 @@ class Reader(object):
self.stream = None
self.stream_pointer = 0
self.eof = True
self.buffer = u''
self.buffer = ''
self.pointer = 0
self.raw_buffer = None
self.raw_decode = None
@@ -69,10 +69,10 @@ class Reader(object):
self.index = 0
self.line = 0
self.column = 0
if isinstance(stream, unicode):
if isinstance(stream, str):
self.name = "<unicode string>"
self.check_printable(stream)
self.buffer = stream+u'\0'
self.buffer = stream+'\0'
elif isinstance(stream, str):
self.name = "<string>"
self.raw_buffer = stream
@@ -103,11 +103,11 @@ class Reader(object):
ch = self.buffer[self.pointer]
self.pointer += 1
self.index += 1
if ch in u'\n\x85\u2028\u2029' \
or (ch == u'\r' and self.buffer[self.pointer] != u'\n'):
if ch in '\n\x85\u2028\u2029' \
or (ch == '\r' and self.buffer[self.pointer] != '\n'):
self.line += 1
self.column = 0
elif ch != u'\uFEFF':
elif ch != '\uFEFF':
self.column += 1
length -= 1
@@ -122,7 +122,7 @@ class Reader(object):
def determine_encoding(self):
while not self.eof and len(self.raw_buffer) < 2:
self.update_raw()
if not isinstance(self.raw_buffer, unicode):
if not isinstance(self.raw_buffer, str):
if self.raw_buffer.startswith(codecs.BOM_UTF16_LE):
self.raw_decode = codecs.utf_16_le_decode
self.encoding = 'utf-16-le'
@@ -134,7 +134,7 @@ class Reader(object):
self.encoding = 'utf-8'
self.update(1)
NON_PRINTABLE = re.compile(u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
NON_PRINTABLE = re.compile('[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
def check_printable(self, data):
match = self.NON_PRINTABLE.search(data)
if match:
@@ -170,7 +170,7 @@ class Reader(object):
self.buffer += data
self.raw_buffer = self.raw_buffer[converted:]
if self.eof:
self.buffer += u'\0'
self.buffer += '\0'
self.raw_buffer = None
break
+58 -58
View File
@@ -66,7 +66,7 @@ class BaseRepresenter(object):
elif None in self.yaml_representers:
node = self.yaml_representers[None](self, data)
else:
node = ScalarNode(None, unicode(data))
node = ScalarNode(None, str(data))
#if alias_key is not None:
# self.represented_objects[alias_key] = node
return node
@@ -141,44 +141,44 @@ class SafeRepresenter(BaseRepresenter):
def ignore_aliases(self, data):
if data in [None, ()]:
return True
if isinstance(data, (str, unicode, bool, int, float)):
if isinstance(data, (str, str, bool, int, float)):
return True
def represent_none(self, data):
return self.represent_scalar(u'tag:yaml.org,2002:null',
u'null')
return self.represent_scalar('tag:yaml.org,2002:null',
'null')
def represent_str(self, data):
tag = None
style = None
try:
data = unicode(data, 'ascii')
tag = u'tag:yaml.org,2002:str'
data = str(data, 'ascii')
tag = 'tag:yaml.org,2002:str'
except UnicodeDecodeError:
try:
data = unicode(data, 'utf-8')
tag = u'tag:yaml.org,2002:str'
data = str(data, 'utf-8')
tag = 'tag:yaml.org,2002:str'
except UnicodeDecodeError:
data = data.encode('base64')
tag = u'tag:yaml.org,2002:binary'
tag = 'tag:yaml.org,2002:binary'
style = '|'
return self.represent_scalar(tag, data, style=style)
def represent_unicode(self, data):
return self.represent_scalar(u'tag:yaml.org,2002:str', data)
return self.represent_scalar('tag:yaml.org,2002:str', data)
def represent_bool(self, data):
if data:
value = u'true'
value = 'true'
else:
value = u'false'
return self.represent_scalar(u'tag:yaml.org,2002:bool', value)
value = 'false'
return self.represent_scalar('tag:yaml.org,2002:bool', value)
def represent_int(self, data):
return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(data))
return self.represent_scalar('tag:yaml.org,2002:int', str(data))
def represent_long(self, data):
return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(data))
return self.represent_scalar('tag:yaml.org,2002:int', str(data))
inf_value = 1e300
while repr(inf_value) != repr(inf_value*inf_value):
@@ -186,13 +186,13 @@ class SafeRepresenter(BaseRepresenter):
def represent_float(self, data):
if data != data or (data == 0.0 and data == 1.0):
value = u'.nan'
value = '.nan'
elif data == self.inf_value:
value = u'.inf'
value = '.inf'
elif data == -self.inf_value:
value = u'-.inf'
value = '-.inf'
else:
value = unicode(repr(data)).lower()
value = str(repr(data)).lower()
# Note that in some cases `repr(data)` represents a float number
# without the decimal parts. For instance:
# >>> repr(1e17)
@@ -200,9 +200,9 @@ class SafeRepresenter(BaseRepresenter):
# Unfortunately, this is not a valid float representation according
# to the definition of the `!!float` tag. We fix this by adding
# '.0' before the 'e' symbol.
if u'.' not in value and u'e' in value:
value = value.replace(u'e', u'.0e', 1)
return self.represent_scalar(u'tag:yaml.org,2002:float', value)
if '.' not in value and 'e' in value:
value = value.replace('e', '.0e', 1)
return self.represent_scalar('tag:yaml.org,2002:float', value)
def represent_list(self, data):
#pairs = (len(data) > 0 and isinstance(data, list))
@@ -212,7 +212,7 @@ class SafeRepresenter(BaseRepresenter):
# pairs = False
# break
#if not pairs:
return self.represent_sequence(u'tag:yaml.org,2002:seq', data)
return self.represent_sequence('tag:yaml.org,2002:seq', data)
#value = []
#for item_key, item_value in data:
# value.append(self.represent_mapping(u'tag:yaml.org,2002:map',
@@ -220,21 +220,21 @@ class SafeRepresenter(BaseRepresenter):
#return SequenceNode(u'tag:yaml.org,2002:pairs', value)
def represent_dict(self, data):
return self.represent_mapping(u'tag:yaml.org,2002:map', data)
return self.represent_mapping('tag:yaml.org,2002:map', data)
def represent_set(self, data):
value = {}
for key in data:
value[key] = None
return self.represent_mapping(u'tag:yaml.org,2002:set', value)
return self.represent_mapping('tag:yaml.org,2002:set', value)
def represent_date(self, data):
value = unicode(data.isoformat())
return self.represent_scalar(u'tag:yaml.org,2002:timestamp', value)
value = str(data.isoformat())
return self.represent_scalar('tag:yaml.org,2002:timestamp', value)
def represent_datetime(self, data):
value = unicode(data.isoformat(' '))
return self.represent_scalar(u'tag:yaml.org,2002:timestamp', value)
value = str(data.isoformat(' '))
return self.represent_scalar('tag:yaml.org,2002:timestamp', value)
def represent_yaml_object(self, tag, data, cls, flow_style=None):
if hasattr(data, '__getstate__'):
@@ -252,7 +252,7 @@ SafeRepresenter.add_representer(type(None),
SafeRepresenter.add_representer(str,
SafeRepresenter.represent_str)
SafeRepresenter.add_representer(unicode,
SafeRepresenter.add_representer(str,
SafeRepresenter.represent_unicode)
SafeRepresenter.add_representer(bool,
@@ -294,15 +294,15 @@ class Representer(SafeRepresenter):
tag = None
style = None
try:
data = unicode(data, 'ascii')
tag = u'tag:yaml.org,2002:str'
data = str(data, 'ascii')
tag = 'tag:yaml.org,2002:str'
except UnicodeDecodeError:
try:
data = unicode(data, 'utf-8')
tag = u'tag:yaml.org,2002:python/str'
data = str(data, 'utf-8')
tag = 'tag:yaml.org,2002:python/str'
except UnicodeDecodeError:
data = data.encode('base64')
tag = u'tag:yaml.org,2002:binary'
tag = 'tag:yaml.org,2002:binary'
style = '|'
return self.represent_scalar(tag, data, style=style)
@@ -310,38 +310,38 @@ class Representer(SafeRepresenter):
tag = None
try:
data.encode('ascii')
tag = u'tag:yaml.org,2002:python/unicode'
tag = 'tag:yaml.org,2002:python/unicode'
except UnicodeEncodeError:
tag = u'tag:yaml.org,2002:str'
tag = 'tag:yaml.org,2002:str'
return self.represent_scalar(tag, data)
def represent_long(self, data):
tag = u'tag:yaml.org,2002:int'
tag = 'tag:yaml.org,2002:int'
if int(data) is not data:
tag = u'tag:yaml.org,2002:python/long'
return self.represent_scalar(tag, unicode(data))
tag = 'tag:yaml.org,2002:python/long'
return self.represent_scalar(tag, str(data))
def represent_complex(self, data):
if data.imag == 0.0:
data = u'%r' % data.real
data = '%r' % data.real
elif data.real == 0.0:
data = u'%rj' % data.imag
data = '%rj' % data.imag
elif data.imag > 0:
data = u'%r+%rj' % (data.real, data.imag)
data = '%r+%rj' % (data.real, data.imag)
else:
data = u'%r%rj' % (data.real, data.imag)
return self.represent_scalar(u'tag:yaml.org,2002:python/complex', data)
data = '%r%rj' % (data.real, data.imag)
return self.represent_scalar('tag:yaml.org,2002:python/complex', data)
def represent_tuple(self, data):
return self.represent_sequence(u'tag:yaml.org,2002:python/tuple', data)
return self.represent_sequence('tag:yaml.org,2002:python/tuple', data)
def represent_name(self, data):
name = u'%s.%s' % (data.__module__, data.__name__)
return self.represent_scalar(u'tag:yaml.org,2002:python/name:'+name, u'')
name = '%s.%s' % (data.__module__, data.__name__)
return self.represent_scalar('tag:yaml.org,2002:python/name:'+name, '')
def represent_module(self, data):
return self.represent_scalar(
u'tag:yaml.org,2002:python/module:'+data.__name__, u'')
'tag:yaml.org,2002:python/module:'+data.__name__, '')
def represent_instance(self, data):
# For instances of classic classes, we use __getinitargs__ and
@@ -362,7 +362,7 @@ class Representer(SafeRepresenter):
# !!python/object/new node.
cls = data.__class__
class_name = u'%s.%s' % (cls.__module__, cls.__name__)
class_name = '%s.%s' % (cls.__module__, cls.__name__)
args = None
state = None
if hasattr(data, '__getinitargs__'):
@@ -373,16 +373,16 @@ class Representer(SafeRepresenter):
state = data.__dict__
if args is None and isinstance(state, dict):
return self.represent_mapping(
u'tag:yaml.org,2002:python/object:'+class_name, state)
'tag:yaml.org,2002:python/object:'+class_name, state)
if isinstance(state, dict) and not state:
return self.represent_sequence(
u'tag:yaml.org,2002:python/object/new:'+class_name, args)
'tag:yaml.org,2002:python/object/new:'+class_name, args)
value = {}
if args:
value['args'] = args
value['state'] = state
return self.represent_mapping(
u'tag:yaml.org,2002:python/object/new:'+class_name, value)
'tag:yaml.org,2002:python/object/new:'+class_name, value)
def represent_object(self, data):
# We use __reduce__ API to save the data. data.__reduce__ returns
@@ -422,16 +422,16 @@ class Representer(SafeRepresenter):
if function.__name__ == '__newobj__':
function = args[0]
args = args[1:]
tag = u'tag:yaml.org,2002:python/object/new:'
tag = 'tag:yaml.org,2002:python/object/new:'
newobj = True
else:
tag = u'tag:yaml.org,2002:python/object/apply:'
tag = 'tag:yaml.org,2002:python/object/apply:'
newobj = False
function_name = u'%s.%s' % (function.__module__, function.__name__)
function_name = '%s.%s' % (function.__module__, function.__name__)
if not args and not listitems and not dictitems \
and isinstance(state, dict) and newobj:
return self.represent_mapping(
u'tag:yaml.org,2002:python/object:'+function_name, state)
'tag:yaml.org,2002:python/object:'+function_name, state)
if not listitems and not dictitems \
and isinstance(state, dict) and not state:
return self.represent_sequence(tag+function_name, args)
@@ -449,7 +449,7 @@ class Representer(SafeRepresenter):
Representer.add_representer(str,
Representer.represent_str)
Representer.add_representer(unicode,
Representer.add_representer(str,
Representer.represent_unicode)
Representer.add_representer(int,
+29 -29
View File
@@ -11,9 +11,9 @@ class ResolverError(YAMLError):
class BaseResolver(object):
DEFAULT_SCALAR_TAG = u'tag:yaml.org,2002:str'
DEFAULT_SEQUENCE_TAG = u'tag:yaml.org,2002:seq'
DEFAULT_MAPPING_TAG = u'tag:yaml.org,2002:map'
DEFAULT_SCALAR_TAG = 'tag:yaml.org,2002:str'
DEFAULT_SEQUENCE_TAG = 'tag:yaml.org,2002:seq'
DEFAULT_MAPPING_TAG = 'tag:yaml.org,2002:map'
yaml_implicit_resolvers = {}
yaml_path_resolvers = {}
@@ -139,8 +139,8 @@ class BaseResolver(object):
def resolve(self, kind, value, implicit):
if kind is ScalarNode and implicit[0]:
if value == u'':
resolvers = self.yaml_implicit_resolvers.get(u'', [])
if value == '':
resolvers = self.yaml_implicit_resolvers.get('', [])
else:
resolvers = self.yaml_implicit_resolvers.get(value[0], [])
resolvers += self.yaml_implicit_resolvers.get(None, [])
@@ -165,60 +165,60 @@ class Resolver(BaseResolver):
pass
Resolver.add_implicit_resolver(
u'tag:yaml.org,2002:bool',
re.compile(ur'''^(?:yes|Yes|YES|no|No|NO
'tag:yaml.org,2002:bool',
re.compile(r'''^(?:yes|Yes|YES|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF)$''', re.X),
list(u'yYnNtTfFoO'))
list('yYnNtTfFoO'))
Resolver.add_implicit_resolver(
u'tag:yaml.org,2002:float',
re.compile(ur'''^(?:[-+]?(?:[0-9][0-9_]*)\.[0-9_]*(?:[eE][-+][0-9]+)?
'tag:yaml.org,2002:float',
re.compile(r'''^(?:[-+]?(?:[0-9][0-9_]*)\.[0-9_]*(?:[eE][-+][0-9]+)?
|\.[0-9_]+(?:[eE][-+][0-9]+)?
|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*
|[-+]?\.(?:inf|Inf|INF)
|\.(?:nan|NaN|NAN))$''', re.X),
list(u'-+0123456789.'))
list('-+0123456789.'))
Resolver.add_implicit_resolver(
u'tag:yaml.org,2002:int',
re.compile(ur'''^(?:[-+]?0b[0-1_]+
'tag:yaml.org,2002:int',
re.compile(r'''^(?:[-+]?0b[0-1_]+
|[-+]?0[0-7_]+
|[-+]?(?:0|[1-9][0-9_]*)
|[-+]?0x[0-9a-fA-F_]+
|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$''', re.X),
list(u'-+0123456789'))
list('-+0123456789'))
Resolver.add_implicit_resolver(
u'tag:yaml.org,2002:merge',
re.compile(ur'^(?:<<)$'),
[u'<'])
'tag:yaml.org,2002:merge',
re.compile(r'^(?:<<)$'),
['<'])
Resolver.add_implicit_resolver(
u'tag:yaml.org,2002:null',
re.compile(ur'''^(?: ~
'tag:yaml.org,2002:null',
re.compile(r'''^(?: ~
|null|Null|NULL
| )$''', re.X),
[u'~', u'n', u'N', u''])
['~', 'n', 'N', ''])
Resolver.add_implicit_resolver(
u'tag:yaml.org,2002:timestamp',
re.compile(ur'''^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]
'tag:yaml.org,2002:timestamp',
re.compile(r'''^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]
|[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?
(?:[Tt]|[ \t]+)[0-9][0-9]?
:[0-9][0-9] :[0-9][0-9] (?:\.[0-9]*)?
(?:[ \t]*(?:Z|[-+][0-9][0-9]?(?::[0-9][0-9])?))?)$''', re.X),
list(u'0123456789'))
list('0123456789'))
Resolver.add_implicit_resolver(
u'tag:yaml.org,2002:value',
re.compile(ur'^(?:=)$'),
[u'='])
'tag:yaml.org,2002:value',
re.compile(r'^(?:=)$'),
['='])
# The following resolver is only for documentation purposes. It cannot work
# because plain scalars cannot start with '!', '&', or '*'.
Resolver.add_implicit_resolver(
u'tag:yaml.org,2002:yaml',
re.compile(ur'^(?:!|&|\*)$'),
list(u'!&*'))
'tag:yaml.org,2002:yaml',
re.compile(r'^(?:!|&|\*)$'),
list('!&*'))
+160 -160
View File
@@ -166,19 +166,19 @@ class Scanner(object):
ch = self.peek()
# Is it the end of stream?
if ch == u'\0':
if ch == '\0':
return self.fetch_stream_end()
# Is it a directive?
if ch == u'%' and self.check_directive():
if ch == '%' and self.check_directive():
return self.fetch_directive()
# Is it the document start?
if ch == u'-' and self.check_document_start():
if ch == '-' and self.check_document_start():
return self.fetch_document_start()
# Is it the document end?
if ch == u'.' and self.check_document_end():
if ch == '.' and self.check_document_end():
return self.fetch_document_end()
# TODO: support for BOM within a stream.
@@ -188,63 +188,63 @@ class Scanner(object):
# Note: the order of the following checks is NOT significant.
# Is it the flow sequence start indicator?
if ch == u'[':
if ch == '[':
return self.fetch_flow_sequence_start()
# Is it the flow mapping start indicator?
if ch == u'{':
if ch == '{':
return self.fetch_flow_mapping_start()
# Is it the flow sequence end indicator?
if ch == u']':
if ch == ']':
return self.fetch_flow_sequence_end()
# Is it the flow mapping end indicator?
if ch == u'}':
if ch == '}':
return self.fetch_flow_mapping_end()
# Is it the flow entry indicator?
if ch == u',':
if ch == ',':
return self.fetch_flow_entry()
# Is it the block entry indicator?
if ch == u'-' and self.check_block_entry():
if ch == '-' and self.check_block_entry():
return self.fetch_block_entry()
# Is it the key indicator?
if ch == u'?' and self.check_key():
if ch == '?' and self.check_key():
return self.fetch_key()
# Is it the value indicator?
if ch == u':' and self.check_value():
if ch == ':' and self.check_value():
return self.fetch_value()
# Is it an alias?
if ch == u'*':
if ch == '*':
return self.fetch_alias()
# Is it an anchor?
if ch == u'&':
if ch == '&':
return self.fetch_anchor()
# Is it a tag?
if ch == u'!':
if ch == '!':
return self.fetch_tag()
# Is it a literal scalar?
if ch == u'|' and not self.flow_level:
if ch == '|' and not self.flow_level:
return self.fetch_literal()
# Is it a folded scalar?
if ch == u'>' and not self.flow_level:
if ch == '>' and not self.flow_level:
return self.fetch_folded()
# Is it a single quoted scalar?
if ch == u'\'':
if ch == '\'':
return self.fetch_single()
# Is it a double quoted scalar?
if ch == u'\"':
if ch == '\"':
return self.fetch_double()
# It must be a plain scalar then.
@@ -692,22 +692,22 @@ class Scanner(object):
# DOCUMENT-START: ^ '---' (' '|'\n')
if self.column == 0:
if self.prefix(3) == u'---' \
and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
if self.prefix(3) == '---' \
and self.peek(3) in '\0 \t\r\n\x85\u2028\u2029':
return True
def check_document_end(self):
# DOCUMENT-END: ^ '...' (' '|'\n')
if self.column == 0:
if self.prefix(3) == u'...' \
and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
if self.prefix(3) == '...' \
and self.peek(3) in '\0 \t\r\n\x85\u2028\u2029':
return True
def check_block_entry(self):
# BLOCK-ENTRY: '-' (' '|'\n')
return self.peek(1) in u'\0 \t\r\n\x85\u2028\u2029'
return self.peek(1) in '\0 \t\r\n\x85\u2028\u2029'
def check_key(self):
@@ -717,7 +717,7 @@ class Scanner(object):
# KEY(block context): '?' (' '|'\n')
else:
return self.peek(1) in u'\0 \t\r\n\x85\u2028\u2029'
return self.peek(1) in '\0 \t\r\n\x85\u2028\u2029'
def check_value(self):
@@ -727,7 +727,7 @@ class Scanner(object):
# VALUE(block context): ':' (' '|'\n')
else:
return self.peek(1) in u'\0 \t\r\n\x85\u2028\u2029'
return self.peek(1) in '\0 \t\r\n\x85\u2028\u2029'
def check_plain(self):
@@ -744,9 +744,9 @@ class Scanner(object):
# '-' character) because we want the flow context to be space
# independent.
ch = self.peek()
return ch not in u'\0 \t\r\n\x85\u2028\u2029-?:,[]{}#&*!|>\'\"%@`' \
or (self.peek(1) not in u'\0 \t\r\n\x85\u2028\u2029'
and (ch == u'-' or (not self.flow_level and ch in u'?:')))
return ch not in '\0 \t\r\n\x85\u2028\u2029-?:,[]{}#&*!|>\'\"%@`' \
or (self.peek(1) not in '\0 \t\r\n\x85\u2028\u2029'
and (ch == '-' or (not self.flow_level and ch in '?:')))
# Scanners.
@@ -770,14 +770,14 @@ class Scanner(object):
# `unwind_indent` before issuing BLOCK-END.
# Scanners for block, flow, and plain scalars need to be modified.
if self.index == 0 and self.peek() == u'\uFEFF':
if self.index == 0 and self.peek() == '\uFEFF':
self.forward()
found = False
while not found:
while self.peek() == u' ':
while self.peek() == ' ':
self.forward()
if self.peek() == u'#':
while self.peek() not in u'\0\r\n\x85\u2028\u2029':
if self.peek() == '#':
while self.peek() not in '\0\r\n\x85\u2028\u2029':
self.forward()
if self.scan_line_break():
if not self.flow_level:
@@ -791,15 +791,15 @@ class Scanner(object):
self.forward()
name = self.scan_directive_name(start_mark)
value = None
if name == u'YAML':
if name == 'YAML':
value = self.scan_yaml_directive_value(start_mark)
end_mark = self.get_mark()
elif name == u'TAG':
elif name == 'TAG':
value = self.scan_tag_directive_value(start_mark)
end_mark = self.get_mark()
else:
end_mark = self.get_mark()
while self.peek() not in u'\0\r\n\x85\u2028\u2029':
while self.peek() not in '\0\r\n\x85\u2028\u2029':
self.forward()
self.scan_directive_ignored_line(start_mark)
return DirectiveToken(name, value, start_mark, end_mark)
@@ -808,8 +808,8 @@ class Scanner(object):
# See the specification for details.
length = 0
ch = self.peek(length)
while u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' \
or ch in u'-_':
while '0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \
or ch in '-_':
length += 1
ch = self.peek(length)
if not length:
@@ -819,7 +819,7 @@ class Scanner(object):
value = self.prefix(length)
self.forward(length)
ch = self.peek()
if ch not in u'\0 \r\n\x85\u2028\u2029':
if ch not in '\0 \r\n\x85\u2028\u2029':
raise ScannerError("while scanning a directive", start_mark,
"expected alphabetic or numeric character, but found %r"
% ch.encode('utf-8'), self.get_mark())
@@ -827,7 +827,7 @@ class Scanner(object):
def scan_yaml_directive_value(self, start_mark):
# See the specification for details.
while self.peek() == u' ':
while self.peek() == ' ':
self.forward()
major = self.scan_yaml_directive_number(start_mark)
if self.peek() != '.':
@@ -837,7 +837,7 @@ class Scanner(object):
self.get_mark())
self.forward()
minor = self.scan_yaml_directive_number(start_mark)
if self.peek() not in u'\0 \r\n\x85\u2028\u2029':
if self.peek() not in '\0 \r\n\x85\u2028\u2029':
raise ScannerError("while scanning a directive", start_mark,
"expected a digit or ' ', but found %r"
% self.peek().encode('utf-8'),
@@ -847,12 +847,12 @@ class Scanner(object):
def scan_yaml_directive_number(self, start_mark):
# See the specification for details.
ch = self.peek()
if not (u'0' <= ch <= u'9'):
if not ('0' <= ch <= '9'):
raise ScannerError("while scanning a directive", start_mark,
"expected a digit, but found %r" % ch.encode('utf-8'),
self.get_mark())
length = 0
while u'0' <= self.peek(length) <= u'9':
while '0' <= self.peek(length) <= '9':
length += 1
value = int(self.prefix(length))
self.forward(length)
@@ -860,10 +860,10 @@ class Scanner(object):
def scan_tag_directive_value(self, start_mark):
# See the specification for details.
while self.peek() == u' ':
while self.peek() == ' ':
self.forward()
handle = self.scan_tag_directive_handle(start_mark)
while self.peek() == u' ':
while self.peek() == ' ':
self.forward()
prefix = self.scan_tag_directive_prefix(start_mark)
return (handle, prefix)
@@ -872,7 +872,7 @@ class Scanner(object):
# See the specification for details.
value = self.scan_tag_handle('directive', start_mark)
ch = self.peek()
if ch != u' ':
if ch != ' ':
raise ScannerError("while scanning a directive", start_mark,
"expected ' ', but found %r" % ch.encode('utf-8'),
self.get_mark())
@@ -882,7 +882,7 @@ class Scanner(object):
# See the specification for details.
value = self.scan_tag_uri('directive', start_mark)
ch = self.peek()
if ch not in u'\0 \r\n\x85\u2028\u2029':
if ch not in '\0 \r\n\x85\u2028\u2029':
raise ScannerError("while scanning a directive", start_mark,
"expected ' ', but found %r" % ch.encode('utf-8'),
self.get_mark())
@@ -890,13 +890,13 @@ class Scanner(object):
def scan_directive_ignored_line(self, start_mark):
# See the specification for details.
while self.peek() == u' ':
while self.peek() == ' ':
self.forward()
if self.peek() == u'#':
while self.peek() not in u'\0\r\n\x85\u2028\u2029':
if self.peek() == '#':
while self.peek() not in '\0\r\n\x85\u2028\u2029':
self.forward()
ch = self.peek()
if ch not in u'\0\r\n\x85\u2028\u2029':
if ch not in '\0\r\n\x85\u2028\u2029':
raise ScannerError("while scanning a directive", start_mark,
"expected a comment or a line break, but found %r"
% ch.encode('utf-8'), self.get_mark())
@@ -913,15 +913,15 @@ class Scanner(object):
# Therefore we restrict aliases to numbers and ASCII letters.
start_mark = self.get_mark()
indicator = self.peek()
if indicator == u'*':
if indicator == '*':
name = 'alias'
else:
name = 'anchor'
self.forward()
length = 0
ch = self.peek(length)
while u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' \
or ch in u'-_':
while '0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \
or ch in '-_':
length += 1
ch = self.peek(length)
if not length:
@@ -931,7 +931,7 @@ class Scanner(object):
value = self.prefix(length)
self.forward(length)
ch = self.peek()
if ch not in u'\0 \t\r\n\x85\u2028\u2029?:,]}%@`':
if ch not in '\0 \t\r\n\x85\u2028\u2029?:,]}%@`':
raise ScannerError("while scanning an %s" % name, start_mark,
"expected alphabetic or numeric character, but found %r"
% ch.encode('utf-8'), self.get_mark())
@@ -942,37 +942,37 @@ class Scanner(object):
# See the specification for details.
start_mark = self.get_mark()
ch = self.peek(1)
if ch == u'<':
if ch == '<':
handle = None
self.forward(2)
suffix = self.scan_tag_uri('tag', start_mark)
if self.peek() != u'>':
if self.peek() != '>':
raise ScannerError("while parsing a tag", start_mark,
"expected '>', but found %r" % self.peek().encode('utf-8'),
self.get_mark())
self.forward()
elif ch in u'\0 \t\r\n\x85\u2028\u2029':
elif ch in '\0 \t\r\n\x85\u2028\u2029':
handle = None
suffix = u'!'
suffix = '!'
self.forward()
else:
length = 1
use_handle = False
while ch not in u'\0 \r\n\x85\u2028\u2029':
if ch == u'!':
while ch not in '\0 \r\n\x85\u2028\u2029':
if ch == '!':
use_handle = True
break
length += 1
ch = self.peek(length)
handle = u'!'
handle = '!'
if use_handle:
handle = self.scan_tag_handle('tag', start_mark)
else:
handle = u'!'
handle = '!'
self.forward()
suffix = self.scan_tag_uri('tag', start_mark)
ch = self.peek()
if ch not in u'\0 \r\n\x85\u2028\u2029':
if ch not in '\0 \r\n\x85\u2028\u2029':
raise ScannerError("while scanning a tag", start_mark,
"expected ' ', but found %r" % ch.encode('utf-8'),
self.get_mark())
@@ -1006,29 +1006,29 @@ class Scanner(object):
else:
indent = min_indent+increment-1
breaks, end_mark = self.scan_block_scalar_breaks(indent)
line_break = u''
line_break = ''
# Scan the inner part of the block scalar.
while self.column == indent and self.peek() != u'\0':
while self.column == indent and self.peek() != '\0':
chunks.extend(breaks)
leading_non_space = self.peek() not in u' \t'
leading_non_space = self.peek() not in ' \t'
length = 0
while self.peek(length) not in u'\0\r\n\x85\u2028\u2029':
while self.peek(length) not in '\0\r\n\x85\u2028\u2029':
length += 1
chunks.append(self.prefix(length))
self.forward(length)
line_break = self.scan_line_break()
breaks, end_mark = self.scan_block_scalar_breaks(indent)
if self.column == indent and self.peek() != u'\0':
if self.column == indent and self.peek() != '\0':
# Unfortunately, folding rules are ambiguous.
#
# This is the folding according to the specification:
if folded and line_break == u'\n' \
and leading_non_space and self.peek() not in u' \t':
if folded and line_break == '\n' \
and leading_non_space and self.peek() not in ' \t':
if not breaks:
chunks.append(u' ')
chunks.append(' ')
else:
chunks.append(line_break)
@@ -1053,7 +1053,7 @@ class Scanner(object):
chunks.extend(breaks)
# We are done.
return ScalarToken(u''.join(chunks), False, start_mark, end_mark,
return ScalarToken(''.join(chunks), False, start_mark, end_mark,
style)
def scan_block_scalar_indicators(self, start_mark):
@@ -1061,21 +1061,21 @@ class Scanner(object):
chomping = None
increment = None
ch = self.peek()
if ch in u'+-':
if ch in '+-':
if ch == '+':
chomping = True
else:
chomping = False
self.forward()
ch = self.peek()
if ch in u'0123456789':
if ch in '0123456789':
increment = int(ch)
if increment == 0:
raise ScannerError("while scanning a block scalar", start_mark,
"expected indentation indicator in the range 1-9, but found 0",
self.get_mark())
self.forward()
elif ch in u'0123456789':
elif ch in '0123456789':
increment = int(ch)
if increment == 0:
raise ScannerError("while scanning a block scalar", start_mark,
@@ -1083,14 +1083,14 @@ class Scanner(object):
self.get_mark())
self.forward()
ch = self.peek()
if ch in u'+-':
if ch in '+-':
if ch == '+':
chomping = True
else:
chomping = False
self.forward()
ch = self.peek()
if ch not in u'\0 \r\n\x85\u2028\u2029':
if ch not in '\0 \r\n\x85\u2028\u2029':
raise ScannerError("while scanning a block scalar", start_mark,
"expected chomping or indentation indicators, but found %r"
% ch.encode('utf-8'), self.get_mark())
@@ -1098,13 +1098,13 @@ class Scanner(object):
def scan_block_scalar_ignored_line(self, start_mark):
# See the specification for details.
while self.peek() == u' ':
while self.peek() == ' ':
self.forward()
if self.peek() == u'#':
while self.peek() not in u'\0\r\n\x85\u2028\u2029':
if self.peek() == '#':
while self.peek() not in '\0\r\n\x85\u2028\u2029':
self.forward()
ch = self.peek()
if ch not in u'\0\r\n\x85\u2028\u2029':
if ch not in '\0\r\n\x85\u2028\u2029':
raise ScannerError("while scanning a block scalar", start_mark,
"expected a comment or a line break, but found %r"
% ch.encode('utf-8'), self.get_mark())
@@ -1115,8 +1115,8 @@ class Scanner(object):
chunks = []
max_indent = 0
end_mark = self.get_mark()
while self.peek() in u' \r\n\x85\u2028\u2029':
if self.peek() != u' ':
while self.peek() in ' \r\n\x85\u2028\u2029':
if self.peek() != ' ':
chunks.append(self.scan_line_break())
end_mark = self.get_mark()
else:
@@ -1129,12 +1129,12 @@ class Scanner(object):
# See the specification for details.
chunks = []
end_mark = self.get_mark()
while self.column < indent and self.peek() == u' ':
while self.column < indent and self.peek() == ' ':
self.forward()
while self.peek() in u'\r\n\x85\u2028\u2029':
while self.peek() in '\r\n\x85\u2028\u2029':
chunks.append(self.scan_line_break())
end_mark = self.get_mark()
while self.column < indent and self.peek() == u' ':
while self.column < indent and self.peek() == ' ':
self.forward()
return chunks, end_mark
@@ -1159,33 +1159,33 @@ class Scanner(object):
chunks.extend(self.scan_flow_scalar_non_spaces(double, start_mark))
self.forward()
end_mark = self.get_mark()
return ScalarToken(u''.join(chunks), False, start_mark, end_mark,
return ScalarToken(''.join(chunks), False, start_mark, end_mark,
style)
ESCAPE_REPLACEMENTS = {
u'0': u'\0',
u'a': u'\x07',
u'b': u'\x08',
u't': u'\x09',
u'\t': u'\x09',
u'n': u'\x0A',
u'v': u'\x0B',
u'f': u'\x0C',
u'r': u'\x0D',
u'e': u'\x1B',
u' ': u'\x20',
u'\"': u'\"',
u'\\': u'\\',
u'N': u'\x85',
u'_': u'\xA0',
u'L': u'\u2028',
u'P': u'\u2029',
'0': '\0',
'a': '\x07',
'b': '\x08',
't': '\x09',
'\t': '\x09',
'n': '\x0A',
'v': '\x0B',
'f': '\x0C',
'r': '\x0D',
'e': '\x1B',
' ': '\x20',
'\"': '\"',
'\\': '\\',
'N': '\x85',
'_': '\xA0',
'L': '\u2028',
'P': '\u2029',
}
ESCAPE_CODES = {
u'x': 2,
u'u': 4,
u'U': 8,
'x': 2,
'u': 4,
'U': 8,
}
def scan_flow_scalar_non_spaces(self, double, start_mark):
@@ -1193,19 +1193,19 @@ class Scanner(object):
chunks = []
while True:
length = 0
while self.peek(length) not in u'\'\"\\\0 \t\r\n\x85\u2028\u2029':
while self.peek(length) not in '\'\"\\\0 \t\r\n\x85\u2028\u2029':
length += 1
if length:
chunks.append(self.prefix(length))
self.forward(length)
ch = self.peek()
if not double and ch == u'\'' and self.peek(1) == u'\'':
chunks.append(u'\'')
if not double and ch == '\'' and self.peek(1) == '\'':
chunks.append('\'')
self.forward(2)
elif (double and ch == u'\'') or (not double and ch in u'\"\\'):
elif (double and ch == '\'') or (not double and ch in '\"\\'):
chunks.append(ch)
self.forward()
elif double and ch == u'\\':
elif double and ch == '\\':
self.forward()
ch = self.peek()
if ch in self.ESCAPE_REPLACEMENTS:
@@ -1215,14 +1215,14 @@ class Scanner(object):
length = self.ESCAPE_CODES[ch]
self.forward()
for k in range(length):
if self.peek(k) not in u'0123456789ABCDEFabcdef':
if self.peek(k) not in '0123456789ABCDEFabcdef':
raise ScannerError("while scanning a double-quoted scalar", start_mark,
"expected escape sequence of %d hexdecimal numbers, but found %r" %
(length, self.peek(k).encode('utf-8')), self.get_mark())
code = int(self.prefix(length), 16)
chunks.append(unichr(code))
chunks.append(chr(code))
self.forward(length)
elif ch in u'\r\n\x85\u2028\u2029':
elif ch in '\r\n\x85\u2028\u2029':
self.scan_line_break()
chunks.extend(self.scan_flow_scalar_breaks(double, start_mark))
else:
@@ -1235,21 +1235,21 @@ class Scanner(object):
# See the specification for details.
chunks = []
length = 0
while self.peek(length) in u' \t':
while self.peek(length) in ' \t':
length += 1
whitespaces = self.prefix(length)
self.forward(length)
ch = self.peek()
if ch == u'\0':
if ch == '\0':
raise ScannerError("while scanning a quoted scalar", start_mark,
"found unexpected end of stream", self.get_mark())
elif ch in u'\r\n\x85\u2028\u2029':
elif ch in '\r\n\x85\u2028\u2029':
line_break = self.scan_line_break()
breaks = self.scan_flow_scalar_breaks(double, start_mark)
if line_break != u'\n':
if line_break != '\n':
chunks.append(line_break)
elif not breaks:
chunks.append(u' ')
chunks.append(' ')
chunks.extend(breaks)
else:
chunks.append(whitespaces)
@@ -1262,13 +1262,13 @@ class Scanner(object):
# Instead of checking indentation, we check for document
# separators.
prefix = self.prefix(3)
if (prefix == u'---' or prefix == u'...') \
and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
if (prefix == '---' or prefix == '...') \
and self.peek(3) in '\0 \t\r\n\x85\u2028\u2029':
raise ScannerError("while scanning a quoted scalar", start_mark,
"found unexpected document separator", self.get_mark())
while self.peek() in u' \t':
while self.peek() in ' \t':
self.forward()
if self.peek() in u'\r\n\x85\u2028\u2029':
if self.peek() in '\r\n\x85\u2028\u2029':
chunks.append(self.scan_line_break())
else:
return chunks
@@ -1290,19 +1290,19 @@ class Scanner(object):
spaces = []
while True:
length = 0
if self.peek() == u'#':
if self.peek() == '#':
break
while True:
ch = self.peek(length)
if ch in u'\0 \t\r\n\x85\u2028\u2029' \
or (not self.flow_level and ch == u':' and
self.peek(length+1) in u'\0 \t\r\n\x85\u2028\u2029') \
or (self.flow_level and ch in u',:?[]{}'):
if ch in '\0 \t\r\n\x85\u2028\u2029' \
or (not self.flow_level and ch == ':' and
self.peek(length+1) in '\0 \t\r\n\x85\u2028\u2029') \
or (self.flow_level and ch in ',:?[]{}'):
break
length += 1
# It's not clear what we should do with ':' in the flow context.
if (self.flow_level and ch == u':'
and self.peek(length+1) not in u'\0 \t\r\n\x85\u2028\u2029,[]{}'):
if (self.flow_level and ch == ':'
and self.peek(length+1) not in '\0 \t\r\n\x85\u2028\u2029,[]{}'):
self.forward(length)
raise ScannerError("while scanning a plain scalar", start_mark,
"found unexpected ':'", self.get_mark(),
@@ -1315,10 +1315,10 @@ class Scanner(object):
self.forward(length)
end_mark = self.get_mark()
spaces = self.scan_plain_spaces(indent, start_mark)
if not spaces or self.peek() == u'#' \
if not spaces or self.peek() == '#' \
or (not self.flow_level and self.column < indent):
break
return ScalarToken(u''.join(chunks), True, start_mark, end_mark)
return ScalarToken(''.join(chunks), True, start_mark, end_mark)
def scan_plain_spaces(self, indent, start_mark):
# See the specification for details.
@@ -1326,32 +1326,32 @@ class Scanner(object):
# We just forbid them completely. Do not use tabs in YAML!
chunks = []
length = 0
while self.peek(length) in u' ':
while self.peek(length) in ' ':
length += 1
whitespaces = self.prefix(length)
self.forward(length)
ch = self.peek()
if ch in u'\r\n\x85\u2028\u2029':
if ch in '\r\n\x85\u2028\u2029':
line_break = self.scan_line_break()
self.allow_simple_key = True
prefix = self.prefix(3)
if (prefix == u'---' or prefix == u'...') \
and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
if (prefix == '---' or prefix == '...') \
and self.peek(3) in '\0 \t\r\n\x85\u2028\u2029':
return
breaks = []
while self.peek() in u' \r\n\x85\u2028\u2029':
while self.peek() in ' \r\n\x85\u2028\u2029':
if self.peek() == ' ':
self.forward()
else:
breaks.append(self.scan_line_break())
prefix = self.prefix(3)
if (prefix == u'---' or prefix == u'...') \
and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
if (prefix == '---' or prefix == '...') \
and self.peek(3) in '\0 \t\r\n\x85\u2028\u2029':
return
if line_break != u'\n':
if line_break != '\n':
chunks.append(line_break)
elif not breaks:
chunks.append(u' ')
chunks.append(' ')
chunks.extend(breaks)
elif whitespaces:
chunks.append(whitespaces)
@@ -1362,18 +1362,18 @@ class Scanner(object):
# For some strange reasons, the specification does not allow '_' in
# tag handles. I have allowed it anyway.
ch = self.peek()
if ch != u'!':
if ch != '!':
raise ScannerError("while scanning a %s" % name, start_mark,
"expected '!', but found %r" % ch.encode('utf-8'),
self.get_mark())
length = 1
ch = self.peek(length)
if ch != u' ':
while u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' \
or ch in u'-_':
if ch != ' ':
while '0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \
or ch in '-_':
length += 1
ch = self.peek(length)
if ch != u'!':
if ch != '!':
self.forward(length)
raise ScannerError("while scanning a %s" % name, start_mark,
"expected '!', but found %r" % ch.encode('utf-8'),
@@ -1389,9 +1389,9 @@ class Scanner(object):
chunks = []
length = 0
ch = self.peek(length)
while u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' \
or ch in u'-;/?:@&=+$,_.!~*\'()[]%':
if ch == u'%':
while '0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \
or ch in '-;/?:@&=+$,_.!~*\'()[]%':
if ch == '%':
chunks.append(self.prefix(length))
self.forward(length)
length = 0
@@ -1407,23 +1407,23 @@ class Scanner(object):
raise ScannerError("while parsing a %s" % name, start_mark,
"expected URI, but found %r" % ch.encode('utf-8'),
self.get_mark())
return u''.join(chunks)
return ''.join(chunks)
def scan_uri_escapes(self, name, start_mark):
# See the specification for details.
bytes = []
mark = self.get_mark()
while self.peek() == u'%':
while self.peek() == '%':
self.forward()
for k in range(2):
if self.peek(k) not in u'0123456789ABCDEFabcdef':
if self.peek(k) not in '0123456789ABCDEFabcdef':
raise ScannerError("while scanning a %s" % name, start_mark,
"expected URI escape sequence of 2 hexdecimal numbers, but found %r" %
(self.peek(k).encode('utf-8')), self.get_mark())
bytes.append(chr(int(self.prefix(2), 16)))
self.forward(2)
try:
value = unicode(''.join(bytes), 'utf-8')
value = str(''.join(bytes), 'utf-8')
except UnicodeDecodeError as exc:
raise ScannerError("while scanning a %s" % name, start_mark, str(exc), mark)
return value
@@ -1438,16 +1438,16 @@ class Scanner(object):
# '\u2029 : '\u2029'
# default : ''
ch = self.peek()
if ch in u'\r\n\x85':
if self.prefix(2) == u'\r\n':
if ch in '\r\n\x85':
if self.prefix(2) == '\r\n':
self.forward(2)
else:
self.forward()
return u'\n'
elif ch in u'\u2028\u2029':
return '\n'
elif ch in '\u2028\u2029':
self.forward()
return ch
return u''
return ''
#try:
# import psyco
+1 -1
View File
@@ -10,7 +10,7 @@ class SerializerError(YAMLError):
class Serializer(object):
ANCHOR_TEMPLATE = u'id%03d'
ANCHOR_TEMPLATE = 'id%03d'
def __init__(self, encoding=None,
explicit_start=None, explicit_end=None, version=None, tags=None):
+29 -29
View File
@@ -656,7 +656,7 @@ class Emitter:
# Last character or followed by a whitespace.
followed_by_whitespace = (len(scalar) == 1 or
scalar[1] in '\0 \t\r\n\x85\u2028\u2029')
scalar[1] in '\0 \t\r\n\x85\\u2028\\u2029')
# The previous character is a space.
previous_space = False
@@ -694,11 +694,11 @@ class Emitter:
block_indicators = True
# Check for line breaks, special, and unicode characters.
if ch in '\n\x85\u2028\u2029':
if ch in '\n\x85\\u2028\\u2029':
line_breaks = True
if not (ch == '\n' or '\x20' <= ch <= '\x7E'):
if (ch == '\x85' or '\xA0' <= ch <= '\uD7FF'
or '\uE000' <= ch <= '\uFFFD') and ch != '\uFEFF':
if (ch == '\x85' or '\xA0' <= ch <= '\\uD7FF'
or '\\uE000' <= ch <= '\\uFFFD') and ch != '\\uFEFF':
unicode_characters = True
if not self.allow_unicode:
special_characters = True
@@ -715,7 +715,7 @@ class Emitter:
break_space = True
previous_space = True
previous_break = False
elif ch in '\n\x85\u2028\u2029':
elif ch in '\n\x85\\u2028\\u2029':
if index == 0:
leading_break = True
if index == len(scalar)-1:
@@ -730,9 +730,9 @@ class Emitter:
# Prepare for the next character.
index += 1
preceeded_by_whitespace = (ch in '\0 \t\r\n\x85\u2028\u2029')
preceeded_by_whitespace = (ch in '\0 \t\r\n\x85\\u2028\\u2029')
followed_by_whitespace = (index+1 >= len(scalar) or
scalar[index+1] in '\0 \t\r\n\x85\u2028\u2029')
scalar[index+1] in '\0 \t\r\n\x85\\u2028\\u2029')
# Let's decide what styles are allowed.
allow_flow_plain = True
@@ -791,7 +791,7 @@ class Emitter:
def write_stream_start(self):
# Write BOM if needed.
if self.encoding and self.encoding.startswith('utf-16'):
self.stream.write('\uFEFF'.encode(self.encoding))
self.stream.write('\\uFEFF'.encode(self.encoding))
def write_stream_end(self):
self.flush_stream()
@@ -872,7 +872,7 @@ class Emitter:
self.stream.write(data)
start = end
elif breaks:
if ch is None or ch not in '\n\x85\u2028\u2029':
if ch is None or ch not in '\n\x85\\u2028\\u2029':
if text[start] == '\n':
self.write_line_break()
for br in text[start:end]:
@@ -883,7 +883,7 @@ class Emitter:
self.write_indent()
start = end
else:
if ch is None or ch in ' \n\x85\u2028\u2029' or ch == '\'':
if ch is None or ch in ' \n\x85\\u2028\\u2029' or ch == '\'':
if start < end:
data = text[start:end]
self.column += len(data)
@@ -900,7 +900,7 @@ class Emitter:
start = end + 1
if ch is not None:
spaces = (ch == ' ')
breaks = (ch in '\n\x85\u2028\u2029')
breaks = (ch in '\n\x85\\u2028\\u2029')
end += 1
self.write_indicator('\'', False)
@@ -918,8 +918,8 @@ class Emitter:
'\\': '\\',
'\x85': 'N',
'\xA0': '_',
'\u2028': 'L',
'\u2029': 'P',
'\\u2028': 'L',
'\\u2029': 'P',
}
def write_double_quoted(self, text, split=True):
@@ -929,11 +929,11 @@ class Emitter:
ch = None
if end < len(text):
ch = text[end]
if ch is None or ch in '"\\\x85\u2028\u2029\uFEFF' \
if ch is None or ch in '"\\\x85\\u2028\\u2029\\uFEFF' \
or not ('\x20' <= ch <= '\x7E'
or (self.allow_unicode
and ('\xA0' <= ch <= '\uD7FF'
or '\uE000' <= ch <= '\uFFFD'))):
and ('\xA0' <= ch <= '\\uD7FF'
or '\\uE000' <= ch <= '\\uFFFD'))):
if start < end:
data = text[start:end]
self.column += len(data)
@@ -946,7 +946,7 @@ class Emitter:
data = '\\'+self.ESCAPE_REPLACEMENTS[ch]
elif ch <= '\xFF':
data = '\\x%02X' % ord(ch)
elif ch <= '\uFFFF':
elif ch <= '\\uFFFF':
data = '\\u%04X' % ord(ch)
else:
data = '\\U%08X' % ord(ch)
@@ -979,11 +979,11 @@ class Emitter:
def determine_block_hints(self, text):
hints = ''
if text:
if text[0] in ' \n\x85\u2028\u2029':
if text[0] in ' \n\x85\\u2028\\u2029':
hints += str(self.best_indent)
if text[-1] not in '\n\x85\u2028\u2029':
if text[-1] not in '\n\x85\\u2028\\u2029':
hints += '-'
elif len(text) == 1 or text[-2] in '\n\x85\u2028\u2029':
elif len(text) == 1 or text[-2] in '\n\x85\\u2028\\u2029':
hints += '+'
return hints
@@ -1002,7 +1002,7 @@ class Emitter:
if end < len(text):
ch = text[end]
if breaks:
if ch is None or ch not in '\n\x85\u2028\u2029':
if ch is None or ch not in '\n\x85\\u2028\\u2029':
if not leading_space and ch is not None and ch != ' ' \
and text[start] == '\n':
self.write_line_break()
@@ -1027,7 +1027,7 @@ class Emitter:
self.stream.write(data)
start = end
else:
if ch is None or ch in ' \n\x85\u2028\u2029':
if ch is None or ch in ' \n\x85\\u2028\\u2029':
data = text[start:end]
self.column += len(data)
if self.encoding:
@@ -1037,7 +1037,7 @@ class Emitter:
self.write_line_break()
start = end
if ch is not None:
breaks = (ch in '\n\x85\u2028\u2029')
breaks = (ch in '\n\x85\\u2028\\u2029')
spaces = (ch == ' ')
end += 1
@@ -1054,7 +1054,7 @@ class Emitter:
if end < len(text):
ch = text[end]
if breaks:
if ch is None or ch not in '\n\x85\u2028\u2029':
if ch is None or ch not in '\n\x85\\u2028\\u2029':
for br in text[start:end]:
if br == '\n':
self.write_line_break()
@@ -1064,7 +1064,7 @@ class Emitter:
self.write_indent()
start = end
else:
if ch is None or ch in '\n\x85\u2028\u2029':
if ch is None or ch in '\n\x85\\u2028\\u2029':
data = text[start:end]
if self.encoding:
data = data.encode(self.encoding)
@@ -1073,7 +1073,7 @@ class Emitter:
self.write_line_break()
start = end
if ch is not None:
breaks = (ch in '\n\x85\u2028\u2029')
breaks = (ch in '\n\x85\\u2028\\u2029')
end += 1
def write_plain(self, text, split=True):
@@ -1110,7 +1110,7 @@ class Emitter:
self.stream.write(data)
start = end
elif breaks:
if ch not in '\n\x85\u2028\u2029':
if ch not in '\n\x85\\u2028\\u2029':
if text[start] == '\n':
self.write_line_break()
for br in text[start:end]:
@@ -1123,7 +1123,7 @@ class Emitter:
self.indention = False
start = end
else:
if ch is None or ch in ' \n\x85\u2028\u2029':
if ch is None or ch in ' \n\x85\\u2028\\u2029':
data = text[start:end]
self.column += len(data)
if self.encoding:
@@ -1132,6 +1132,6 @@ class Emitter:
start = end
if ch is not None:
spaces = (ch == ' ')
breaks = (ch in '\n\x85\u2028\u2029')
breaks = (ch in '\n\x85\\u2028\\u2029')
end += 1
Loaded 100 of 150 files, more files were not shown because too many files have changed in this diff. Show more