Exemplo n.º 1
0
def run(argv, input, output):
    options, args = parse_commandline(argv)

    if options.in_place:
        os.rename(options.in_place, options.in_place + '~')
        input = open(options.in_place + '~')
        output = open(options.in_place, 'w')

    # Auto-import. This is not smart.
    all_text = ' '.join([(options.begin or ''), ' '.join(args),
                         (options.end or '')])
    modules = re.findall(r'([\w.]+)+(?=\.\w+)\b', all_text)

    context = Context.from_options(options, modules)
    actions = [Action.from_options(options, arg) for arg in args]
    if not actions:
        actions = [Action.from_options(options, '')]

    try:
        process(context, input, output, options.begin, actions, options.end,
                options.strict)
    finally:
        if options.in_place:
            output.close()
            input.close()
Exemplo n.º 2
0
def benchmark_fields():
    options, _ = parse_commandline([''])
    action = Action(cmd='f')
    context = Context.from_options(options, [])
    t = timeit.Timer(
        lambda: action.apply(context, 'foo bar waz was haz has hair'))
    print t.repeat(repeat=3, number=100000)
Exemplo n.º 3
0
def run(argv, input, output):
    options, args = parse_commandline(argv)

    if options.in_place:
        os.rename(options.in_place, options.in_place + '~')
        input = open(options.in_place + '~')
        output = open(options.in_place, 'w')

    # Auto-import. This is not smart.
    all_text = ' '.join([(options.begin or ''), ' '.join(args), (options.end or '')])
    modules = re.findall(r'([\w.]+)+(?=\.\w+)\b', all_text)

    context = Context.from_options(options, modules)
    actions = [Action.from_options(options, arg) for arg in args]
    if not actions:
        actions = [Action.from_options(options, '')]

    try:
        process(context, input, output, options.begin, actions, options.end, options.strict)
    finally:
        if options.in_place:
            output.close()
            input.close()
Exemplo n.º 4
0
def benchmark_fields():
    options, _ = parse_commandline([''])
    action = Action(cmd='f')
    context = Context.from_options(options, [])
    t = timeit.Timer(lambda: action.apply(context, 'foo bar waz was haz has hair'))
    print t.repeat(repeat=3, number=100000)