1
# -*- coding: utf-8 -*-
4
# Copyright (C) 2012 Yahoo! Inc.
6
# Author: Joshua Harlow <harlowja@yahoo-inc.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License version 3, as
10
# published by the Free Software Foundation.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
def __init__(self, _merger, opts):
25
self._append = 'append' in opts
28
return 'StringMerger: (append=%s)' % (self._append)
30
# On encountering a unicode object to merge value with
31
# we will for now just proxy into the string method to let it handle it.
32
def _on_unicode(self, value, merge_with):
33
return self._on_str(value, merge_with)
35
# On encountering a string object to merge with we will
36
# perform the following action, if appending we will
37
# merge them together, otherwise we will just return value.
38
def _on_str(self, value, merge_with):
39
if not isinstance(value, six.string_types):
43
if isinstance(value, six.text_type):
44
return value + six.text_type(merge_with)
46
return value + six.binary_type(merge_with)