Giter Club home page Giter Club logo

perl2python's People

Contributors

carygravel avatar

Watchers

 avatar  avatar

perl2python's Issues

substitution magic

$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";

substitution with expression

$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";

Slurp

$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";

eval "use MyPackage" + plan skip_all

$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";

Subclass GObject

$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";

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.