OpenSDN source code
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_program * get_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_type * get_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_program * program_
 
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 48 of file t_py_generator.cc.

Constructor & Destructor Documentation

◆ t_py_generator()

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 50 of file t_py_generator.cc.

Member Function Documentation

◆ argument_list()

string t_py_generator::argument_list ( t_struct *  tstruct)

Renders a field list

Definition at line 4054 of file t_py_generator.cc.

Here is the call graph for this function:

◆ close_generator()

void t_py_generator::close_generator ( )
virtual

Closes the type files

Reimplemented from t_generator.

Definition at line 577 of file t_py_generator.cc.

◆ declare_argument()

string t_py_generator::declare_argument ( t_field *  tfield)

Declares an argument, which may include initialization as necessary.

Parameters
tfieldThe field

Definition at line 3993 of file t_py_generator.cc.

Here is the call graph for this function:

◆ function_signature()

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 4025 of file t_py_generator.cc.

Here is the call graph for this function:

◆ function_signature_if()

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 4039 of file t_py_generator.cc.

Here is the call graph for this function:

◆ future_imports()

string t_py_generator::future_imports ( )

Prints standard future imports

Definition at line 569 of file t_py_generator.cc.

◆ generate_const()

void t_py_generator::generate_const ( t_const *  tconst)
virtual

Generate a constant value

Reimplemented from t_generator.

Definition at line 647 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_deserialize_container()

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 3463 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_deserialize_field()

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 3340 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_deserialize_list_element()

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

Write a list element

Definition at line 3627 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_deserialize_map_element()

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 3571 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_deserialize_set_element()

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

Write a set element

Definition at line 3612 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_deserialize_struct()

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 3447 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_enum()

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 608 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_process_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 3146 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_py_function_helpers()

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 2517 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_py_struct()

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

Struct generation code

Generates a python struct

Definition at line 806 of file t_py_generator.cc.

◆ generate_py_struct_definition()

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 816 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_py_struct_reader()

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

Generates the read method for a struct

Definition at line 1066 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_py_struct_required_validator()

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

Definition at line 1305 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_py_struct_writer()

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

Definition at line 1202 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_python_docstring() [1/4]

void t_py_generator::generate_python_docstring ( std::ofstream &  out,
t_doc *  tdoc 
)

◆ generate_python_docstring() [2/4]

void t_py_generator::generate_python_docstring ( std::ofstream &  out,
t_doc *  tdoc,
t_struct *  tstruct,
const char *  subheader 
)

◆ generate_python_docstring() [3/4]

void t_py_generator::generate_python_docstring ( std::ofstream &  out,
t_function *  tfunction 
)

◆ generate_python_docstring() [4/4]

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

◆ generate_serialize_container()

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

Definition at line 3782 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_serialize_field()

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 3646 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_serialize_list_element()

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 3911 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_serialize_map_element()

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 3865 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_serialize_set_element()

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 3901 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_serialize_struct()

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 3758 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_service()

void t_py_generator::generate_service ( t_service *  tservice)
virtual

Generates a thrift service

Parameters
tserviceThe service definition

Implements t_generator.

Definition at line 2454 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_service_client()

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 2585 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_service_helpers()

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 2498 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_service_interface()

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 2540 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_service_remote()

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 2861 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_service_server()

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 3031 of file t_py_generator.cc.

Here is the call graph for this function:

◆ generate_struct()

void t_py_generator::generate_struct ( t_struct *  tstruct)
virtual

Generates a python struct

Implements t_generator.

Definition at line 785 of file t_py_generator.cc.

◆ generate_typedef()

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 598 of file t_py_generator.cc.

◆ generate_xception()

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 795 of file t_py_generator.cc.

◆ get_real_py_module()

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

Definition at line 294 of file t_py_generator.cc.

Here is the call graph for this function:

◆ init_generator()

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 381 of file t_py_generator.cc.

◆ is_valid_namespace()

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

Definition at line 290 of file t_py_generator.cc.

◆ py_autogen_comment()

string t_py_generator::py_autogen_comment ( )

Helper rendering functions

Autogen'd comment

Definition at line 530 of file t_py_generator.cc.

◆ py_imports()

string t_py_generator::py_imports ( )

Prints standard thrift imports

Definition at line 556 of file t_py_generator.cc.

◆ render_const_value()

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 661 of file t_py_generator.cc.

Here is the call graph for this function:

◆ render_fastbinary_includes()

string t_py_generator::render_fastbinary_includes ( )

Renders all the imports necessary to use the accelerated TBinaryProtocol

Definition at line 477 of file t_py_generator.cc.

◆ render_field_default_value()

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 4010 of file t_py_generator.cc.

Here is the call graph for this function:

◆ render_includes()

string t_py_generator::render_includes ( )

Renders all the imports necessary for including another Thrift program

Definition at line 461 of file t_py_generator.cc.

◆ type_name()

string t_py_generator::type_name ( t_type *  ttype)

Definition at line 4071 of file t_py_generator.cc.

Here is the call graph for this function:

◆ type_to_enum()

string t_py_generator::type_to_enum ( t_type *  type)

Converts the parse type to a Python tyoe

Definition at line 4085 of file t_py_generator.cc.

Here is the call graph for this function:

◆ type_to_spec_args()

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 4170 of file t_py_generator.cc.

Here is the call graph for this function:

Member Data Documentation

◆ copy_options_

std::string t_py_generator::copy_options_
private

Definition at line 329 of file t_py_generator.cc.

◆ f_consts_

std::ofstream t_py_generator::f_consts_
private

Definition at line 363 of file t_py_generator.cc.

◆ f_service_

std::ofstream t_py_generator::f_service_
private

Definition at line 364 of file t_py_generator.cc.

◆ f_types_

std::ofstream t_py_generator::f_types_
private

File streams

Definition at line 362 of file t_py_generator.cc.

◆ gen_dynamic_

bool t_py_generator::gen_dynamic_
private

True if we should generate dynamic style classes.

Definition at line 319 of file t_py_generator.cc.

◆ gen_dynbase_

bool t_py_generator::gen_dynbase_
private

Definition at line 321 of file t_py_generator.cc.

◆ gen_dynbaseclass_

std::string t_py_generator::gen_dynbaseclass_
private

Definition at line 322 of file t_py_generator.cc.

◆ gen_dynbaseclass_exc_

std::string t_py_generator::gen_dynbaseclass_exc_
private

Definition at line 323 of file t_py_generator.cc.

◆ gen_newstyle_

bool t_py_generator::gen_newstyle_
private

True if we should generate new-style classes.

Definition at line 314 of file t_py_generator.cc.

◆ gen_slots_

bool t_py_generator::gen_slots_
private

Definition at line 327 of file t_py_generator.cc.

◆ gen_twisted_

bool t_py_generator::gen_twisted_
private

True if we should generate Twisted-friendly RPC services.

Definition at line 334 of file t_py_generator.cc.

◆ gen_utf8strings_

bool t_py_generator::gen_utf8strings_
private

True if strings should be encoded using utf-8.

Definition at line 339 of file t_py_generator.cc.

◆ import_dynbase_

std::string t_py_generator::import_dynbase_
private

Definition at line 325 of file t_py_generator.cc.

◆ package_dir_

std::string t_py_generator::package_dir_
private

Definition at line 370 of file t_py_generator.cc.


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