Expand some query-related testcases
[xapian.git] / xapian-bindings / python3 / fixup-swig-py3-wrapper
blobe7d43e565620c6102d40b1ce8f3bfd983e8c7082
1 #!/usr/bin/perl
2 # Copyright (c) 2016 Olly Betts
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to
6 # deal in the Software without restriction, including without limitation the
7 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 # sell copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
22 use strict;
23 use warnings;
25 undef $/;
26 $_ = <>;
28 my ($pos, $find, $replace);
30 s/^(from \. import _xapian\n)(?:.*\n)+? *import __builtin__\n/$1/m or
31 die "Failed to fix up import code";
33 s/\b_swig_property\b/property/g or
34 die "Failed to fix up _swig_property";
36 s/\bnew_instancemethod\(([^(),]+),\s*[^(),]+,\s*[^(),]+\s*\)/_xapian.SWIG_PyInstanceMethod_New($1)/g or
37 die "Failed to fix up new_instancemethod";
39 /\bnew_instancemethod\b/ and
40 die "Failed to fully fix up new_instancemethod";
42 $replace = << '__END__';
43 def _swig_repr(self):
44 strthis = ""
45 if hasattr(self.this, '__repr__'):
46 strthis = "proxy of " + self.this.__repr__()
47 __END__
48 s/^def _swig_repr\(self\):.*?(\n return)/$replace$1/sm or
49 die "Failed to fix up _swig_repr";
51 $replace = << '__END__';
52 from weakref import proxy as weakref_proxy
53 __END__
54 s/^try:\n import weakref.*?\n\n/$replace\n/sm or
55 die "Failed to fix up weakref_proxy";
57 /\b__builtin__\b/ and
58 die "Failed to fully fix up __builtin__";
60 s/^def _swig_setattr\(.*?\n\n/\n/sm or
61 die "Failed to fix up _swig_setattr";
63 $find = << '__END__';
65 def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
66 __END__
67 $replace = << '__END__';
69 def _swig_setattr(self, class_type, name, value):
70 __END__
71 $pos = index($_, $find);
72 $pos >= 0 or die "Failed to fix up _swig_setattr_nondynamic";
73 $_ = substr($_, 0, $pos) . $replace . substr($_, $pos + length($find));
75 $find = << '__END__';
76 if (not static):
77 object.__setattr__(self, name, value)
78 else:
79 raise AttributeError("You cannot add attributes to %s" % self)
80 __END__
81 $replace = << '__END__';
82 object.__setattr__(self, name, value)
83 __END__
84 $pos = index($_, $find);
85 $pos >= 0 or die "Failed to fix up _swig_setattr_nondynamic part 2";
86 $_ = substr($_, 0, $pos) . $replace . substr($_, $pos + length($find));
88 /\b_swig_setattr_nondynamic\b/ and
89 die "Failed to fully fix up _swig_setattr_nondynamic";
91 s/^def _swig_setattr_nondynamic_method\(set\):\n.*?\n\n//sm or
92 die "Failed to fix up _swig_setattr_nondynamic_method";
94 /\b_swig_setattr_nondynamic_method\b/ and
95 die "Failed to fully fix up _swig_setattr_nondynamic_method";
97 print;
99 # Workaround Perl 5.28 -i quirk: