OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
t_py_generator Class Reference
Inheritance diagram for t_py_generator:
Collaboration diagram for t_py_generator:

Public Member Functions

 t_py_generator (t_program *program, const std::map< std::string, std::string > &parsed_options, const std::string &option_string)
 
void init_generator ()
 
void close_generator ()
 
void generate_typedef (t_typedef *ttypedef)
 
void generate_enum (t_enum *tenum)
 
void generate_const (t_const *tconst)
 
void generate_struct (t_struct *tstruct)
 
void generate_xception (t_struct *txception)
 
void generate_service (t_service *tservice)
 
std::string render_const_value (t_type *type, t_const_value *value)
 
void generate_py_struct (t_struct *tstruct, bool is_exception)
 
void generate_py_struct_definition (std::ofstream &out, t_struct *tstruct, bool is_xception=false, bool is_result=false)
 
void generate_py_struct_reader (std::ofstream &out, t_struct *tstruct)
 
void generate_py_struct_writer (std::ofstream &out, t_struct *tstruct)
 
void generate_py_struct_required_validator (std::ofstream &out, t_struct *tstruct)
 
void generate_py_function_helpers (t_function *tfunction)
 
void generate_service_helpers (t_service *tservice)
 
void generate_service_interface (t_service *tservice)
 
void generate_service_client (t_service *tservice)
 
void generate_service_remote (t_service *tservice)
 
void generate_service_server (t_service *tservice)
 
void generate_process_function (t_service *tservice, t_function *tfunction)
 
void generate_deserialize_field (std::ofstream &out, t_field *tfield, std::string prefix="", bool inclass=false)
 
void generate_deserialize_struct (std::ofstream &out, t_struct *tstruct, std::string prefix="")
 
void generate_deserialize_container (std::ofstream &out, t_type *ttype, std::string prefix="")
 
void generate_deserialize_set_element (std::ofstream &out, t_set *tset, std::string prefix="")
 
void generate_deserialize_map_element (std::ofstream &out, t_map *tmap, std::string prefix="")
 
void generate_deserialize_list_element (std::ofstream &out, t_list *tlist, std::string prefix="")
 
void generate_serialize_field (std::ofstream &out, t_field *tfield, std::string prefix="")
 
void generate_serialize_struct (std::ofstream &out, t_struct *tstruct, std::string prefix="")
 
void generate_serialize_container (std::ofstream &out, t_type *ttype, std::string prefix="")
 
void generate_serialize_map_element (std::ofstream &out, t_map *tmap, std::string kiter, std::string viter)
 
void generate_serialize_set_element (std::ofstream &out, t_set *tmap, std::string iter)
 
void generate_serialize_list_element (std::ofstream &out, t_list *tlist, std::string iter)
 
void generate_python_docstring (std::ofstream &out, t_struct *tstruct)
 
void generate_python_docstring (std::ofstream &out, t_function *tfunction)
 
void generate_python_docstring (std::ofstream &out, t_doc *tdoc, t_struct *tstruct, const char *subheader)
 
void generate_python_docstring (std::ofstream &out, t_doc *tdoc)
 
std::string py_autogen_comment ()
 
std::string future_imports ()
 
std::string py_imports ()
 
std::string render_includes ()
 
std::string render_fastbinary_includes ()
 
std::string declare_argument (t_field *tfield)
 
std::string render_field_default_value (t_field *tfield)
 
std::string type_name (t_type *ttype)
 
std::string function_signature (t_function *tfunction, std::string prefix="")
 
std::string function_signature_if (t_function *tfunction, std::string prefix="")
 
std::string argument_list (t_struct *tstruct)
 
std::string type_to_enum (t_type *ttype)
 
std::string type_to_spec_args (t_type *ttype)
 
- Public Member Functions inherited from t_generator
 t_generator (t_program *program)
 
virtual ~t_generator ()
 
virtual void generate_program ()
 
const t_programget_program () const
 
void generate_docstring_comment (std::ofstream &out, const std::string &comment_start, const std::string &line_prefix, const std::string &contents, const std::string &comment_end)
 
virtual std::string escape_string (const std::string &in) const
 
std::string get_escaped_string (t_const_value *constval)
 

Static Public Member Functions

static bool is_valid_namespace (const std::string &sub_namespace)
 
static std::string get_real_py_module (const t_program *program, bool gen_twisted)
 
- Static Public Member Functions inherited from t_generator
static bool is_valid_namespace (const std::string &sub_namespace)
 
static t_typeget_true_type (t_type *type)
 

Private Attributes

bool gen_newstyle_
 
bool gen_dynamic_
 
bool gen_dynbase_
 
std::string gen_dynbaseclass_
 
std::string gen_dynbaseclass_exc_
 
std::string import_dynbase_
 
bool gen_slots_
 
std::string copy_options_
 
bool gen_twisted_
 
bool gen_utf8strings_
 
std::ofstream f_types_
 
std::ofstream f_consts_
 
std::ofstream f_service_
 
std::string package_dir_
 

Additional Inherited Members

- Protected Member Functions inherited from t_generator
virtual void generate_consts (std::vector< t_const * > consts)
 
virtual std::string get_program_name (t_program *tprogram)
 
virtual std::string get_service_name (t_service *tservice)
 
virtual std::string get_out_dir () const
 
std::string tmp (std::string name)
 
void indent_up ()
 
void indent_down ()
 
std::string indent ()
 
std::ostream & indent (std::ostream &os)
 
std::string capitalize (std::string in)
 
std::string decapitalize (std::string in)
 
std::string lowercase (std::string in)
 
std::string uppercase (std::string in)
 
std::string underscore (std::string in)
 
std::string camelcase (std::string in)
 
- Protected Attributes inherited from t_generator
t_programprogram_
 
std::string program_name_
 
std::string service_name_
 
std::string out_dir_base_
 
std::map< char, std::string > escape_
 

Detailed Description

Python code generator.

Definition at line 45 of file t_py_generator.cc.

Constructor & Destructor Documentation

t_py_generator::t_py_generator ( t_program program,
const std::map< std::string, std::string > &  parsed_options,
const std::string &  option_string 
)
inline

Definition at line 47 of file t_py_generator.cc.

Member Function Documentation

string t_py_generator::argument_list ( t_struct tstruct)

Renders a field list

Definition at line 4051 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::close_generator ( )
virtual

Closes the type files

Reimplemented from t_generator.

Definition at line 574 of file t_py_generator.cc.

string t_py_generator::declare_argument ( t_field tfield)

Declares an argument, which may include initialization as necessary.

Parameters
tfieldThe field

Definition at line 3990 of file t_py_generator.cc.

Here is the call graph for this function:

string t_py_generator::function_signature ( t_function tfunction,
std::string  prefix = "" 
)

Renders a function signature of the form 'type name(args)'

Parameters
tfunctionFunction definition
Returns
String of rendered function definition

Definition at line 4022 of file t_py_generator.cc.

Here is the call graph for this function:

string t_py_generator::function_signature_if ( t_function tfunction,
std::string  prefix = "" 
)

Renders an interface function signature of the form 'type name(args)'

Parameters
tfunctionFunction definition
Returns
String of rendered function definition

Definition at line 4036 of file t_py_generator.cc.

Here is the call graph for this function:

string t_py_generator::future_imports ( )

Prints standard future imports

Definition at line 566 of file t_py_generator.cc.

void t_py_generator::generate_const ( t_const tconst)
virtual

Generate a constant value

Reimplemented from t_generator.

Definition at line 644 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_deserialize_container ( std::ofstream &  out,
t_type ttype,
std::string  prefix = "" 
)

Serialize a container by writing out the header followed by data and then a footer.

Definition at line 3460 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_deserialize_field ( std::ofstream &  out,
t_field tfield,
std::string  prefix = "",
bool  inclass = false 
)

Serialization constructs

Deserializes a field of any type.

Definition at line 3337 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_deserialize_list_element ( std::ofstream &  out,
t_list tlist,
std::string  prefix = "" 
)

Write a list element

Definition at line 3624 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_deserialize_map_element ( std::ofstream &  out,
t_map tmap,
std::string  prefix = "" 
)

Generates code to deserialize a map

Definition at line 3568 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_deserialize_set_element ( std::ofstream &  out,
t_set tset,
std::string  prefix = "" 
)

Write a set element

Definition at line 3609 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_deserialize_struct ( std::ofstream &  out,
t_struct tstruct,
std::string  prefix = "" 
)

