Bytes literal.
diff --git a/Lib/compiler/ast.py b/Lib/compiler/ast.py
index bc283c0..4794d66 100644
--- a/Lib/compiler/ast.py
+++ b/Lib/compiler/ast.py
@@ -267,6 +267,20 @@
def __repr__(self):
return "Break()"
+class Bytes(Node):
+ def __init__(self, value, lineno=None):
+ self.value = value
+ self.lineno = lineno
+
+ def getChildren(self):
+ return self.value,
+
+ def getChildNodes(self):
+ return ()
+
+ def __repr__(self):
+ return "Bytes(%s)" % (repr(self.value),)
+
class CallFunc(Node):
def __init__(self, node, args, star_args = None, dstar_args = None, lineno=None):
self.node = node
diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py
index cac899d..f665c54 100644
--- a/Lib/compiler/pyassem.py
+++ b/Lib/compiler/pyassem.py
@@ -792,6 +792,7 @@
'DELETE_ATTR': -1,
'STORE_GLOBAL': -1,
'BUILD_MAP': 1,
+ 'MAKE_BYTES': 0,
'COMPARE_OP': -1,
'STORE_FAST': -1,
'IMPORT_STAR': -1,
diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py
index 8db4e0d..83fbc17 100644
--- a/Lib/compiler/pycodegen.py
+++ b/Lib/compiler/pycodegen.py
@@ -930,6 +930,10 @@
def visitConst(self, node):
self.emit('LOAD_CONST', node.value)
+
+ def visitBytes(self, node):
+ self.emit('LOAD_CONST', node.value)
+ self.emit('MAKE_BYTES')
def visitKeyword(self, node):
self.emit('LOAD_CONST', node.name)
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index 5f2face..79b702c 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -745,9 +745,11 @@
return eval(lit)
def atom_string(self, nodelist):
- k = ''
- for node in nodelist:
+ k = self.decode_literal(nodelist[0][1])
+ for node in nodelist[1:]:
k += self.decode_literal(node[1])
+ if isinstance(k, bytes):
+ return Bytes(str(k), lineno=nodelist[0][2])
return Const(k, lineno=nodelist[0][2])
def atom_ellipsis(self, nodelist):