We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add "Deep Learning Computation" chapter
- [x] index.md
- [x] model-construction.md
- [x] parameters.md
- [x] deferred-init.md
- [x] custom-layer.md
- [x] read-write.md
- [x] use-gpu.md

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `utils.py`
Content:
```
1 # encoding=utf8
2 import codecs
3 import filecmp
4 import re
5 import sys
6 import argparse
7 
8 BEGIN_BLOCK_COMMENT = '<!--\n'
9 END_BLOCK_COMMENT = '-->\n\n'
10 TRANSLATE_INDICATOR = '*dịch đoạn phía trên*'
11 HEADER_INDICATOR = ' *dịch tiêu đề phía trên*\n'
12 IMAGE_CAPTION_INDICATOR = '*dịch chú thích ảnh phía trên*'
13 START_FILE = '<!-- ===================== Bắt đầu dịch Phần 1 ==================== -->\n'
14 END_FILE = '<!-- ===================== Kết thúc dịch Phần 1 ==================== -->\n'
15 SUFIX_PATH = 'contributors_template_vn.md'
16 
17 # Our special mark in markdown, e.g. :label:`chapter_intro`
18 MARK_RE_MD = re.compile(':([-\/\\._\w\d]+):`([\*-\/\\\._\w\d]+)`')
19 
20 parser = argparse.ArgumentParser(description='Dịch Dive into Deep Learning')
21 parser.add_argument('--convert', type=str, help='path to md file')
22 
23 
24 def is_blank_line(line):
25     return line.strip() == ''
26 
27 
28 class MyLine(object):
29     def __init__(self, line_str, in_code_block):
30         self.line_str = line_str.replace(' -- ', ' \-\- ')
31         self.in_code_block = in_code_block
32         self.end_comment_if_next_line_blank = None
33 
34     def process(self, file_writer, last_line):
35         if self.in_code_block:
36             file_writer.write(self.line_str)
37         else:
38             self._process(file_writer, last_line)
39         return self
40 
41     def _process(self, file_writer, last_line):
42         raise NotImplementedError
43 
44 
45 class NormalLine(MyLine):
46     def __init__(self, line_str, in_code_block):
47         super(NormalLine, self).__init__(line_str, in_code_block)
48         self.end_comment_if_next_line_blank = True
49 
50     def _process(self, file_writer, last_line):
51         if isinstance(last_line, BlankLine):
52             file_writer.write(BEGIN_BLOCK_COMMENT)
53         file_writer.write(self.line_str)
54 
55 
56 class BlankLine(MyLine):
57     def __init__(self, line_str, in_code_block):
58         super(BlankLine, self).__init__(line_str, in_code_block)
59         self.end_comment_if_next_line_blank = False
60 
61     def _process(self, file_writer, last_line):
62         if last_line.end_comment_if_next_line_blank:
63             file_writer.write(END_BLOCK_COMMENT)
64             file_writer.write(TRANSLATE_INDICATOR)
65             file_writer.write('\n')
66         file_writer.write('\n')
67 
68 
69 class HeaderLine(MyLine):
70     def __init__(self, line_str, in_code_block):
71         super(HeaderLine, self).__init__(line_str, in_code_block)
72         self.end_comment_if_next_line_blank = False
73         self.heading = 0
74         cnt = 0
75         for char in self.line_str:
76             if char == '#':
77                 cnt += 1
78             elif char == ' ':
79                 self.heading = cnt
80                 break
81             else:
82                 assert False, self.line_str
83 
84     def _process(self, file_writer, last_line):
85         assert isinstance(last_line, BlankLine),\
86             last_line.line_str
87         file_writer.write(BEGIN_BLOCK_COMMENT)
88         file_writer.write(self.line_str)
89         file_writer.write(END_BLOCK_COMMENT)
90         file_writer.write('#'*self.heading + HEADER_INDICATOR)
91 
92 
93 class ImageLine(MyLine):
94     def __init(self, line_str, in_code_block):
95         assert not in_code_block
96         super(ImageLine, self).__init__(line_str, in_code_block)
97 
98     def _process(self, file_writer, last_line):
99         close_square_bracket_id = self.line_str.index(']')
100         assert self.line_str[close_square_bracket_id+1] == '(', self.line_str
101         # assert self.line_str.endswith(')'), self.line_str
102         file_writer.write(BEGIN_BLOCK_COMMENT)
103         file_writer.write(self.line_str)
104         file_writer.write(END_BLOCK_COMMENT)
105         file_writer.write(
106             '![' + IMAGE_CAPTION_INDICATOR + ']' + self.line_str[close_square_bracket_id+1:]
107         )
108 
109 
110 class CodeMarkerLine(MyLine):
111     def __init__(self, line_str, in_code_block):
112         super(CodeMarkerLine, self).__init__(line_str, in_code_block)
113         self.end_comment_if_next_line_blank = False
114 
115     def _process(self, file_writer, last_line):
116         """ the print is printed in the super class"""
117         file_writer.write(self.line_str)
118 
119 
120 
121 class MathLine(MyLine):
122     def __init__(self, line_str, in_code_block):
123         super(MathLine, self).__init__(line_str, in_code_block)
124         self.end_comment_if_next_line_blank = False
125 
126     def _process(self, file_writer, last_line):
127         file_writer.write(self.line_str)
128         return self
129 
130 
131 class LabelLine(MyLine):
132     def __init__(self, line_str, in_code_block):
133         super(LabelLine, self).__init__(line_str, in_code_block)
134         self.end_comment_if_next_line_blank = False
135 
136     def _process(self, file_writer, last_line):
137         # assert isinstance(last_line, HeaderLine) or isinstance(last_line, ImageLine), 'last line: {}\nthis_line: {}'.format(
138         #         last_line.line_str, self.line_str
139         #     )
140         file_writer.write(self.line_str)
141         # file_writer.write('\n')
142         return self
143 
144 
145 def block_comment(input_md, output_md, add_prefix_suffix=False):
146     last_line = BlankLine('', False)
147     in_code_block = False
148     with codecs.open(input_md, 'r', encoding='utf-8') as input_handle,\
149             codecs.open(output_md, 'w', encoding='utf-8') as output_handle,\
150             codecs.open(SUFIX_PATH, 'r', encoding='utf-8') as surfix_handle:
151         if add_prefix_suffix:
152             output_handle.write(START_FILE)
153             output_handle.write('\n')
154         for line_str in input_handle:
155             line_str = line_str.rstrip() + '\n'
156             line_str = line_str.replace(' -- ', ' \-\- ')
157             match = MARK_RE_MD.match(line_str)
158             if is_blank_line(line_str):
159                 line_type = BlankLine
160             elif line_str.startswith('#'):
161                 line_type = HeaderLine
162             elif line_str.startswith('!['):
163                 line_type = ImageLine
164             elif line_str.startswith('$'):
165                 line_type = MathLine
166             elif line_str.startswith('```'):
167                 in_code_block = not in_code_block
168                 line_type = CodeMarkerLine
169             elif match is not None and match[1] in ['label', 'eqlabel']:
170                 line_type = LabelLine
171             else:
172                 line_type = NormalLine
173 
174             this_line = line_type(line_str, in_code_block)
175             last_line = this_line.process(output_handle, last_line)
176 
177         assert in_code_block is False
178 
179         # TODO: simplify 5 lines below
180         if isinstance(last_line, BlankLine) or isinstance(last_line, LabelLine)\
181                 or isinstance(last_line, CodeMarkerLine) or isinstance(last_line, ImageLine):
182             print('skip')
183         else:
184             output_handle.write(END_BLOCK_COMMENT)
185             output_handle.write(TRANSLATE_INDICATOR)
186         if add_prefix_suffix:
187             output_handle.write('\n')
188             output_handle.write(END_FILE)
189             output_handle.write('\n')
190             for line in surfix_handle:
191                 output_handle.write(line)
192 
193 
194 if __name__ == '__main__':
195     args = parser.parse_args()
196     input_md = args.convert
197     output_md = input_md[:-len('.md')] + '_vn.md'
198     block_comment(input_md, output_md, add_prefix_suffix=True)
199
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/utils.py b/utils.py
--- a/utils.py
+++ b/utils.py
@@ -10,8 +10,8 @@
 TRANSLATE_INDICATOR = '*dịch đoạn phía trên*'
 HEADER_INDICATOR = ' *dịch tiêu đề phía trên*\n'
 IMAGE_CAPTION_INDICATOR = '*dịch chú thích ảnh phía trên*'
