carygravel / perl2python Goto Github PK
View Code? Open in Web Editor NEWTool to transcribe Perl 5 to Python 3
Tool to transcribe Perl 5 to Python 3
$script = <<'EOS';
eval "use MyPackage";
plan skip_all => "MyPackage required" if $@;
EOS
$expected = <<'EOS';
pytest.importorskip('MyPackage')
EOS
is map_document( $script ), $expected, "conditionally skip more tests";
$script = <<'EOS';
$data =~ s{\\(?:([0-7]{1,3})|(.))} {defined($1) ? chr(oct($1)) : $2}eg;
EOS
$expected = <<'EOS';
import re
def anonymous_01(m):
return chr(oct(m[1])) if m[1] is not None else m[2]
data = re.sub(r"\\(?:([0-7]{1,3})|(.))",anonymous_01,data)
EOS
is map_document( \$script ), $expected, "substitution with expression";
$script = <<'EOS';
for ( @{$array} ) {
s{in}{out}g;
}
EOS
$expected = <<'EOS';
import re
for _ in array :
_ = re.sub("in","out",_)
EOS
is map_document( \$script ), $expected, "regex replace magic variables";
$script = <<'EOS';
package MyObject;
use Glib::Object::Subclass MyObject::, signals => {
'signal_with_float' => {
param_types => ['Glib::Float'],
},
'signal_with_ints' => {
param_types => [ 'Glib::Int', 'Glib::Int' ],
},
},
properties => [
Glib::ParamSpec->scalar('name1', 'Nick1', 'Blurb1', G_PARAM_READWRITE),
Glib::ParamSpec->string('name2','Nick2','Blurb2','default',G_PARAM_READWRITE),
];
EOS
$expected = <<'EOS';
from gi.repository import GObject
class MyObject(GObject.GObject):
__gsignals__ = {
'signal_with_float': (GObject.SIGNAL_RUN_FIRST, None,
(float,)),
'signal_with_ints': (GObject.SIGNAL_RUN_FIRST, None,
(int,int)),
}
foo = GObject.Property(type=str, default='bar')
property_float = GObject.Property(type=float)
def __init__(self):
GObject.GObject.__init__(self)
EOS
is map_document( \$script ), $expected, "subclass GObject";
$script = <<'EOS';
my $output = do { local ( @ARGV, $/ ) = $filename; <> };
EOS
$expected = <<'EOS';
with open($filename, 'r') as fd:
output = fd.read()
EOS
is map_document( \$script ), $expected, "slurp file";
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.