Generates an unserializer for a struct, calling read()

Definition at line 3444 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_enum ( t_enum tenum)
virtual

Generates code for an enumerated type. Done using a class to scope the values.

Parameters
tenumThe enumeration

Implements t_generator.

Definition at line 605 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_process_function ( t_service tservice,
t_function tfunction 
)

Generates a process function definition.

Parameters
tfunctionThe function to write a dispatcher for

Definition at line 3143 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_py_function_helpers ( t_function tfunction)

Generates a struct and helpers for a function.

Parameters
tfunctionThe function

Definition at line 2514 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_py_struct ( t_struct tstruct,
bool  is_exception 
)

Struct generation code

Generates a python struct

Definition at line 803 of file t_py_generator.cc.

void t_py_generator::generate_py_struct_definition ( std::ofstream &  out,
t_struct tstruct,
bool  is_xception = false,
bool  is_result = false 
)

Generates a struct definition for a thrift data type.

Parameters
tstructThe struct definition

Definition at line 813 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_py_struct_reader ( std::ofstream &  out,
t_struct tstruct 
)

Generates the read method for a struct

Definition at line 1063 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_py_struct_required_validator ( std::ofstream &  out,
t_struct tstruct 
)

Definition at line 1302 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_py_struct_writer ( std::ofstream &  out,
t_struct tstruct 
)

Definition at line 1199 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_python_docstring ( std::ofstream &  out,
t_struct tstruct 
)
void t_py_generator::generate_python_docstring ( std::ofstream &  out,
t_function tfunction 
)
void t_py_generator::generate_python_docstring ( std::ofstream &  out,
t_doc tdoc,
t_struct tstruct,
const char *  subheader 
)
void t_py_generator::generate_python_docstring ( std::ofstream &  out,
t_doc tdoc 
)
void t_py_generator::generate_serialize_container ( std::ofstream &  out,
t_type ttype,
std::string  prefix = "" 
)

Definition at line 3779 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_serialize_field ( std::ofstream &  out,
t_field tfield,
std::string  prefix = "" 
)

Serializes a field of any type.

Parameters
tfieldThe field to serialize
prefixName to prepend to field name

Definition at line 3643 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_serialize_list_element ( std::ofstream &  out,
t_list tlist,
std::string  iter 
)

Serializes the members of a list.

Definition at line 3908 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_serialize_map_element ( std::ofstream &  out,
t_map tmap,
std::string  kiter,
std::string  viter 
)

Serializes the members of a map.

Definition at line 3862 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_serialize_set_element ( std::ofstream &  out,
t_set tmap,
std::string  iter 
)

Serializes the members of a set.

Definition at line 3898 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_serialize_struct ( std::ofstream &  out,
t_struct tstruct,
std::string  prefix = "" 
)

Serializes all the members of a struct.

Parameters
tstructThe struct to serialize
prefixString prefix to attach to all fields

Definition at line 3755 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_service ( t_service tservice)
virtual

Generates a thrift service

Parameters
tserviceThe service definition

Implements t_generator.

Definition at line 2451 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_service_client ( t_service tservice)

Generates a service client definition.

Parameters
tserviceThe service to generate a server for.

Definition at line 2582 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_service_helpers ( t_service tservice)

Sandesh generation code Service-level generation functions

Generates helper functions for a service.

Parameters
tserviceThe service to generate a header definition for

Definition at line 2495 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_service_interface ( t_service tservice)

Generates a service interface definition.

Parameters
tserviceThe service to generate a header definition for

Definition at line 2537 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_service_remote ( t_service tservice)

Generates a command line tool for making remote requests

Parameters
tserviceThe service to generate a remote for.

Definition at line 2858 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_service_server ( t_service tservice)

Generates a service server definition.

Parameters
tserviceThe service to generate a server for.

Definition at line 3028 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::generate_struct ( t_struct tstruct)
virtual

Generates a python struct

Implements t_generator.

Definition at line 782 of file t_py_generator.cc.

void t_py_generator::generate_typedef ( t_typedef ttypedef)
virtual

Program-level generation functions

Generates a typedef. This is not done in Python, types are all implicit.

Parameters
ttypedefThe type definition

Implements t_generator.

