Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix python invalid syntax on triple quotation """

I encountered an error on codegen.py when trying to build rabbitmq server using make. I'm using 64 bit Windows 7, Python33, erl5.10.3, cygwin and GNU Make 4.0 for i686-pc-cygwin. I read that triple quotes are accepted in python. How do I fix this?

D:\cygwin\bin\make
Makefile:378: deps.mk: No such file or directory
python codegen.py body ../rabbitmq-codegen//amqp-rabbitmq-0.9.1.json ../rabbitmq
-codegen//credit_extension.json src/rabbit_framing_amqp_0_9_1.erl
  File "codegen.py", line 110
    %%"""
        ^
SyntaxError: invalid syntax
Makefile:144: recipe for target 'src/rabbit_framing_amqp_0_9_1.erl' failed
make: *** [src/rabbit_framing_amqp_0_9_1.erl] Error 1

codegen.py until where the error appeared (last line of code):

##  The contents of this file are subject to the Mozilla Public License
##  Version 1.1 (the "License"); you may not use this file except in
##  compliance with the License. You may obtain a copy of the License
##  at http://www.mozilla.org/MPL/
##
##  Software distributed under the License is distributed on an "AS IS"
##  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
##  the License for the specific language governing rights and
##  limitations under the License.
##
##  The Original Code is RabbitMQ.
##
##  The Initial Developer of the Original Code is GoPivotal, Inc.
##  Copyright (c) 2007-2013 GoPivotal, Inc.  All rights reserved.
##

from __future__ import nested_scopes

import sys
sys.path.append("../rabbitmq-codegen")  # in case we're next to an experimental revision
sys.path.append("codegen")              # in case we're building from a distribution package

from amqp_codegen import *
import string
import re

# Coming up with a proper encoding of AMQP tables in JSON is too much
# hassle at this stage. Given that the only default value we are
# interested in is for the empty table, we only support that.
def convertTable(d):
    if len(d) == 0:
        return "[]"
    else:
        raise Exception('Non-empty table defaults not supported ' + d)

erlangDefaultValueTypeConvMap = {
    bool : lambda x: str(x).lower(),
    str : lambda x: "<<\"" + x + "\">>",
    int : lambda x: str(x),
    float : lambda x: str(x),
    dict: convertTable,
    unicode: lambda x: "<<\"" + x.encode("utf-8") + "\">>"
}

def erlangize(s):
    s = s.replace('-', '_')
    s = s.replace(' ', '_')
    return s

AmqpMethod.erlangName = lambda m: "'" + erlangize(m.klass.name) + '.' + erlangize(m.name) + "'"

AmqpClass.erlangName = lambda c: "'" + erlangize(c.name) + "'"

def erlangConstantName(s):
    return '_'.join(re.split('[- ]', s.upper()))

class PackedMethodBitField:
    def __init__(self, index):
        self.index = index
        self.domain = 'bit'
        self.contents = []

    def extend(self, f):
        self.contents.append(f)

    def count(self):
        return len(self.contents)

    def full(self):
        return self.count() == 8

def multiLineFormat(things, prologue, separator, lineSeparator, epilogue, thingsPerLine = 4):
    r = [prologue]
    i = 0
    for t in things:
        if i != 0:
            if i % thingsPerLine == 0:
                r += [lineSeparator]
            else:
                r += [separator]
        r += [t]
        i += 1
    r += [epilogue]
    return "".join(r)

def prettyType(typeName, subTypes, typesPerLine = 4):
    """Pretty print a type signature made up of many alternative subtypes"""
    sTs = multiLineFormat(subTypes,
                          "( ", " | ", "\n       | ", " )",
                          thingsPerLine = typesPerLine)
    return "-type(%s ::\n       %s)." % (typeName, sTs)

def printFileHeader():
    print """%%   Autogenerated code. Do not edit.
%%
%%  The contents of this file are subject to the Mozilla Public License
%%  Version 1.1 (the "License"); you may not use this file except in
%%  compliance with the License. You may obtain a copy of the License
%%  at http://www.mozilla.org/MPL/
%%
%%  Software distributed under the License is distributed on an "AS IS"
%%  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%%  the License for the specific language governing rights and
%%  limitations under the License.
%%
%%  The Original Code is RabbitMQ.
%%
%%  The Initial Developer of the Original Code is GoPivotal, Inc.
%%  Copyright (c) 2007-2013 GoPivotal, Inc.  All rights reserved.
%%"""
like image 336
Joshua Avatar asked Jan 12 '23 11:01

Joshua


1 Answers

The issue is not the triple quotes. Because you're using Python 3, print is a function instead of a statement. Surround the triple-quoted string in parentheses.

like image 96
Ismail Badawi Avatar answered Jan 22 '23 07:01

Ismail Badawi