Optimise diversification by implementing C2-GLS
[xapian.git] / xapian-bindings / python / fixup-swig-py2-wrapper
blob97f086c6f5b6d95fdf16e9575b3e04739df6fc99
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 # Specify the encoding of the source file - see:
31 # https://www.python.org/dev/peps/pep-0263/
32 s/^/# encoding: utf-8\n/;
34 s/^try:\n _swig_property =(?:.*\n)+? *import __builtin__\n//m or
35 die "Failed to fix up import code";
37 s/\b_swig_property\b/property/g or
38 die "Failed to fix up _swig_property";
40 $replace = << '__END__';
41 def _swig_repr(self):
42 strthis = ""
43 if hasattr(self.this, '__repr__'):
44 strthis = "proxy of " + self.this.__repr__()
45 __END__
46 s/^def _swig_repr\(self\):.*?(\n return)/$replace$1/sm or
47 die "Failed to fix up _swig_repr";
49 $replace = << '__END__';
50 from weakref import proxy as weakref_proxy
51 __END__
52 s/^try:\n import weakref.*?\n\n/$replace\n/sm or
53 die "Failed to fix up weakref_proxy";
55 /\b__builtin__\b/ and
56 die "Failed to fully fix up __builtin__";
58 s/^def _swig_setattr\(.*?\n\n/\n/sm or
59 die "Failed to fix up _swig_setattr";
61 $find = << '__END__';
63 def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
64 __END__
65 $replace = << '__END__';
67 def _swig_setattr(self, class_type, name, value):
68 __END__
69 $pos = index($_, $find);
70 $pos >= 0 or die "Failed to fix up _swig_setattr_nondynamic";
71 $_ = substr($_, 0, $pos) . $replace . substr($_, $pos + length($find));
73 $find = << '__END__';
74 if (not static):
75 object.__setattr__(self, name, value)
76 else:
77 raise AttributeError("You cannot add attributes to %s" % self)
78 __END__
79 $replace = << '__END__';
80 object.__setattr__(self, name, value)
81 __END__
82 $pos = index($_, $find);
83 $pos >= 0 or die "Failed to fix up _swig_setattr_nondynamic part 2";
84 $_ = substr($_, 0, $pos) . $replace . substr($_, $pos + length($find));
86 /\b_swig_setattr_nondynamic\b/ and
87 die "Failed to fully fix up _swig_setattr_nondynamic";
89 s/^def _swig_setattr_nondynamic_method\(set\):\n.*?\n\n//sm or
90 die "Failed to fix up _swig_setattr_nondynamic_method";
92 /\b_swig_setattr_nondynamic_method\b/ and
93 die "Failed to fully fix up _swig_setattr_nondynamic_method";
95 print;