Definition at line 595 of file t_py_generator.cc.

void t_py_generator::generate_xception ( t_struct txception)
virtual

Generates a struct definition for a thrift exception. Basically the same as a struct but extends the Exception class.

Parameters
txceptionThe struct definition

Reimplemented from t_generator.

Definition at line 792 of file t_py_generator.cc.

static std::string t_py_generator::get_real_py_module ( const t_program program,
bool  gen_twisted 
)
inlinestatic

Definition at line 291 of file t_py_generator.cc.

Here is the call graph for this function:

void t_py_generator::init_generator ( )
virtual

Init and close methods

Prepares for file generation by opening up the necessary file output streams.

Parameters
tprogramThe program to generate

Reimplemented from t_generator.

Definition at line 378 of file t_py_generator.cc.

static bool t_py_generator::is_valid_namespace ( const std::string &  sub_namespace)
inlinestatic

Definition at line 287 of file t_py_generator.cc.

string t_py_generator::py_autogen_comment ( )

Helper rendering functions

Autogen'd comment

Definition at line 527 of file t_py_generator.cc.

string t_py_generator::py_imports ( )

Prints standard thrift imports

Definition at line 553 of file t_py_generator.cc.

string t_py_generator::render_const_value ( t_type type,
t_const_value value 
)

Prints the value of a constant with the given type. Note that type checking is NOT performed in this function as it is always run beforehand using the validate_types method in main.cc

Definition at line 658 of file t_py_generator.cc.

Here is the call graph for this function:

string t_py_generator::render_fastbinary_includes ( )

Renders all the imports necessary to use the accelerated TBinaryProtocol

Definition at line 474 of file t_py_generator.cc.

string t_py_generator::render_field_default_value ( t_field tfield)

Renders a field default value, returns None otherwise.

Parameters
tfieldThe field

Definition at line 4007 of file t_py_generator.cc.

Here is the call graph for this function:

string t_py_generator::render_includes ( )

Renders all the imports necessary for including another Thrift program

Definition at line 458 of file t_py_generator.cc.

string t_py_generator::type_name ( t_type ttype)

Definition at line 4068 of file t_py_generator.cc.

Here is the call graph for this function:

string t_py_generator::type_to_enum ( t_type type)

Converts the parse type to a Python tyoe

Definition at line 4082 of file t_py_generator.cc.

Here is the call graph for this function:

string t_py_generator::type_to_spec_args ( t_type ttype)

See the comment inside generate_py_struct_definition for what this is.

Definition at line 4167 of file t_py_generator.cc.

Here is the call graph for this function:

Member Data Documentation

std::string t_py_generator::copy_options_
private

Definition at line 326 of file t_py_generator.cc.

std::ofstream t_py_generator::f_consts_
private

Definition at line 360 of file t_py_generator.cc.

std::ofstream t_py_generator::f_service_
private

Definition at line 361 of file t_py_generator.cc.

std::ofstream t_py_generator::f_types_
private

File streams

Definition at line 359 of file t_py_generator.cc.

bool t_py_generator::gen_dynamic_
private

True if we should generate dynamic style classes.

Definition at line 316 of file t_py_generator.cc.

bool t_py_generator::gen_dynbase_
private

Definition at line 318 of file t_py_generator.cc.

std::string t_py_generator::gen_dynbaseclass_
private

Definition at line 319 of file t_py_generator.cc.

std::string t_py_generator::gen_dynbaseclass_exc_
private

Definition at line 320 of file t_py_generator.cc.

bool t_py_generator::gen_newstyle_
private

True if we should generate new-style classes.

Definition at line 311 of file t_py_generator.cc.

bool t_py_generator::gen_slots_
private

Definition at line 324 of file t_py_generator.cc.

bool t_py_generator::gen_twisted_
private

True if we should generate Twisted-friendly RPC services.

Definition at line 331 of file t_py_generator.cc.

bool t_py_generator::gen_utf8strings_
private

True if strings should be encoded using utf-8.

Definition at line 336 of file t_py_generator.cc.

std::string t_py_generator::import_dynbase_
private

Definition at line 322 of file t_py_generator.cc.

std::string t_py_generator::package_dir_
private

Definition at line 367 of file t_py_generator.cc.


The documentation for this class was generated from the following file: