[Erp5-dev] [Erp5-report] r26242 - in /erp5/trunk/products/ERP5: Tool/ tests/

Yoshinori Okuji yo at nexedi.com
Thu Apr 2 05:51:34 CEST 2009


I don't understand why you need to *deprecate* cmp.

YO

On Thursday 02 April 2009 00:01:13 nobody at svn.erp5.org wrote:
> Author: jm
> Date: Wed Apr  1 17:01:12 2009
> New Revision: 26242
>
> URL: http://svn.erp5.org?rev=26242&view=rev
> Log:
> Deprecate sort_method parameter in DomainTool.searchPredicateList since cmp
> parameter in sorting methods is slow and deprecated. Add new
> sort_key_method parameter that is passed as key parameter to list.sort.
>
> Modified:
>     erp5/trunk/products/ERP5/Tool/DomainTool.py
>     erp5/trunk/products/ERP5/tests/testDomainTool.py
>
> Modified: erp5/trunk/products/ERP5/Tool/DomainTool.py
> URL:
> http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/DomainTool.py?rev=26242&r
>1=26241&r2=26242&view=diff
> ===========================================================================
>=== --- erp5/trunk/products/ERP5/Tool/DomainTool.py [utf8] (original)
> +++ erp5/trunk/products/ERP5/Tool/DomainTool.py [utf8] Wed Apr  1 17:01:12
> 2009 @@ -60,7 +60,7 @@
>                              ignored_category_list=None,
>                              tested_base_category_list=None,
>                              filter_method=None, acquired=1,
> -                            strict=True, **kw):
> +                            strict=True, sort_key_method=None, **kw):
>        # XXX: about "strict" parameter: This is a transition parameter,
>        # allowing someone hitting a bug to revert to original behaviour
> easily. # It is not a correct name, as pointed out by Jerome. But instead
> of @@ -68,9 +68,11 @@
>        """
>        Search all predicates which corresponds to this particular
>        context.
> -
> -      - The sort_method parameter allows to give a method which will be
> -        used in order to sort the list of predicates found. The most
> +
> +      - sort_method parameter is deprecated: use sort_key_method instead.
> +
> +      - sort_key_method parameter is passed to list.sort as key parameter
> if it +        is not None. This allows to sort the list of predicates
> found. The most important predicate is the first one in the list.
>
>        - ignored_category_list:  this is the list of category that we do
> @@ -203,8 +205,12 @@
>  #       LOG('searchPredicateList, result_list before sort', 0,
> result_list) if filter_method is not None:
>          result_list = filter_method(result_list)
> -      if sort_method is not None:
> -        result_list.sort(sort_method)
> +      if sort_key_method is not None:
> +        result_list.sort(key=sort_key_method)
> +      elif sort_method is not None:
> +        LOG('searchPredicateList', 0,
> +            'sort_method parameter is deprecated: sort_key_method
> instead') +        result_list.sort(cmp=sort_method)
>  #       LOG('searchPredicateList, result_list after sort', 0, result_list)
>        return result_list
>
>
> Modified: erp5/trunk/products/ERP5/tests/testDomainTool.py
> URL:
> http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testDomainTool.py?rev=26
>242&r1=26241&r2=26242&view=diff
> ===========================================================================
>=== --- erp5/trunk/products/ERP5/tests/testDomainTool.py [utf8] (original)
> +++ erp5/trunk/products/ERP5/tests/testDomainTool.py [utf8] Wed Apr  1
> 17:01:12 2009 @@ -376,6 +376,10 @@
>            return -1
>        return 0
>
> +    def sort_key_method(x):
> +      hasCellContent = getattr(x, 'hasCellContent', None)
> +      return bool(hasCellContent and hasCellContent(base_id='path'))
> +
>      get_transaction().commit()
>      self.tic()
>      domain_tool = self.getDomainTool()
> @@ -384,16 +388,24 @@
>                       'variation/%s/blue' %
> self.resource.getRelativeUrl()]) mapped_value =
> domain_tool.generateMappedValue(context,sort_method=sort_method)
> self.assertEquals(mapped_value.getProperty('base_price'),45)
> +    mapped_value =
> domain_tool.generateMappedValue(context,sort_key_method=sort_key_method) + 
>   self.assertEquals(mapped_value.getProperty('base_price'),45)
>      context = self.resource.asContext(
>                       categories=['resource/%s' %
> self.resource.getRelativeUrl(), 'variation/%s/red' %
> self.resource.getRelativeUrl()]) mapped_value =
> domain_tool.generateMappedValue(context,sort_method=sort_method) +   
> self.assertEquals(mapped_value.getProperty('base_price'),26)
> +    mapped_value =
> domain_tool.generateMappedValue(context,sort_key_method=sort_key_method)
> self.assertEquals(mapped_value.getProperty('base_price'),26)
>      # Now check the price
>     
> self.assertEquals(self.resource.getPrice(context=self.resource.asContext(
> categories=['resource/%s' % self.resource.getRelativeUrl(),
> 'variation/%s/blue' % self.resource.getRelativeUrl()]),
> sort_method=sort_method),45)
> +   
> self.assertEquals(self.resource.getPrice(context=self.resource.asContext( +
>                     categories=['resource/%s' %
> self.resource.getRelativeUrl(), +                     'variation/%s/blue' %
> self.resource.getRelativeUrl()]), +                    
> sort_key_method=sort_key_method),45)
>
>    def test_06_SQLQueryDoesNotReturnTooManyPredicates(self, quiet=0,
> run=run_all_test): if not run: return
>
> _______________________________________________
> Erp5-report mailing list
> Erp5-report at erp5.org
> http://mail.nexedi.com/mailman/listinfo/erp5-report



-- 
Yoshinori Okuji, Nexedi KK President
Nexedi: Consulting and Development of Free / Open Source Software
http://www.nexedi.co.jp/
ERP5: Full Featured High End Open Source ERP
http://www.erp5.com/
ERP5 Wiki: Developer Zone for ERP5 Community
http://www.erp5.org/



More information about the Erp5-dev mailing list