libsoup3: update to 3.6.0; fix GTK2/3 app startup
[oi-userland.git] / components / network / avahi / patches / 19-py3-dbm.patch
blob5089e995b88868ca6bbf1d3c7b1c9fb2c3742daf
1 From 63750f1be96ad08c407193b08bf3b9ee74310e2d Mon Sep 17 00:00:00 2001
2 From: "Jan Alexander Steffens (heftig)" <jan.steffens@gmail.com>
3 Date: Tue, 11 Jul 2017 21:52:37 +0200
4 Subject: [PATCH] avahi-python: Use the agnostic DBM interface
6 Also fixes configure failing if Python 3 is the build python and GDBM is
7 enabled, since Py3 only has anydbm under the name of 'dbm'.
9 Not enough to make ServiceTypeDatabase.py compatible with Py3, but it's
10 a start.
11 ---
12 avahi-python/avahi/Makefile.am | 15 +--------
13 avahi-python/avahi/ServiceTypeDatabase.py.in | 33 ++++++++++++++-----
14 configure.ac | 9 +++--
15 service-type-database/.gitignore | 1 -
16 service-type-database/Makefile.am | 18 +++-------
17 .../{build-db.in => build-db} | 13 +++++---
18 6 files changed, 42 insertions(+), 47 deletions(-)
19 rename service-type-database/{build-db.in => build-db} (87%)
21 diff --git a/avahi-python/avahi/Makefile.am b/avahi-python/avahi/Makefile.am
22 index 3eb67d0d..c906b9bf 100644
23 --- a/avahi-python/avahi/Makefile.am
24 +++ b/avahi-python/avahi/Makefile.am
25 @@ -25,29 +25,16 @@ avahidir = $(pythondir)/avahi
27 if HAVE_GDBM
28 nodist_avahi_SCRIPTS = ServiceTypeDatabase.py
30 -ServiceTypeDatabase.py: ServiceTypeDatabase.py.in
31 - $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
32 - -e 's,@DBM\@,gdbm,g' \
33 - -e 's,@FIRST_KEY\@,key = self.db.firstkey(),g' \
34 - -e 's,@CHECK_KEY\@,while key is not None:,g' \
35 - -e 's,@NEXT_KEY\@,key = self.db.nextkey(key),g' \
36 - -e 's,@pkglibdatadir\@,$(pkglibdatadir),g' $< > $@ && \
37 - chmod +x $@
38 endif
40 if HAVE_DBM
41 nodist_avahi_SCRIPTS = ServiceTypeDatabase.py
42 +endif
44 ServiceTypeDatabase.py: ServiceTypeDatabase.py.in
45 $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
46 - -e 's,@DBM\@,dbm,g' \
47 - -e 's,@FIRST_KEY\@,keys = self.db.keys(),g' \
48 - -e 's,@CHECK_KEY\@,for key in keys:,g' \
49 - -e 's,@NEXT_KEY\@,,g' \
50 -e 's,@pkglibdatadir\@,$(pkglibdatadir),g' $< > $@ && \
51 chmod +x $@
52 -endif
54 avahi_PYTHON = $(avahi_SCRIPTS)
56 diff --git a/avahi-python/avahi/ServiceTypeDatabase.py.in b/avahi-python/avahi/ServiceTypeDatabase.py.in
57 index 4ddd6544..d7f9969b 100644
58 --- a/avahi-python/avahi/ServiceTypeDatabase.py.in
59 +++ b/avahi-python/avahi/ServiceTypeDatabase.py.in
60 @@ -17,7 +17,11 @@
61 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
62 # USA.
64 -import @DBM@
65 +try:
66 + import anydbm as dbm
67 +except ImportError:
68 + import dbm
70 import locale
71 import re
73 @@ -28,7 +32,7 @@ class ServiceTypeDatabase:
75 def __init__(self, filename = "@pkglibdatadir@/service-types.db"):
77 - self.db = @DBM@.open(filename, "r")
78 + self.db = dbm.open(filename, "r")
80 l = locale.getlocale(locale.LC_MESSAGES)
82 @@ -90,13 +94,24 @@ class ServiceTypeDatabase:
84 def __iter__(self):
86 - @FIRST_KEY@
87 - @CHECK_KEY@
89 - if re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+', key) and not re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+\[.*\]', key):
90 - yield key
92 - @NEXT_KEY@
93 + def want_key(key):
94 + if not re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+', key):
95 + return False
96 + if re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+\[.*\]', key):
97 + return False
98 + return True
100 + try:
101 + key = self.db.firstkey()
102 + except AttributeError:
103 + for key in self.db.keys():
104 + if want_key(key):
105 + yield key
106 + else:
107 + while key is not None:
108 + if want_key(key):
109 + yield key
110 + key = self.db.nextkey(key)
112 def __len__(self):
114 diff --git a/configure.ac b/configure.ac
115 index 66789718..fbbf7cf3 100644
116 --- a/configure.ac
117 +++ b/configure.ac
118 @@ -824,11 +824,10 @@ if test "x$HAVE_PYTHON" = "xyes" ; then
121 AM_CHECK_PYMOD(socket,,,[AC_MSG_ERROR(Could not find Python module socket)])
122 - if test "x$HAVE_GDBM" = "xyes"; then
123 - AM_CHECK_PYMOD(gdbm,,,[AC_MSG_ERROR(Could not find Python module gdbm)])
124 - fi
125 - if test "x$HAVE_DBM" = "xyes"; then
126 - AM_CHECK_PYMOD(dbm,,,[AC_MSG_ERROR(Could not find Python module dbm)])
127 + if test "x$HAVE_GDBM" = "xyes" || test "x$HAVE_DBM" = "xyes"; then
128 + AM_CHECK_PYMOD(anydbm,,,[
129 + AM_CHECK_PYMOD(dbm,,,[AC_MSG_ERROR(Could not find Python module dbm)])
130 + ])
134 diff --git a/service-type-database/Makefile.am b/service-type-database/Makefile.am
135 index d184fde3..f9fa0825 100644
136 --- a/service-type-database/Makefile.am
137 +++ b/service-type-database/Makefile.am
138 @@ -15,7 +15,7 @@
139 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
140 # USA.
142 -EXTRA_DIST=build-db.in service-types
143 +EXTRA_DIST=service-types
145 pkglibdatadir=$(libdir)/avahi
147 @@ -27,16 +27,11 @@ if HAVE_GDBM
148 noinst_SCRIPTS=build-db
149 pkglibdata_DATA+=service-types.db
151 -build-db: build-db.in
152 - $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
153 - -e 's,@DBM\@,gdbm,g' $< > $@ && \
154 - chmod +x $@
156 -service-types.db: service-types build-db
157 +service-types.db: service-types
158 $(AM_V_GEN)$(PYTHON) build-db $< $@.coming && \
159 mv $@.coming $@
161 -CLEANFILES = service-types.db build-db
162 +CLEANFILES = service-types.db
164 endif
165 if HAVE_DBM
166 @@ -44,11 +39,6 @@ if HAVE_DBM
167 noinst_SCRIPTS=build-db
168 pkglibdata_DATA+=service-types.db.pag service-types.db.dir
170 -build-db: build-db.in
171 - $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
172 - -e 's,@DBM\@,dbm,g' $< > $@ && \
173 - chmod +x $@
175 service-types.db.pag: service-types.db
176 $(AM_V_GEN)mv service-types.db.coming.pag service-types.db.pag
177 service-types.db.dir: service-types.db
178 @@ -57,7 +47,7 @@ service-types.db: service-types build-db
179 $(AM_V_GEN)$(PYTHON) build-db $< $@.coming && \
180 if test -f "$@.coming"; then mv $@.coming $@; fi
182 -CLEANFILES = service-types.db* build-db
183 +CLEANFILES = service-types.db*
185 endif
186 endif
187 diff --git a/service-type-database/build-db.in b/service-type-database/build-db
188 similarity index 87%
189 rename from service-type-database/build-db.in
190 rename to service-type-database/build-db
191 index 4cda4253..78ee892f 100755
192 --- a/service-type-database/build-db.in
193 +++ b/service-type-database/build-db
194 @@ -1,4 +1,4 @@
195 -#!@PYTHON@
196 +#!/usr/bin/env python
197 # -*-python-*-
198 # This file is part of avahi.
200 @@ -17,7 +17,12 @@
201 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
202 # USA.
204 -import @DBM@, sys
205 +try:
206 + import anydbm as dbm
207 +except ImportError:
208 + import dbm
210 +import sys
212 if len(sys.argv) > 1:
213 infn = sys.argv[1]
214 @@ -29,9 +34,9 @@ if len(sys.argv) > 2:
215 else:
216 outfn = infn + ".db"
218 -db = @DBM@.open(outfn, "n")
219 +db = dbm.open(outfn, "n")
221 -for ln in file(infn, "r"):
222 +for ln in open(infn, "r"):
223 ln = ln.strip(" \r\n\t")
225 if ln == "" or ln.startswith("#"):