-START_FILE = '<!-- ===================== Bắt đầu dịch Phần 1 ==================== -->\n'
-END_FILE = '<!-- ===================== Kết thúc dịch Phần 1 ==================== -->\n'
+START_FILE = '<!-- ===================== Bắt đầu dịch Phần  ==================== -->\n<!-- ========================================= REVISE PHẦN  - BẮT ĐẦU =================================== -->\n'
+END_FILE = '<!-- ===================== Kết thúc dịch Phần  ==================== -->\n<!-- ========================================= REVISE PHẦN  - KẾT THÚC ===================================-->\n'
 SUFIX_PATH = 'contributors_template_vn.md'
 
 # Our special mark in markdown, e.g. :label:`chapter_intro`

{"golden_diff": "diff --git a/utils.py b/utils.py\n--- a/utils.py\n+++ b/utils.py\n@@ -10,8 +10,8 @@\n TRANSLATE_INDICATOR = '*d\u1ecbch \u0111o\u1ea1n ph\u00eda tr\u00ean*'\n HEADER_INDICATOR = ' *d\u1ecbch ti\u00eau \u0111\u1ec1 ph\u00eda tr\u00ean*\\n'\n IMAGE_CAPTION_INDICATOR = '*d\u1ecbch ch\u00fa th\u00edch \u1ea3nh ph\u00eda tr\u00ean*'\n-START_FILE = '<!-- ===================== B\u1eaft \u0111\u1ea7u d\u1ecbch Ph\u1ea7n 1 ==================== -->\\n'\n-END_FILE = '<!-- ===================== K\u1ebft th\u00fac d\u1ecbch Ph\u1ea7n 1 ==================== -->\\n'\n+START_FILE = '<!-- ===================== B\u1eaft \u0111\u1ea7u d\u1ecbch Ph\u1ea7n  ==================== -->\\n<!-- ========================================= REVISE PH\u1ea6N  - B\u1eaeT \u0110\u1ea6U =================================== -->\\n'\n+END_FILE = '<!-- ===================== K\u1ebft th\u00fac d\u1ecbch Ph\u1ea7n  ==================== -->\\n<!-- ========================================= REVISE PH\u1ea6N  - K\u1ebeT TH\u00daC ===================================-->\\n'\n SUFIX_PATH = 'contributors_template_vn.md'\n \n # Our special mark in markdown, e.g. :label:`chapter_intro`\n", "issue": "Add \"Deep Learning Computation\" chapter\n- [x] index.md\r\n- [x] model-construction.md\r\n- [x] parameters.md\r\n- [x] deferred-init.md\r\n- [x] custom-layer.md\r\n- [x] read-write.md\r\n- [x] use-gpu.md\n", "before_files": [{"content": "# encoding=utf8\nimport codecs\nimport filecmp\nimport re\nimport sys\nimport argparse\n\nBEGIN_BLOCK_COMMENT = '<!--\\n'\nEND_BLOCK_COMMENT = '-->\\n\\n'\nTRANSLATE_INDICATOR = '*d\u1ecbch \u0111o\u1ea1n ph\u00eda tr\u00ean*'\nHEADER_INDICATOR = ' *d\u1ecbch ti\u00eau \u0111\u1ec1 ph\u00eda tr\u00ean*\\n'\nIMAGE_CAPTION_INDICATOR = '*d\u1ecbch ch\u00fa th\u00edch \u1ea3nh ph\u00eda tr\u00ean*'\nSTART_FILE = '<!-- ===================== B\u1eaft \u0111\u1ea7u d\u1ecbch Ph\u1ea7n 1 ==================== -->\\n'\nEND_FILE = '<!-- ===================== K\u1ebft th\u00fac d\u1ecbch Ph\u1ea7n 1 ==================== -->\\n'\nSUFIX_PATH = 'contributors_template_vn.md'\n\n# Our special mark in markdown, e.g. :label:`chapter_intro`\nMARK_RE_MD = re.compile(':([-\\/\\\\._\\w\\d]+):`([\\*-\\/\\\\\\._\\w\\d]+)`')\n\nparser = argparse.ArgumentParser(description='D\u1ecbch Dive into Deep Learning')\nparser.add_argument('--convert', type=str, help='path to md file')\n\n\ndef is_blank_line(line):\n    return line.strip() == ''\n\n\nclass MyLine(object):\n    def __init__(self, line_str, in_code_block):\n        self.line_str = line_str.replace(' -- ', ' \\-\\- ')\n        self.in_code_block = in_code_block\n        self.end_comment_if_next_line_blank = None\n\n    def process(self, file_writer, last_line):\n        if self.in_code_block:\n            file_writer.write(self.line_str)\n        else:\n            self._process(file_writer, last_line)\n        return self\n\n    def _process(self, file_writer, last_line):\n        raise NotImplementedError\n\n\nclass NormalLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(NormalLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = True\n\n    def _process(self, file_writer, last_line):\n        if isinstance(last_line, BlankLine):\n            file_writer.write(BEGIN_BLOCK_COMMENT)\n        file_writer.write(self.line_str)\n\n\nclass BlankLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(BlankLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n\n    def _process(self, file_writer, last_line):\n        if last_line.end_comment_if_next_line_blank:\n            file_writer.write(END_BLOCK_COMMENT)\n            file_writer.write(TRANSLATE_INDICATOR)\n            file_writer.write('\\n')\n        file_writer.write('\\n')\n\n\nclass HeaderLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(HeaderLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n        self.heading = 0\n        cnt = 0\n        for char in self.line_str:\n            if char == '#':\n                cnt += 1\n            elif char == ' ':\n                self.heading = cnt\n                break\n            else:\n                assert False, self.line_str\n\n    def _process(self, file_writer, last_line):\n        assert isinstance(last_line, BlankLine),\\\n            last_line.line_str\n        file_writer.write(BEGIN_BLOCK_COMMENT)\n        file_writer.write(self.line_str)\n        file_writer.write(END_BLOCK_COMMENT)\n        file_writer.write('#'*self.heading + HEADER_INDICATOR)\n\n\nclass ImageLine(MyLine):\n    def __init(self, line_str, in_code_block):\n        assert not in_code_block\n        super(ImageLine, self).__init__(line_str, in_code_block)\n\n    def _process(self, file_writer, last_line):\n        close_square_bracket_id = self.line_str.index(']')\n        assert self.line_str[close_square_bracket_id+1] == '(', self.line_str\n        # assert self.line_str.endswith(')'), self.line_str\n        file_writer.write(BEGIN_BLOCK_COMMENT)\n        file_writer.write(self.line_str)\n        file_writer.write(END_BLOCK_COMMENT)\n        file_writer.write(\n            '![' + IMAGE_CAPTION_INDICATOR + ']' + self.line_str[close_square_bracket_id+1:]\n        )\n\n\nclass CodeMarkerLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(CodeMarkerLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n\n    def _process(self, file_writer, last_line):\n        \"\"\" the print is printed in the super class\"\"\"\n        file_writer.write(self.line_str)\n\n\n\nclass MathLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(MathLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n\n    def _process(self, file_writer, last_line):\n        file_writer.write(self.line_str)\n        return self\n\n\nclass LabelLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(LabelLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n\n    def _process(self, file_writer, last_line):\n        # assert isinstance(last_line, HeaderLine) or isinstance(last_line, ImageLine), 'last line: {}\\nthis_line: {}'.format(\n        #         last_line.line_str, self.line_str\n        #     )\n        file_writer.write(self.line_str)\n        # file_writer.write('\\n')\n        return self\n\n\ndef block_comment(input_md, output_md, add_prefix_suffix=False):\n    last_line = BlankLine('', False)\n    in_code_block = False\n    with codecs.open(input_md, 'r', encoding='utf-8') as input_handle,\\\n            codecs.open(output_md, 'w', encoding='utf-8') as output_handle,\\\n            codecs.open(SUFIX_PATH, 'r', encoding='utf-8') as surfix_handle:\n        if add_prefix_suffix:\n            output_handle.write(START_FILE)\n            output_handle.write('\\n')\n        for line_str in input_handle:\n            line_str = line_str.rstrip() + '\\n'\n            line_str = line_str.replace(' -- ', ' \\-\\- ')\n            match = MARK_RE_MD.match(line_str)\n            if is_blank_line(line_str):\n                line_type = BlankLine\n            elif line_str.startswith('#'):\n                line_type = HeaderLine\n            elif line_str.startswith('!['):\n                line_type = ImageLine\n            elif line_str.startswith('$'):\n                line_type = MathLine\n            elif line_str.startswith('```'):\n                in_code_block = not in_code_block\n                line_type = CodeMarkerLine\n            elif match is not None and match[1] in ['label', 'eqlabel']:\n                line_type = LabelLine\n            else:\n                line_type = NormalLine\n\n            this_line = line_type(line_str, in_code_block)\n            last_line = this_line.process(output_handle, last_line)\n\n        assert in_code_block is False\n\n        # TODO: simplify 5 lines below\n        if isinstance(last_line, BlankLine) or isinstance(last_line, LabelLine)\\\n                or isinstance(last_line, CodeMarkerLine) or isinstance(last_line, ImageLine):\n            print('skip')\n        else:\n            output_handle.write(END_BLOCK_COMMENT)\n            output_handle.write(TRANSLATE_INDICATOR)\n        if add_prefix_suffix:\n            output_handle.write('\\n')\n            output_handle.write(END_FILE)\n            output_handle.write('\\n')\n            for line in surfix_handle:\n                output_handle.write(line)\n\n\nif __name__ == '__main__':\n    args = parser.parse_args()\n    input_md = args.convert\n    output_md = input_md[:-len('.md')] + '_vn.md'\n    block_comment(input_md, output_md, add_prefix_suffix=True)\n", "path": "utils.py"}], "after_files": [{"content": "# encoding=utf8\nimport codecs\nimport filecmp\nimport re\nimport sys\nimport argparse\n\nBEGIN_BLOCK_COMMENT = '<!--\\n'\nEND_BLOCK_COMMENT = '-->\\n\\n'\nTRANSLATE_INDICATOR = '*d\u1ecbch \u0111o\u1ea1n ph\u00eda tr\u00ean*'\nHEADER_INDICATOR = ' *d\u1ecbch ti\u00eau \u0111\u1ec1 ph\u00eda tr\u00ean*\\n'\nIMAGE_CAPTION_INDICATOR = '*d\u1ecbch ch\u00fa th\u00edch \u1ea3nh ph\u00eda tr\u00ean*'\nSTART_FILE = '<!-- ===================== B\u1eaft \u0111\u1ea7u d\u1ecbch Ph\u1ea7n  ==================== -->\\n<!-- ========================================= REVISE PH\u1ea6N  - B\u1eaeT \u0110\u1ea6U =================================== -->\\n'\nEND_FILE = '<!-- ===================== K\u1ebft th\u00fac d\u1ecbch Ph\u1ea7n  ==================== -->\\n<!-- ========================================= REVISE PH\u1ea6N  - K\u1ebeT TH\u00daC ===================================-->\\n'\nSUFIX_PATH = 'contributors_template_vn.md'\n\n# Our special mark in markdown, e.g. :label:`chapter_intro`\nMARK_RE_MD = re.compile(':([-\\/\\\\._\\w\\d]+):`([\\*-\\/\\\\\\._\\w\\d]+)`')\n\nparser = argparse.ArgumentParser(description='D\u1ecbch Dive into Deep Learning')\nparser.add_argument('--convert', type=str, help='path to md file')\n\n\ndef is_blank_line(line):\n    return line.strip() == ''\n\n\nclass MyLine(object):\n    def __init__(self, line_str, in_code_block):\n        self.line_str = line_str.replace(' -- ', ' \\-\\- ')\n        self.in_code_block = in_code_block\n        self.end_comment_if_next_line_blank = None\n\n    def process(self, file_writer, last_line):\n        if self.in_code_block:\n            file_writer.write(self.line_str)\n        else:\n            self._process(file_writer, last_line)\n        return self\n\n    def _process(self, file_writer, last_line):\n        raise NotImplementedError\n\n\nclass NormalLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(NormalLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = True\n\n    def _process(self, file_writer, last_line):\n        if isinstance(last_line, BlankLine):\n            file_writer.write(BEGIN_BLOCK_COMMENT)\n        file_writer.write(self.line_str)\n\n\nclass BlankLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(BlankLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n\n    def _process(self, file_writer, last_line):\n        if last_line.end_comment_if_next_line_blank:\n            file_writer.write(END_BLOCK_COMMENT)\n            file_writer.write(TRANSLATE_INDICATOR)\n            file_writer.write('\\n')\n        file_writer.write('\\n')\n\n\nclass HeaderLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(HeaderLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n        self.heading = 0\n        cnt = 0\n        for char in self.line_str:\n            if char == '#':\n                cnt += 1\n            elif char == ' ':\n                self.heading = cnt\n                break\n            else:\n                assert False, self.line_str\n\n    def _process(self, file_writer, last_line):\n        assert isinstance(last_line, BlankLine),\\\n            last_line.line_str\n        file_writer.write(BEGIN_BLOCK_COMMENT)\n        file_writer.write(self.line_str)\n        file_writer.write(END_BLOCK_COMMENT)\n        file_writer.write('#'*self.heading + HEADER_INDICATOR)\n\n\nclass ImageLine(MyLine):\n    def __init(self, line_str, in_code_block):\n        assert not in_code_block\n        super(ImageLine, self).__init__(line_str, in_code_block)\n\n    def _process(self, file_writer, last_line):\n        close_square_bracket_id = self.line_str.index(']')\n        assert self.line_str[close_square_bracket_id+1] == '(', self.line_str\n        # assert self.line_str.endswith(')'), self.line_str\n        file_writer.write(BEGIN_BLOCK_COMMENT)\n        file_writer.write(self.line_str)\n        file_writer.write(END_BLOCK_COMMENT)\n        file_writer.write(\n            '![' + IMAGE_CAPTION_INDICATOR + ']' + self.line_str[close_square_bracket_id+1:]\n        )\n\n\nclass CodeMarkerLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(CodeMarkerLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n\n    def _process(self, file_writer, last_line):\n        \"\"\" the print is printed in the super class\"\"\"\n        file_writer.write(self.line_str)\n\n\n\nclass MathLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(MathLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n\n    def _process(self, file_writer, last_line):\n        file_writer.write(self.line_str)\n        return self\n\n\nclass LabelLine(MyLine):\n    def __init__(self, line_str, in_code_block):\n        super(LabelLine, self).__init__(line_str, in_code_block)\n        self.end_comment_if_next_line_blank = False\n\n    def _process(self, file_writer, last_line):\n        # assert isinstance(last_line, HeaderLine) or isinstance(last_line, ImageLine), 'last line: {}\\nthis_line: {}'.format(\n        #         last_line.line_str, self.line_str\n        #     )\n        file_writer.write(self.line_str)\n        # file_writer.write('\\n')\n        return self\n\n\ndef block_comment(input_md, output_md, add_prefix_suffix=False):\n    last_line = BlankLine('', False)\n    in_code_block = False\n    with codecs.open(input_md, 'r', encoding='utf-8') as input_handle,\\\n            codecs.open(output_md, 'w', encoding='utf-8') as output_handle,\\\n            codecs.open(SUFIX_PATH, 'r', encoding='utf-8') as surfix_handle:\n        if add_prefix_suffix:\n            output_handle.write(START_FILE)\n            output_handle.write('\\n')\n        for line_str in input_handle:\n            line_str = line_str.rstrip() + '\\n'\n            line_str = line_str.replace(' -- ', ' \\-\\- ')\n            match = MARK_RE_MD.match(line_str)\n            if is_blank_line(line_str):\n                line_type = BlankLine\n            elif line_str.startswith('#'):\n                line_type = HeaderLine\n            elif line_str.startswith('!['):\n                line_type = ImageLine\n            elif line_str.startswith('$'):\n                line_type = MathLine\n            elif line_str.startswith('```'):\n                in_code_block = not in_code_block\n                line_type = CodeMarkerLine\n            elif match is not None and match[1] in ['label', 'eqlabel']:\n                line_type = LabelLine\n            else:\n                line_type = NormalLine\n\n            this_line = line_type(line_str, in_code_block)\n            last_line = this_line.process(output_handle, last_line)\n\n        assert in_code_block is False\n\n        # TODO: simplify 5 lines below\n        if isinstance(last_line, BlankLine) or isinstance(last_line, LabelLine)\\\n                or isinstance(last_line, CodeMarkerLine) or isinstance(last_line, ImageLine):\n            print('skip')\n        else:\n            output_handle.write(END_BLOCK_COMMENT)\n            output_handle.write(TRANSLATE_INDICATOR)\n        if add_prefix_suffix:\n            output_handle.write('\\n')\n            output_handle.write(END_FILE)\n            output_handle.write('\\n')\n            for line in surfix_handle:\n                output_handle.write(line)\n\n\nif __name__ == '__main__':\n    args = parser.parse_args()\n    input_md = args.convert\n    output_md = input_md[:-len('.md')] + '_vn.md'\n    block_comment(input_md, output_md, add_prefix_suffix=True)\n", "path": "utils.py"}]}