parameters: (self, context_document=None, test_mode=False, REQUEST=None, **kw)
return_statement: return object_list
docstring: Make this object callable. It will call the method defined in reference using
      the web service connector it is related to
docstring_summary: Make this object callable. It will call the method defined in reference using
      the web service connector it is related to
docstring_tokens: Make this object callable . It will call the method defined in reference using the web service connector it is related to
function: def __call__(self, context_document=None, test_mode=False, REQUEST=None, **kw):
      """
      Make this object callable. It will call the method defined in reference using
      the web service connector it is related to
      """
      if REQUEST is not None:
        return self.view()
      #LOG("_call__", 300, kw)
      if kw.has_key("id"):
        kw[self.getIDParameterName()] = str(kw.pop("id"))
  
      sub_id = None
      if kw.has_key(self.getIDParameterName()) and ID_SEPARATOR in kw[self.getIDParameterName()]:
        kw[self.getIDParameterName()], sub_id = kw[self.getIDParameterName()].split(ID_SEPARATOR)
  
      object_list = []
      method_name = self.getReference()
      try:
        connection = self.getSourceValue().getConnection()
      except AttributeError:
        LOG("__call__ of %s" %(self.getPath(),), ERROR,
            "Error on getting connection, connector is %s" %(self.getSourceValue(),))
        connection = None
      if connection is None:
        if test_mode:
          self._edit(last_request_parameter=str(kw),
                     last_request_result="",
                     last_request_path="",
                     last_request_error="No connection available, connector is %s" %(self.getSourceValue(),))
          return []
        else:
          raise ValueError("No connection available")
  
      # Add specific parameters defined on integration site
      site = self.getIntegrationSite()
      if site.getLanguage():
        kw['language'] = site.getLanguage()
  
      if site.getStartDate():
        kw['start_date'] = site.getStartDate()
  
      if site.getStopDate():
        kw['stop_date'] = site.getStopDate()
  
        
      # Render page template content
      if self.hasData():
        #LOG("passing options %s to self %s" %(kw, self.getPath()), 300, "CALL")
        pt_data = self.pt_render(extra_context={'options': kw, })
        pt_data = pt_data.replace('\n', '')
        kw = {'data': pt_data}
  
      # transforms parameters
      #LOG("before transformation of params %s" %(kw), 300, self.getPath())
      new_kw = kw.copy()
      args = []
      if self.getDestination():
        for k,v in kw.iteritems():
          new_key = site.getMappingFromProperty(self.getDestinationValue(), k)
          new_kw.pop(k)
          if new_key is None:
            # Some web service does not need explicit parameters
            args.append(v)
          else:
            new_kw[new_key] = v
  
      kw = new_kw
      #LOG("calling with params args = %s, kw = %s" %(args, kw), 300, self.getPath())
      error = None
  
      def callRequest(self, method_name, *args, **kw):
        connection = self.getSourceValue().getConnection()
        return getattr(connection, method_name)(*args, **kw)
  
      # cached_callRequest = CachingMethod(callRequest,
      #                                    id="WebServiceRequest_callRequest",
      #                                    cache_factory="erp5_content_short")
      
      # Call the method
      try:
        url, xml = callRequest(self, method_name, *args, **kw)
      except ConnectionError, msg:
        if test_mode:
          error = msg
          url = connection.url
          xml = ""
        else:
          raise
  
      # Register information for testing/debug purposes
      if test_mode:
        self._edit(last_request_parameter="args = %s, kw = %s" %(str(args), str(kw)),
                   last_request_result=xml,
                   last_request_path=url,
                   last_request_error=error)
  
      def buildParserDict(root_mapping):
        parser_dict = {}
        for mapping in root_mapping.contentValues():
          if len(mapping.contentValues()):
            sub_parser_dict = buildParserDict(mapping)
            parser_dict[mapping.getSourceReference()] = (mapping.getDestinationReference(), sub_parser_dict)
          else:
            parser_dict[mapping.getSourceReference()] = (mapping.getDestinationReference(), None)
        return parser_dict
  
      if self.hasDestination():
        sub_parser_dict = buildParserDict(self.getDestinationValue())
        parser_dict = {self.getDestinationValue().getSourceReference() : (self.getDestinationValue().getDestinationReference(), sub_parser_dict)}
      else:
        return []
  
      # Parse the result
      if self.getSourceValue().getParserMethodId():
        method = getattr(self, self.getSourceValue().getParserMethodId())
        result_list = method(result=xml, parser_dict=parser_dict)
      else:
        if type(xml) == list:
          result_list = self.parse_dict(parser_dict, xml)
        else:
          parser = etree.XMLParser(target = NewEchoDictTarget(parser_dict))
          # FIXME: About prestashop sync, '&' and '&' char in xml cause problem
          # xml = xml.replace('&', '')
          #LOG("got XML from WSR %s = %s" %(method_name, xml), 300, "will call parser with %s" %(parser_dict))
          result_list = []
          try:
            result_list = etree.XML(xml, parser,)
            #LOG("result_list = %r" %(result_list), 300, "")
          except etree.XMLSyntaxError:
            LOG("WebServiceRequest", ERROR, "Bad XML returned by request %s with kw = %s, xml = %s" %(self.getPath(), kw, xml))
            if test_mode:
              self._edit(last_request_error="Bad XML returned by request, impossible to parse it")
            else:
              raise ValueError("Bad XML returned by request %s with kw = %s, xml = %s" %(self.getPath(), kw, xml))
  
      brain = getBrain(self.brain_class_file, self.brain_class_name, reload=1)
  
      script_id = self.getBrainBuilderScript(None)
      if script_id is not None:
        brain_builder_script = getattr(self, script_id, None)
      else:
        brain_builder_script = None
      if brain_builder_script is not None:
        for result in result_list:
          object_list.extend(brain_builder_script(result, brain))
        if sub_id:
          object_list = [object_list[int(sub_id)-1],]
      else:
        for result in result_list:
          #LOG("initialising brain", INFO, "data is %s" %(result))
          obj = brain(context=self,
                      object_type=self.getDestinationObjectType(),
                      **result)
          object_list.append(obj)
  
      return object_list
