[libsoup] win32/replace.py: Sync with GLib master
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] win32/replace.py: Sync with GLib master
- Date: Thu, 9 Mar 2017 09:19:12 +0000 (UTC)
commit 71fcfce84e43afcf4f3fdd76cba154668bc67131
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Thu Mar 9 16:21:58 2017 +0800
win32/replace.py: Sync with GLib master
This will allow us to refactor how we generate soup-version.h on Visual
Studio builds, as well as generating the .pc files for the package in a
cleanish way.
win32/replace.py | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/win32/replace.py b/win32/replace.py
index dbfb122..0cb269a 100644
--- a/win32/replace.py
+++ b/win32/replace.py
@@ -21,12 +21,19 @@ valid_actions = ['remove-prefix',
'replace-str',
'remove-str']
-def replace(src, dest, instring, outstring):
+def replace_multi(src, dest, replace_items):
with open(src, 'r') as s:
with open(dest, 'w') as d:
for line in s:
- i = line.replace(instring, outstring)
- d.write(i)
+ replace_dict = dict((re.escape(key), value) \
+ for key, value in replace_items.items())
+ replace_pattern = re.compile("|".join(replace_dict.keys()))
+ d.write(replace_pattern.sub(lambda m: \
+ replace_dict[re.escape(m.group(0))], line))
+
+def replace(src, dest, instring, outstring):
+ replace_item = {instring: outstring}
+ replace_multi(src, dest, replace_item)
def check_required_args(args, params):
for param in params:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]