# Source files
SRC_FILES = main.cc \
generate/t_generator.cc \
+ generate/t_py_generator.cc \
generate/t_java_generator.cc \
generate/t_php_generator.cc \
generate/t_cpp_generator.cc
php_includes();
f_service_ <<
- "require_once dirname(__FILE__).'/" << service_name_ << "_types.php';" << endl << endl;
+ "require_once dirname(__FILE__).'/" << program_name_ << "_types.php';" << endl << endl;
// Generate the three main parts of the service (well, two for now in PHP)
generate_service_interface(tservice);
result += " = 0";
} else if (type->is_container()) {
result += " = array()";
- } else if (type->is_struct()) {
+ } else if (type->is_struct() || type->is_xception()) {
if (obj) {
result += " = new " + type->get_name() + "()";
} else {
#include "generate/t_cpp_generator.h"
#include "generate/t_java_generator.h"
#include "generate/t_php_generator.h"
+#include "generate/t_py_generator.h"
using namespace std;
fprintf(stderr, " --java Generate Java output files\n");
fprintf(stderr, " --php Generate PHP output files\n");
fprintf(stderr, " --phpi Generate PHP inlined files\n");
- //fprintf(stderr, " -python Generate Python output files\n");
- fprintf(stderr, " --debug Print parse debugging to standard output\n");
+ fprintf(stderr, " --py Generate Python output files\n");
+ fprintf(stderr, " --debug Print parse debugging to standard output\n");
exit(1);
}
int i;
bool gen_cpp = false;
bool gen_java = false;
+ bool gen_py = false;
bool gen_php = false;
bool php_inline = false;
} else if (strcmp(argv[i], "--phpi") == 0) {
gen_php = true;
php_inline = true;
+ } else if (strcmp(argv[i], "--py") == 0) {
+ gen_py = true;
} else {
fprintf(stderr, "!!! Unrecognized option: %s\n", argv[i]);
usage();
}
}
- if (!gen_cpp && !gen_java && !gen_php) {
+ if (!gen_cpp && !gen_java && !gen_php && !gen_py) {
fprintf(stderr, "!!! No output language(s) specified\n\n");
usage();
}
php->generate_program(g_program);
delete php;
}
+
+ if (gen_py) {
+ t_py_generator* py = new t_py_generator();
+ py->generate_program(g_program);
+ delete py;
+ }
} catch (string s) {
printf("Error: %s\n", s.c_str());
} catch (const char* exc) {
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
* @parem int $seqid The sequence id of this message
*/
- public abstract function readMessageBegin($out, &$name, &$type, &$seqid);
+ public abstract function readMessageBegin($in, &$name, &$type, &$seqid);
/**
* Read the close of message
*
* @param TTransport $out Output transport
*/
- public abstract function readMessageEnd($out);
+ public abstract function readMessageEnd($in);
public abstract function readStructBegin($in, &$name);
author = ['Mark Slee'],
author_email = ['mcslee@facebook.com'],
url = 'http://code.facebook.com/thrift',
- packages = ['thrift', 'thrift.protocol', 'thrift.transport']
+ packages = ['thrift', 'thrift.protocol', 'thrift.transport'],
package_dir = {'thrift' : 'src'},
)
--- /dev/null
+# Makefile for Thrift test project.
+#
+# Author:
+# Mark Slee <mcslee@facebook.com>
+
+# Default target is everything
+target: all
+
+# Tools
+THRIFT = thrift
+
+all: stubs
+
+stubs: ../ThriftTest.thrift
+ $(THRIFT) --py ../ThriftTest.thrift
+
+clean:
+ rm -fr gen-py
--- /dev/null
+#!/usr/bin/python
+
+import sys
+sys.path.append('./gen-py')
+
+import ThriftTest
+from ThriftTest_types import *
+from thrift.transport import TSocket
+from thrift.protocol import TBinaryProtocol
+
+transport = TSocket.TSocket('localhost', 9090)
+protocol = TBinaryProtocol.TBinaryProtocol()
+client = ThriftTest.Client(transport, protocol)
+
+transport.open()
+
+print "testVoid()"
+print client.testVoid()
+
+print "testString('PythonTest')"
+print client.testString('PythonTest')
+
+print "testByte(63)"
+print client.testByte(63)
+
+print "testException('Safe')"
+print client.testException('Safe')
+
+print "textException('Xception')"
+try:
+ print client.testException('Xception')
+except Xception, x:
+ print 'Xception (%d, %s)' % (x.errorCode, x.message)
+
+transport.close()