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
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__';
43 if hasattr
(self
.this
, '__repr__'):
44 strthis
= "proxy of " + self
.this
.__repr__
()
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
52 s/^try:\n import weakref.*?\n\n/$replace\n/sm or
53 die "Failed to fix up weakref_proxy";
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";
63 def _swig_setattr_nondynamic
(self
, class_type
, name
, value
, static
=1):
65 $replace = << '__END__';
67 def _swig_setattr
(self
, class_type
, name
, value
):
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));
75 object
.__setattr__
(self
, name
, value
)
77 raise AttributeError
("You cannot add attributes to %s" % self
)
79 $replace = << '__END__';
80 object
.__setattr__
(self
, name
, value
)
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";