operator_re = re.compile('(%s)' % '|'.join([
isinstance(x, unicode) and str(x) or re.escape(x) for x in [
# math operators
- '+', '-', '*', '/', '%',
+ '+', '-', '*', '//', '/', '%',
# braces and parenthesis
'[', ']', '(', ')', '{', '}',
# attribute access and comparison / logical operators
ast.Add: self.handle_add,
ast.Sub: self.handle_sub,
ast.Div: self.handle_div,
+ ast.FloorDiv: self.handle_floor_div,
ast.Mul: self.handle_mul,
ast.Mod: self.handle_mod,
ast.UnaryAdd: self.handle_unary_add,
self.handle_node(node.right)
)
+ def handle_floor_div(self, node):
+ """
+ Divide two items, return truncated result.
+ """
+ return '(%s // %s)' % (
+ self.handle_node(node.left),
+ self.handle_node(node.right)
+ )
+
def handle_mul(self, node):
"""
Multiply two items.