Module pylupdate :: Class FunctionValidator
[hide private]
[frames] | no frames]

Class FunctionValidator

source code

     object --+        
              |        
ast.NodeVisitor --+    
                  |    
      ParentVisitor --+
                      |
                     FunctionValidator

ast Visitor to find calls to pyTSon's translation functions

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
bool
_hasImport(self)
Checks, if the translation functions were already imported
source code
ast.ClassDef
_getClass(self, node)
Returns the parent class of some ast node
source code
bool
_classIsTranslatable(self, node)
Checks, if a class is a subclass of pytson.Translatable
source code
tuple(str, str or None, bool)
_getKeywords(self, node)
Gets the keyword parameters of a translate function call
source code
tuple(str, str, str or None, bool) or None
_extractMethodCall(self, node)
Extracts all info from a Translatable._tr call
source code
tuple(str, Message) or None
_extractModuleCall(self, node)
Extracts all info from a pytson.tr call
source code
tuple(str, Message) or None
_extractFunctionCall(self, node)
Extracts all info from a tr call (imported with alias)
source code
tuple(str, str, str or None, bool) or None
_validateExtract(self, node)
Extracts all info from a translation call
source code
 
visit_Import(self, node)
Visits each import of the ast
source code
 
visit_ImportFrom(self, node)
Visits each import (from) of the ast
source code
 
visit_Call(self, node)
Visits each function call of the ast
source code

Inherited from ParentVisitor: generic_visit

Inherited from ast.NodeVisitor: visit

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
bool
_checkArguments(node, count)
Checks, if the argument list of a translation function is valid
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

_hasImport(self)

source code 

Checks, if the translation functions were already imported

Returns: bool
Returns True, if any function is available

_getClass(self, node)

source code 

Returns the parent class of some ast node

Parameters:
  • node (ast.AST) - the node to get the parent of (must be previously visited with ParentVisitor)
Returns: ast.ClassDef
the node of the parent class

_classIsTranslatable(self, node)

source code 

Checks, if a class is a subclass of pytson.Translatable

Parameters:
  • node (ast.ClassDef) - the node of the classdef
Returns: bool
True or False

_getKeywords(self, node)

source code 

Gets the keyword parameters of a translate function call

Parameters:
  • node (ast.AST)
Returns: tuple(str, str or None, bool)
a tuple containing the contextname, the source string, the disambiguation string and if the numerous form is requested

_checkArguments(node, count)
Static Method

source code 

Checks, if the argument list of a translation function is valid

Parameters:
  • node (ast.AST) - the node of the call
  • count (int) - number of arguments to check for
Returns: bool
True or False

_extractMethodCall(self, node)

source code 

Extracts all info from a Translatable._tr call

Parameters:
  • node (ast.Attribute) - the method call
Returns: tuple(str, str, str or None, bool) or None
a tuple containing the contextname and the message or None, if the call is not valid

_extractModuleCall(self, node)

source code 

Extracts all info from a pytson.tr call

Parameters:
  • node (ast.Attribute) - the function call
Returns: tuple(str, Message) or None
a tuple containing the contextname and the message or None, if the call is not valid

_extractFunctionCall(self, node)

source code 

Extracts all info from a tr call (imported with alias)

Parameters:
  • node (ast.Attribute) - the function call
Returns: tuple(str, Message) or None
a tuple containing the contextname and the message or None, if the call is not valid

_validateExtract(self, node)

source code 

Extracts all info from a translation call

Parameters:
  • node (ast.Attribute) - the method call
Returns: tuple(str, str, str or None, bool) or None
a tuple containing the contextname and the message or None, if the call is not valid

visit_Import(self, node)

source code 

Visits each import of the ast

Parameters:
  • node (ast.Import) - the import node

visit_ImportFrom(self, node)

source code 

Visits each import (from) of the ast

Parameters:
  • node (ast.ImportFrom) - the import node

visit_Call(self, node)

source code 

Visits each function call of the ast

Parameters:
  • node (ast.Call) - the call node