comparison curlyq @ 10:397c178c5b98

Make it array-based.
author David Barts <n5jrn@me.com>
date Fri, 27 Dec 2019 11:26:00 -0800
parents 05363e803272
children a771878f6cf4
comparison
equal deleted inserted replaced
9:84adbbb69a9d 10:397c178c5b98
4 import os, sys 4 import os, sys
5 import argparse 5 import argparse
6 import codecs 6 import codecs
7 7
8 from curlers import TextCurler, HtmlCurler, uncurl 8 from curlers import TextCurler, HtmlCurler, uncurl
9 from workspace import Workspace 9 from runes import Workspace
10 from writer import CODECS_TO_NAME 10 from writer import CODECS_TO_NAME
11 11
12 # V a r i a b l e s 12 # V a r i a b l e s
13 13
14 # Name invoked by 14 # Name invoked by
20 20
21 # F u n c t i o n s 21 # F u n c t i o n s
22 22
23 def normal(): 23 def normal():
24 global input_fp, output_fp, args 24 global input_fp, output_fp, args
25 with Workspace() as ws: 25 ws = Workspace()
26 curler = TextCurler(ws) 26 curler = TextCurler(ws)
27 while True: 27 while True:
28 line = input_fp.readline() 28 line = input_fp.readline()
29 ws.write(line) 29 ws.append(line)
30 if line == "" or line == "\n": 30 if line == "" or line == "\n":
31 if args.force: uncurl(ws) 31 if args.force: uncurl(ws)
32 curler.feed() 32 curler.feed()
33 output_fp.write(ws.getvalue()) 33 output_fp.write(str(ws))
34 ws.clear() 34 ws.clear()
35 if line == "": 35 if line == "":
36 break 36 break
37 37
38 def flowed(): 38 def flowed():
39 global input_fp, output_fp, args 39 global input_fp, output_fp, args
40 with Workspace() as ws: 40 ws = Workspace()
41 curler = TextCurler(ws) 41 curler = TextCurler(ws)
42 while True: 42 while True:
43 line = input_fp.readline() 43 line = input_fp.readline()
44 if line == "": 44 if line == "":
45 break 45 break
46 ws.write(line) 46 ws.append(line)
47 if args.force: uncurl(ws) 47 if args.force: uncurl(ws)
48 curler.feed() 48 curler.feed()
49 output_fp.write(ws.getvalue()) 49 output_fp.write(str(ws))
50 ws.clear() 50 ws.clear()
51 51
52 def html(): 52 def html():
53 global input_fp, output_fp 53 global input_fp, output_fp
54 with Workspace(input_fp.read()) as ws: 54 ws = Workspace(input_fp.read())
55 curler = HtmlCurler(ws) 55 curler = HtmlCurler(ws)
56 if args.force: uncurl(ws) 56 if args.force: uncurl(ws)
57 curler.feed() 57 curler.feed()
58 output_fp.write(ws.getvalue()) 58 output_fp.write(str(ws))
59 59
60 def do_uncurl(): 60 def do_uncurl():
61 global input_fp, output_fp 61 global input_fp, output_fp
62 with Workspace(input_fp.read()) as ws: 62 ws = Workspace(input_fp.read())
63 uncurl(ws) 63 uncurl(ws)
64 output_fp.write(ws.getvalue()) 64 output_fp.write(str(ws))
65 65
66 # M a i n P r o g r a m 66 # M a i n P r o g r a m
67 67
68 # Parse arguments 68 # Parse arguments
69 parser = argparse.ArgumentParser( 69 parser = argparse.ArgumentParser(