function_tokens: def __call__ ( self , context_document = None , test_mode = False , REQUEST = None , * * kw ) : if REQUEST is not None : return self . view ( ) #LOG("_call__", 300, kw) if kw . has_key ( "id" ) : kw [ self . getIDParameterName ( ) ] = str ( kw . pop ( "id" ) ) sub_id = None if kw . has_key ( self . getIDParameterName ( ) ) and ID_SEPARATOR in kw [ self . getIDParameterName ( ) ] : kw [ self . getIDParameterName ( ) ] , sub_id = kw [ self . getIDParameterName ( ) ] . split ( ID_SEPARATOR ) object_list = [ ] method_name = self . getReference ( ) try : connection = self . getSourceValue ( ) . getConnection ( ) except AttributeError : LOG ( "__call__ of %s" % ( self . getPath ( ) , ) , ERROR , "Error on getting connection, connector is %s" % ( self . getSourceValue ( ) , ) ) connection = None if connection is None : if test_mode : self . _edit ( last_request_parameter = str ( kw ) , last_request_result = "" , last_request_path = "" , last_request_error = "No connection available, connector is %s" % ( self . getSourceValue ( ) , ) ) return [ ] else : raise ValueError ( "No connection available" ) # Add specific parameters defined on integration site site = self . getIntegrationSite ( ) if site . getLanguage ( ) : kw [ 'language' ] = site . getLanguage ( ) if site . getStartDate ( ) : kw [ 'start_date' ] = site . getStartDate ( ) if site . getStopDate ( ) : kw [ 'stop_date' ] = site . getStopDate ( ) # Render page template content if self . hasData ( ) : #LOG("passing options %s to self %s" %(kw, self.getPath()), 300, "CALL") pt_data = self . pt_render ( extra_context = { 'options' : kw , } ) pt_data = pt_data . replace ( '\n' , '' ) kw = { 'data' : pt_data } # transforms parameters #LOG("before transformation of params %s" %(kw), 300, self.getPath()) new_kw = kw . copy ( ) args = [ ] if self . getDestination ( ) : for k , v in kw . iteritems ( ) : new_key = site . getMappingFromProperty ( self . getDestinationValue ( ) , k ) new_kw . pop ( k ) if new_key is None : # Some web service does not need explicit parameters args . append ( v ) else : new_kw [ new_key ] = v kw = new_kw #LOG("calling with params args = %s, kw = %s" %(args, kw), 300, self.getPath()) error = None def callRequest ( self , method_name , * args , * * kw ) : connection = self . getSourceValue ( ) . getConnection ( ) return getattr ( connection , method_name ) ( * args , * * kw ) # cached_callRequest = CachingMethod(callRequest, #                                    id="WebServiceRequest_callRequest", #                                    cache_factory="erp5_content_short") # Call the method try : url , xml = callRequest ( self , method_name , * args , * * kw ) except ConnectionError , msg : if test_mode : error = msg url = connection . url xml = "" else : raise # Register information for testing/debug purposes if test_mode : self . _edit ( last_request_parameter = "args = %s, kw = %s" % ( str ( args ) , str ( kw ) ) , last_request_result = xml , last_request_path = url , last_request_error = error ) def buildParserDict ( root_mapping ) : parser_dict = { } for mapping in root_mapping . contentValues ( ) : if len ( mapping . contentValues ( ) ) : sub_parser_dict = buildParserDict ( mapping ) parser_dict [ mapping . getSourceReference ( ) ] = ( mapping . getDestinationReference ( ) , sub_parser_dict ) else : parser_dict [ mapping . getSourceReference ( ) ] = ( mapping . getDestinationReference ( ) , None ) return parser_dict if self . hasDestination ( ) : sub_parser_dict = buildParserDict ( self . getDestinationValue ( ) ) parser_dict = { self . getDestinationValue ( ) . getSourceReference ( ) : ( self . getDestinationValue ( ) . getDestinationReference ( ) , sub_parser_dict ) } else : return [ ] # Parse the result if self . getSourceValue ( ) . getParserMethodId ( ) : method = getattr ( self , self . getSourceValue ( ) . getParserMethodId ( ) ) result_list = method ( result = xml , parser_dict = parser_dict ) else : if type ( xml ) == list : result_list = self . parse_dict ( parser_dict , xml ) else : parser = etree . XMLParser ( target = NewEchoDictTarget ( parser_dict ) ) # FIXME: About prestashop sync, '&' and '&' char in xml cause problem # xml = xml.replace('&', '') #LOG("got XML from WSR %s = %s" %(method_name, xml), 300, "will call parser with %s" %(parser_dict)) result_list = [ ] try : result_list = etree . XML ( xml , parser , ) #LOG("result_list = %r" %(result_list), 300, "") except etree . XMLSyntaxError : LOG ( "WebServiceRequest" , ERROR , "Bad XML returned by request %s with kw = %s, xml = %s" % ( self . getPath ( ) , kw , xml ) ) if test_mode : self . _edit ( last_request_error = "Bad XML returned by request, impossible to parse it" ) else : raise ValueError ( "Bad XML returned by request %s with kw = %s, xml = %s" % ( self . getPath ( ) , kw , xml ) ) brain = getBrain ( self . brain_class_file , self . brain_class_name , reload = 1 ) script_id = self . getBrainBuilderScript ( None ) if script_id is not None : brain_builder_script = getattr ( self , script_id , None ) else : brain_builder_script = None if brain_builder_script is not None : for result in result_list : object_list . extend ( brain_builder_script ( result , brain ) ) if sub_id : object_list = [ object_list [ int ( sub_id ) - 1 ] , ] else : for result in result_list : #LOG("initialising brain", INFO, "data is %s" %(result)) obj = brain ( context = self , object_type = self . getDestinationObjectType ( ) , * * result ) object_list . append ( obj ) return object_list