[hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
the idea is to make a first pass over all the hooks in the registry and to mark
put some of them in a disabled list. The disabled hooks are the one which:
* are disabled at the session level
* have a match_rtype or an is_instance selector which does not
match the rtype / etype of the relations / entities for
which we are calling the hooks. This works because the
repository calls the hooks grouped by rtype or by etype when
using the entities or eids_to_from keyword arguments
Only hooks with a simple selector or an AndSelector of simple
selectors (is_instance and match_rtype) are considered for disabling.
#!/usr/bin/python
"""usage: fix-po-encodings [filename...]
change the encoding of the po files passed as arguments to utf-8
"""
import sys
import re
import codecs
def change_encoding(filename, target='UTF-8'):
fdesc = open(filename)
data = fdesc.read()
fdesc.close()
encoding = find_encoding(data)
if encoding == target:
return
data = fix_encoding(data, target)
data = unicode(data, encoding)
fdesc = codecs.open(filename, 'wb', encoding=target)
fdesc.write(data)
fdesc.close()
def find_encoding(data):
regexp = re.compile(r'"Content-Type:.* charset=([a-zA-Z0-9-]+)\\n"', re.M)
mo = regexp.search(data)
if mo is None:
raise ValueError('No encoding declaration')
return mo.group(1)
def fix_encoding(data, target_encoding):
regexp = re.compile(r'("Content-Type:.* charset=)(.*)(\\n")', re.M)
return regexp.sub(r'\1%s\3' % target_encoding, data)
for filename in sys.argv[1:]:
print filename
change_encoding(filename)