add UnicodeFilter
This commit is contained in:
parent
6e1cdce54d
commit
4680cb8e3d
@ -347,6 +347,21 @@ class Unique(ConditionalFilter):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
class UnicodeFilter(Filter):
|
||||||
|
""" Convert all str elements in the record to Unicode.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, encoding='utf-8', errors='ignore'):
|
||||||
|
super(UnicodeFilter, self).__init__()
|
||||||
|
self._encoding = encoding
|
||||||
|
self._errors = errors
|
||||||
|
|
||||||
|
def process_record(self, record):
|
||||||
|
for key, value in record.iteritems():
|
||||||
|
if isinstance(value, str):
|
||||||
|
record[key] = unicode(value, self._encoding, self._errors)
|
||||||
|
return record
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
## Commonly Used Filters ##
|
## Commonly Used Filters ##
|
||||||
###########################
|
###########################
|
||||||
|
Loading…
Reference in New Issue
Block a user