Kaydet (Commit) f7a94e4b authored tarafından Guido van Rossum's avatar Guido van Rossum

SF patch# 1761465 by Jeffrey Yasskin.

Fix test_aepack and test_applesingle.
üst 67feb09d
# Generated from 'AEDataModel.h' # Generated from 'AEDataModel.h'
def FOUR_CHAR_CODE(x): return x def FOUR_CHAR_CODE(x): return bytes(x)
typeBoolean = FOUR_CHAR_CODE('bool') typeBoolean = FOUR_CHAR_CODE('bool')
typeChar = FOUR_CHAR_CODE('TEXT') typeChar = FOUR_CHAR_CODE('TEXT')
typeSInt16 = FOUR_CHAR_CODE('shor') typeSInt16 = FOUR_CHAR_CODE('shor')
......
This diff is collapsed.
...@@ -16,6 +16,14 @@ def nice(s): ...@@ -16,6 +16,14 @@ def nice(s):
if isinstance(s, str): return repr(s) if isinstance(s, str): return repr(s)
else: return str(s) else: return str(s)
def _four_char_code(four_chars):
"""Convert a str or bytes object into a 4-byte array.
four_chars must contain only ASCII characters.
"""
return bytes("%-4.4s" % str(four_chars))
class Unknown: class Unknown:
"""An uninterpreted AE object""" """An uninterpreted AE object"""
...@@ -33,13 +41,13 @@ class Enum: ...@@ -33,13 +41,13 @@ class Enum:
"""An AE enumeration value""" """An AE enumeration value"""
def __init__(self, enum): def __init__(self, enum):
self.enum = "%-4.4s" % str(enum) self.enum = _four_char_code(enum)
def __repr__(self): def __repr__(self):
return "Enum(%r)" % (self.enum,) return "Enum(%r)" % (self.enum,)
def __str__(self): def __str__(self):
return self.enum.strip() return self.enum.strip(b' ')
def __aepack__(self): def __aepack__(self):
return pack(self.enum, typeEnumeration) return pack(self.enum, typeEnumeration)
...@@ -100,7 +108,7 @@ class Type: ...@@ -100,7 +108,7 @@ class Type:
"""An AE 4-char typename object""" """An AE 4-char typename object"""
def __init__(self, type): def __init__(self, type):
self.type = "%-4.4s" % str(type) self.type = _four_char_code(type)
def __repr__(self): def __repr__(self):
return "Type(%r)" % (self.type,) return "Type(%r)" % (self.type,)
...@@ -123,7 +131,7 @@ class Keyword: ...@@ -123,7 +131,7 @@ class Keyword:
"""An AE 4-char keyword object""" """An AE 4-char keyword object"""
def __init__(self, keyword): def __init__(self, keyword):
self.keyword = "%-4.4s" % str(keyword) self.keyword = _four_char_code(keyword)
def __repr__(self): def __repr__(self):
return "Keyword(%r)" % self.keyword return "Keyword(%r)" % self.keyword
...@@ -161,7 +169,7 @@ class Comparison: ...@@ -161,7 +169,7 @@ class Comparison:
def __init__(self, obj1, relo, obj2): def __init__(self, obj1, relo, obj2):
self.obj1 = obj1 self.obj1 = obj1
self.relo = "%-4.4s" % str(relo) self.relo = _four_char_code(relo)
self.obj2 = obj2 self.obj2 = obj2
def __repr__(self): def __repr__(self):
...@@ -190,7 +198,7 @@ class Ordinal: ...@@ -190,7 +198,7 @@ class Ordinal:
def __init__(self, abso): def __init__(self, abso):
# self.obj1 = obj1 # self.obj1 = obj1
self.abso = "%-4.4s" % str(abso) self.abso = _four_char_code(abso)
def __repr__(self): def __repr__(self):
return "Ordinal(%r)" % (self.abso,) return "Ordinal(%r)" % (self.abso,)
...@@ -214,7 +222,7 @@ class Logical: ...@@ -214,7 +222,7 @@ class Logical:
"""An AE logical expression object""" """An AE logical expression object"""
def __init__(self, logc, term): def __init__(self, logc, term):
self.logc = "%-4.4s" % str(logc) self.logc = _four_char_code(logc)
self.term = term self.term = term
def __repr__(self): def __repr__(self):
...@@ -554,12 +562,12 @@ template = """ ...@@ -554,12 +562,12 @@ template = """
class %s(ComponentItem): want = '%s' class %s(ComponentItem): want = '%s'
""" """
exec(template % ("Text", 'text')) exec(template % ("Text", b'text'))
exec(template % ("Character", 'cha ')) exec(template % ("Character", b'cha '))
exec(template % ("Word", 'cwor')) exec(template % ("Word", b'cwor'))
exec(template % ("Line", 'clin')) exec(template % ("Line", b'clin'))
exec(template % ("paragraph", 'cpar')) exec(template % ("paragraph", b'cpar'))
exec(template % ("Window", 'cwin')) exec(template % ("Window", b'cwin'))
exec(template % ("Document", 'docu')) exec(template % ("Document", b'docu'))
exec(template % ("File", 'file')) exec(template % ("File", b'file'))
exec(template % ("InsertionPoint", 'cins')) exec(template % ("InsertionPoint", b'cins'))
...@@ -8,18 +8,18 @@ from test import test_support ...@@ -8,18 +8,18 @@ from test import test_support
class TestAepack(unittest.TestCase): class TestAepack(unittest.TestCase):
OBJECTS = [ OBJECTS = [
aetypes.Enum('enum'), aetypes.Enum(b'enum'),
aetypes.Type('type'), aetypes.Type(b'type'),
aetypes.Keyword('kwrd'), aetypes.Keyword(b'kwrd'),
aetypes.Range(1, 10), aetypes.Range(1, 10),
aetypes.Comparison(1, '< ', 10), aetypes.Comparison(1, b'< ', 10),
aetypes.Logical('not ', 1), aetypes.Logical(b'not ', 1),
aetypes.IntlText(0, 0, 'international text'), aetypes.IntlText(0, 0, b'international text'),
aetypes.IntlWritingCode(0,0), aetypes.IntlWritingCode(0,0),
aetypes.QDPoint(50,100), aetypes.QDPoint(50,100),
aetypes.QDRectangle(50,100,150,200), aetypes.QDRectangle(50,100,150,200),
aetypes.RGBColor(0x7000, 0x6000, 0x5000), aetypes.RGBColor(0x7000, 0x6000, 0x5000),
aetypes.Unknown('xxxx', 'unknown type data'), aetypes.Unknown(b'xxxx', b'unknown type data'),
aetypes.Character(1), aetypes.Character(1),
aetypes.Character(2, aetypes.Line(2)), aetypes.Character(2, aetypes.Line(2)),
] ]
......
...@@ -12,8 +12,8 @@ import applesingle ...@@ -12,8 +12,8 @@ import applesingle
AS_MAGIC=0x00051600 AS_MAGIC=0x00051600
AS_VERSION=0x00020000 AS_VERSION=0x00020000
dataforkdata = 'hello\r\0world\n' dataforkdata = b'hello\r\0world\n'
resourceforkdata = 'goodbye\ncruel\0world\r' resourceforkdata = b'goodbye\ncruel\0world\r'
applesingledata = struct.pack(">ll16sh", AS_MAGIC, AS_VERSION, "foo", 2) + \ applesingledata = struct.pack(">ll16sh", AS_MAGIC, AS_VERSION, "foo", 2) + \
struct.pack(">llllll", 1, 50, len(dataforkdata), struct.pack(">llllll", 1, 50, len(dataforkdata),
...@@ -25,7 +25,7 @@ TESTFN2 = test_support.TESTFN + '2' ...@@ -25,7 +25,7 @@ TESTFN2 = test_support.TESTFN + '2'
class TestApplesingle(unittest.TestCase): class TestApplesingle(unittest.TestCase):
def setUp(self): def setUp(self):
fp = open(test_support.TESTFN, 'w') fp = open(test_support.TESTFN, 'wb')
fp.write(applesingledata) fp.write(applesingledata)
fp.close() fp.close()
......
...@@ -835,9 +835,9 @@ static PyObject *AEDesc_get_data(AEDescObject *self, void *closure) ...@@ -835,9 +835,9 @@ static PyObject *AEDesc_get_data(AEDescObject *self, void *closure)
OSErr err; OSErr err;
size = AEGetDescDataSize(&self->ob_itself); size = AEGetDescDataSize(&self->ob_itself);
if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL ) if ( (res = PyBytes_FromStringAndSize(NULL, size)) == NULL )
return NULL; return NULL;
if ( (ptr = PyString_AsString(res)) == NULL ) if ( (ptr = PyBytes_AsString(res)) == NULL )
return NULL; return NULL;
if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 ) if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
return PyMac_Error(err); return PyMac_Error(err);
......
...@@ -194,7 +194,7 @@ PyObject * ...@@ -194,7 +194,7 @@ PyObject *
PyMac_BuildOSType(OSType t) PyMac_BuildOSType(OSType t)
{ {
uint32_t tmp = htonl((uint32_t)t); uint32_t tmp = htonl((uint32_t)t);
return PyString_FromStringAndSize((char *)&tmp, 4); return PyBytes_FromStringAndSize((char *)&tmp, 4);
} }
/* Convert an NumVersion value to a 4-element tuple */ /* Convert an NumVersion value to a 4-element tuple */
...@@ -215,7 +215,7 @@ PyMac_GetStr255(PyObject *v, Str255 pbuf) ...@@ -215,7 +215,7 @@ PyMac_GetStr255(PyObject *v, Str255 pbuf)
if (PyUnicode_Check(v)) { if (PyUnicode_Check(v)) {
v = _PyUnicode_AsDefaultEncodedString(v, NULL); v = _PyUnicode_AsDefaultEncodedString(v, NULL);
if (v == NULL) if (v == NULL)
return NULL; return 0;
} }
if (PyString_Check(v)) { if (PyString_Check(v)) {
ptr = PyString_AS_STRING(v); ptr = PyString_AS_STRING(v);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment