parameters: (function, policy)
return_statement: return policy
docstring: Show a warning to the user if the function needs a policy and doesn't
      have one. Return a policy to the function, which is the given policy itself
      if it is not None, or a default policy for this method.
docstring_summary: Show a warning to the user if the function needs a policy and doesn't
      have one. Return a policy to the function, which is the given policy itself
      if it is not None, or a default policy for this method.
docstring_tokens: Show a warning to the user if the function needs a policy and doesn t have one . Return a policy to the function which is the given policy itself if it is not None or a default policy for this method .
function: def HandlePolicy(function, policy):
      '''Show a warning to the user if the function needs a policy and doesn't
      have one. Return a policy to the function, which is the given policy itself
      if it is not None, or a default policy for this method.
      '''
      
      def IsString(type):
          'Return True if the Type instance can be considered a string'
          return type.FullName() == 'const char*'
  
      def IsPyObject(type):
          return type.FullName() == '_object *' # internal name of PyObject
      
      result = function.result
      # if the function returns const char*, a policy is not needed
      if IsString(result) or IsPyObject(result):
          return policy
      # if returns a const T&, set the default policy
      if policy is None and result.const and isinstance(result, ReferenceType):
          policy = return_value_policy(copy_const_reference)
      # basic test if the result type demands a policy
      needs_policy = isinstance(result, (ReferenceType, PointerType)) 
      # show a warning to the user, if needed
      if needs_policy and policy is None:
          global _printed_warnings
          warning = '---> Error: %s returns a pointer or a reference, ' \
                    'but no policy was specified.' % function.FullName()
          if warning not in _printed_warnings:
              print warning
              print 
              # avoid double prints of the same warning
              _printed_warnings[warning] = 1
      return policy
function_tokens: def HandlePolicy ( function , policy ) : def IsString ( type ) : 'Return True if the Type instance can be considered a string' return type . FullName ( ) == 'const char*' def IsPyObject ( type ) : return type . FullName ( ) == '_object *' # internal name of PyObject result = function . result # if the function returns const char*, a policy is not needed if IsString ( result ) or IsPyObject ( result ) : return policy # if returns a const T&, set the default policy if policy is None and result . const and isinstance ( result , ReferenceType ) : policy = return_value_policy ( copy_const_reference ) # basic test if the result type demands a policy needs_policy = isinstance ( result , ( ReferenceType , PointerType ) ) # show a warning to the user, if needed if needs_policy and policy is None : global _printed_warnings warning = '---> Error: %s returns a pointer or a reference, ' 'but no policy was specified.' % function . FullName ( ) if warning not in _printed_warnings : print warning print # avoid double prints of the same warning _printed_warnings [ warning ] = 1 return policy