Procházet zdrojové kódy

문단 수정 개선

Surplus_Up (2DU) před 6 roky
rodič
revize
c188ac7a65

+ 2 - 2
app.py

@@ -4,7 +4,7 @@ import re
 for i_data in os.listdir("route"):
     f_src = re.search("(.+)\.py$", i_data)
     if f_src:
-        f_src = f_src.groups()[0]
+        f_src = f_src.group(1)
 
         exec("from route." + f_src + " import *")
 
@@ -56,7 +56,7 @@ while 1:
             for i_data in os.listdir("."):
                 f_src = re.search("(.+)\.db$", i_data)
                 if f_src:
-                    all_src += [f_src.groups()[0]]
+                    all_src += [f_src.group(1)]
 
             if all_src != [] and new_json[0] != 'mysql':
                 print('DB name (data) [' + ', '.join(all_src) + '] : ', end = '')

+ 1 - 1
emergency_tool.py

@@ -50,7 +50,7 @@ while 1:
             for i_data in os.listdir("."):
                 f_src = re.search("(.+)\.db$", i_data)
                 if f_src:
-                    all_src += [f_src.groups()[0]]
+                    all_src += [f_src.group(1)]
 
             if all_src != [] and new_json[0] != 'mysql':
                 print('DB name (data) [' + ', '.join(all_src) + '] : ', end = '')

+ 1 - 1
route/api_user_info.py

@@ -49,7 +49,7 @@ def api_user_info_2(conn, name):
             plus_t += [load_lang('blocked') + '<br>']
 
             match = re.search("^([0-9]{1,3}\.[0-9]{1,3})", name)
-            match = match.groups()[0] if match else '-'
+            match = match.group(1) if match else '-'
             regex_ban = 0
 
             curs.execute(db_change("select login, block, end, why from ban where band = 'regex'"))

+ 31 - 21
route/edit.py

@@ -5,6 +5,8 @@ def edit_2(conn, name):
 
     ip = ip_check()
     section = flask.request.args.get('section', None)
+    if section:
+        section = int(number_check(section))
 
     curs.execute(db_change("select data from data where title = ?"), [name])
     old = curs.fetchall()
@@ -42,7 +44,28 @@ def edit_2(conn, name):
             o_data = old[0][0].replace('\r\n', '\n')
 
             if section:
-                content = o_data.replace(o_content, content)
+                class run_count_section:
+                    def __init__(self, key, change):
+                        self.counter = key
+                        self.change = change
+
+                    def __call__(self, match):
+                        self.counter -= 1
+
+                        if self.counter == 0:
+                            return '\n' + self.change
+                        else:
+                            return '\n' + match[1]
+
+                run_count = run_count_section(section, content)
+
+                o_data = html.escape('\n' + o_data)
+                o_data = re.sub('\n(?P<in>={1,6})', '<br>\g<in>', o_data)
+                o_data = re.sub('<br>((?:(?:(?!<br>).)*\n*)*)', run_count, o_data)
+                o_data = re.sub('^\n', '', o_data)
+                o_data = html.unescape(o_data)
+
+                content = o_data
 
             leng = leng_check(len(o_data), len(content))
         else:
@@ -85,29 +108,16 @@ def edit_2(conn, name):
         conn.commit()
         
         return redirect('/w/' + url_pas(name))
-    else:            
+    else:
         if old:
             if section:
-                section = number_check(section)
-                data = html.escape('\n' + old[0][0].replace('\r\n', '\n') + '\n')
+                data = html.escape('\n' + old[0][0].replace('\r\n', '\n'))
                 
-                i = 1
-                while 1:
-                    if re.search('\n(?P<in>={1,6})', data):
-                        data = re.sub(
-                            '\n(?P<in>={1,6})', 
-                            '<br><' + str(i) + '>\g<in>', 
-                            data,
-                            1
-                        )
-
-                        i += 1
-                    else:
-                        break
-
-                section_data = re.search('<br><' + str(section) + '>((?:(?:(?!<br>).)*\n*)*)', data)
-                if section_data:
-                    data = section_data.groups()[0]
+                data = re.sub('\n(?P<in>={1,6})', '<br>\g<in>', data)
+
+                section_data = re.findall('<br>((?:(?:(?!<br>).)*\n*)*)', data)
+                if len(section_data) >= section:
+                    data = section_data[section - 1]
                 else:
                     return redirect('/edit/' + url_pas(name))
             else:

+ 1 - 1
route/give_acl.py

@@ -16,7 +16,7 @@ def give_acl_2(conn, name):
         if check_data and ip_or_user(ip) != 0:
             return redirect('/login')
 
-        if user_data.groups()[0] != ip_check():
+        if user_data.group(1) != ip_check():
             if admin_check(5) != 1:
                 if check_data:
                     return re_error('/error/3')

+ 1 - 1
route/login_need_email.py

@@ -41,7 +41,7 @@ def login_need_email_2(conn, tool):
             if 'c_id' in flask.session:
                 data = re.search('@([^@]+)$', flask.request.form.get('email', ''))
                 if data:
-                    data = data.groups()[0]
+                    data = data.group(1)
 
                     curs.execute(db_change("select html from html_filter where html = ? and kind = 'email'"), [data])
                     if curs.fetchall():

+ 1 - 1
route/main_image_view.py

@@ -6,7 +6,7 @@ def main_image_view_2(conn, name, app_var):
     if os.path.exists(os.path.join(app_var['path_data_image'], name)):
         return flask.send_from_directory(
             './' + app_var['path_data_image'], name, 
-            mimetype = 'image/' + re.search('\.([^\.]+)$', name).groups()[0]
+            mimetype = 'image/' + re.search('\.([^\.]+)$', name).group(1)
         )
     else:
         return redirect()

+ 1 - 1
route/main_views.py

@@ -16,7 +16,7 @@ def main_views_2(conn, name):
         plus = ''
         rename = name
 
-    mime_type = re.search('\.([^\.]+)$', rename).groups()[0]
+    mime_type = re.search('\.([^\.]+)$', rename).group(1)
     if mime_type:
         if mime_type in ['.jpeg', '.jpg', '.gif', '.png', '.webp', '.JPEG', '.JPG', '.GIF', '.PNG', '.WEBP']:
             mime_type = 'image/' + mime_type

+ 2 - 2
route/tool/func.py

@@ -193,7 +193,7 @@ def update(ver_num, set_data):
         if change_rec and change_rec[0][0] != '':
             new_rec = re.search('data-sitekey="([^"]+)"', change_rec[0][0])
             if new_rec:
-                curs.execute(db_change("update other set data = ? where name = 'recaptcha'"), [new_rec.groups()[0]])
+                curs.execute(db_change("update other set data = ? where name = 'recaptcha'"), [new_rec.group(1)])
             else:
                 curs.execute(db_change("update other set data = '' where name = 'recaptcha'"))
                 curs.execute(db_change("update other set data = '' where name = 'sec_re'"))
@@ -990,7 +990,7 @@ def ban_check(ip = None, tool = None):
 
     band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
     if band:
-        band_it = band.groups()[0]
+        band_it = band.group(1)
     else:
         band_it = '-'
 

+ 30 - 30
route/tool/set_mark/namumark.py

@@ -29,7 +29,7 @@ def link_fix(main_link):
 
     other_link = re.search('[^\\\\]?(#[^#]+)$', main_link)
     if other_link:
-        other_link = other_link.groups()[0]
+        other_link = other_link.group(1)
 
         main_link = re.sub('(#[^#]+)$', '', main_link)
     else:
@@ -173,11 +173,11 @@ def table_start(data):
 
         table = re.search('\n((?:(?:(?:(?:\|\||\|[^|]+\|)+(?:(?:(?!\|\|).\n*)*))+)\|\|(?:\n)?)+)', data)
         if table:
-            table = re.sub('(\|\|)+\n', '||\n', table.groups()[0])
+            table = re.sub('(\|\|)+\n', '||\n', table.group(1))
             
             table_caption = re.search('^\|([^|]+)\|', table)
             if table_caption:
-                table_caption = '<caption>' + table_caption.groups()[0] + '</caption>'
+                table_caption = '<caption>' + table_caption.group(1) + '</caption>'
                 
                 table = re.sub('^\|([^|]+)\|', '||', table)
             else:
@@ -188,7 +188,7 @@ def table_start(data):
             table_cel = re.findall('(\n(?:(?:\|\|)+)|\|\|\n(?:(?:\|\|)+)|(?:(?:\|\|)+))((?:(?:(?!\n|\|\|).)+\n*)+)', table)
             for i in table_cel:
                 cel_plus = re.search('^((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)', i[1])
-                cel_plus = cel_plus.groups()[0] if cel_plus else ''
+                cel_plus = cel_plus.group(1) if cel_plus else ''
                 cel_data = re.sub('^((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)', '', i[1])
 
                 if re.search('^\n', i[0]):
@@ -285,22 +285,22 @@ def middle_parser(data, include_num):
                         middle_search = re.search('^(#(?:[0-9a-f-A-F]{3}){1,2})', middle_data[0])
                         middle_list += ['span']
 
-                        data = middle_re.sub('<span style="color: ' + middle_search.groups()[0] + ';">', data, 1)
+                        data = middle_re.sub('<span style="color: ' + middle_search.group(1) + ';">', data, 1)
                     elif re.search('^(?:#(\w+))', middle_data[0]):
                         middle_search = re.search('^(?:#(\w+))', middle_data[0])
                         middle_list += ['span']
 
-                        data = middle_re.sub('<span style="color: ' + middle_search.groups()[0] + ';">', data, 1)
+                        data = middle_re.sub('<span style="color: ' + middle_search.group(1) + ';">', data, 1)
                     elif re.search('^(?:@((?:[0-9a-f-A-F]{3}){1,2}))', middle_data[0]):
                         middle_search = re.search('^(?:@((?:[0-9a-f-A-F]{3}){1,2}))', middle_data[0])
                         middle_list += ['span']
 
-                        data = middle_re.sub('<span style="background: #' + middle_search.groups()[0] + ';">', data, 1)
+                        data = middle_re.sub('<span style="background: #' + middle_search.group(1) + ';">', data, 1)
                     elif re.search('^(?:@(\w+))', middle_data[0]):
                         middle_search = re.search('^(?:@(\w+))', middle_data[0])
                         middle_list += ['span']
 
-                        data = middle_re.sub('<span style="background: ' + middle_search.groups()[0] + ';">', data, 1)
+                        data = middle_re.sub('<span style="background: ' + middle_search.group(1) + ';">', data, 1)
                     elif re.search('^(\+|-)([1-5])', middle_data[0]):
                         middle_search = re.search('^(\+|-)([1-5])', middle_data[0])
                         middle_search = middle_search.groups()
@@ -502,7 +502,7 @@ def namumark(conn, data, title, include_num):
     while 1:
         math = math_re.search(data)
         if math:
-            math = math.groups()[0]
+            math = math.group(1)
             math = math.replace('{', '<math_mid_1>')
             math = math.replace('}', '<math_mid_2>')
             math = math.replace('\\', '<math_slash>')
@@ -520,7 +520,7 @@ def namumark(conn, data, title, include_num):
     while 1:
         math = math_re.search(data)
         if math:
-            math = math.groups()[0]
+            math = math.group(1)
             math = math.replace('<math_mid_1>', '{')
             math = math.replace('<math_mid_2>', '}')
             math = math.replace('<math_slash>', '\\')
@@ -562,11 +562,11 @@ def namumark(conn, data, title, include_num):
 
         include = include_re.search(data)
         if include:
-            include = include.groups()[0]
+            include = include.group(1)
 
             include_data = re.search('^((?:(?!,).)+)', include)
             if include_data:
-                include_data = include_data.groups()[0]
+                include_data = include_data.group(1)
             else:
                 include_data = 'Test'
 
@@ -635,7 +635,7 @@ def namumark(conn, data, title, include_num):
     redirect_re = re.compile('\n#(?:redirect|넘겨주기) ((?:(?!\n).)+)\n', re.I)
     redirect = redirect_re.search(data)
     if redirect:
-        redirect = redirect.groups()[0]
+        redirect = redirect.group(1)
 
         return_link = link_fix(redirect)
         main_link = html.unescape(return_link[0])
@@ -751,7 +751,7 @@ def namumark(conn, data, title, include_num):
     
     now_time = tool.get_time()
     time_data = re.search('^([0-9]{4}-[0-9]{2}-[0-9]{2})', now_time)
-    time = time_data.groups()[0]
+    time = time_data.group(1)
     
     macro_re = re.compile('\[([^[(]+)\(((?:(?!\)]).)+)\)\]')
     macro_data = macro_re.findall(data)
@@ -760,7 +760,7 @@ def namumark(conn, data, title, include_num):
         if macro_name == 'youtube' or macro_name == 'kakaotv' or macro_name == 'nicovideo':
             width = re.search(', ?width=((?:(?!,).)+)', i[1])
             if width:
-                video_width = width.groups()[0]
+                video_width = width.group(1)
                 if re.search('^[0-9]+$', video_width):
                     video_width += 'px'
             else:
@@ -768,7 +768,7 @@ def namumark(conn, data, title, include_num):
 
             height = re.search(', ?height=((?:(?!,).)+)', i[1])
             if height:
-                video_height = height.groups()[0]
+                video_height = height.group(1)
                 if re.search('^[0-9]+$', video_height):
                     video_height += 'px'
             else:
@@ -776,7 +776,7 @@ def namumark(conn, data, title, include_num):
 
             code = re.search('^((?:(?!,).)+)', i[1])
             if code:
-                video_code = code.groups()[0]
+                video_code = code.group(1)
             else:
                 video_code = ''
 
@@ -785,7 +785,7 @@ def namumark(conn, data, title, include_num):
             if macro_name == 'youtube':
                 start = re.search(', ?(start=(?:(?!,).)+)', i[1])
                 if start:
-                    video_start = '?' + start.groups()[0]
+                    video_start = '?' + start.group(1)
 
                 video_code = re.sub('^https:\/\/www\.youtube\.com\/watch\?v=', '', video_code)
                 video_code = re.sub('^https:\/\/youtu\.be\/', '', video_code)
@@ -809,19 +809,19 @@ def namumark(conn, data, title, include_num):
         elif macro_name == 'ruby':
             ruby_code = re.search('^([^,]+)', i[1])
             if ruby_code:
-                ruby_code = ruby_code.groups()[0]
+                ruby_code = ruby_code.group(1)
             else:
                 ruby_code = 'Test'
 
             ruby_top = re.search('ruby=([^,]+)', i[1], flags = re.I)
             if ruby_top:
-                ruby_top = ruby_top.groups()[0]
+                ruby_top = ruby_top.group(1)
             else:
                 ruby_top = 'Test'
 
             ruby_color = re.search('color=([^,]+)', i[1], flags = re.I)
             if ruby_color:
-                ruby_color = 'color: ' + ruby_color.groups()[0] + ';'
+                ruby_color = 'color: ' + ruby_color.group(1) + ';'
             else:
                 ruby_color = ''
 
@@ -869,7 +869,7 @@ def namumark(conn, data, title, include_num):
     while 1:
         block = re.search('(\n(?:&gt; ?(?:(?:(?!\n).)+)?\n)+)', data)
         if block:
-            block = block.groups()[0]
+            block = block.group(1)
 
             block = re.sub('^\n&gt; ?', '', block)
             block = re.sub('\n&gt; ?', '\n', block)
@@ -892,7 +892,7 @@ def namumark(conn, data, title, include_num):
     while 1:
         li = re.search('(\n(?:(?: *)\* ?(?:(?:(?!\n).)+)\n)+)', data)
         if li:
-            li = li.groups()[0]
+            li = li.group(1)
             while 1:
                 sub_li = re.search('\n(?:( *)\* ?((?:(?!\n).)+))', li)
                 if sub_li:
@@ -917,7 +917,7 @@ def namumark(conn, data, title, include_num):
     while 1:
         indent = re.search('\n( +)', data)
         if indent:
-            indent = len(indent.groups()[0])
+            indent = len(indent.group(1))
 
             margin = '<span style="margin-left: 20px;"></span>' * indent
 
@@ -932,7 +932,7 @@ def namumark(conn, data, title, include_num):
     while 1:
         link = re.search('\[\[((?:(?!\[\[|\]\]|<\/td>).)+)\]\]', data)
         if link:
-            link = link.groups()[0]
+            link = link.group(1)
 
             link_split = re.search('((?:(?!\|).)+)(?:\|((?:(?!\|).)+))', link)
             if link_split:
@@ -949,7 +949,7 @@ def namumark(conn, data, title, include_num):
 
                 file_width = re.search('width=((?:(?!&).)+)', see_link)
                 if file_width:
-                    file_width = file_width.groups()[0]
+                    file_width = file_width.group(1)
                     if re.search('px$', file_width):
                         file_style += 'width: ' + file_width + ';'
                     else:
@@ -957,7 +957,7 @@ def namumark(conn, data, title, include_num):
 
                 file_height = re.search('height=((?:(?!&).)+)', see_link)
                 if file_height:
-                    file_height = file_height.groups()[0]
+                    file_height = file_height.group(1)
                     if re.search('px$', file_height):
                         file_style += 'height: ' + file_height + ';'
                     else:
@@ -965,7 +965,7 @@ def namumark(conn, data, title, include_num):
 
                 file_align = re.search('align=((?:(?!&).)+)', see_link)
                 if file_align:
-                    file_align = file_align.groups()[0]
+                    file_align = file_align.group(1)
                     if file_align == 'center':
                         file_align = 'display: block; text-align: center;'
                     else:
@@ -975,7 +975,7 @@ def namumark(conn, data, title, include_num):
 
                 file_color = re.search('bgcolor=((?:(?!&).)+)', see_link)
                 if file_color:
-                    file_color = 'background: ' + file_color.groups()[0] + '; display: inline-block;'
+                    file_color = 'background: ' + file_color.group(1) + '; display: inline-block;'
                 else:
                     file_color = ''
 
@@ -1078,7 +1078,7 @@ def namumark(conn, data, title, include_num):
                     data = re.sub('\[\[((?:(?!\[\[|\]\]|<\/td>).)+)\]\]', 'Not exist', data, 1)
             elif re.search('^(\/(?:.+))$', main_link):
                 under_title = re.search('^(\/(?:.+))$', main_link)
-                under_title = under_title.groups()[0]
+                under_title = under_title.group(1)
 
                 if see_link != main_link:
                     data = re.sub('\[\[((?:(?!\[\[|\]\]|<\/td>).)+)\]\]', '[[' + title + under_title + '|' + see_link + ']]', data, 1)

+ 5 - 5
route/topic.py

@@ -44,25 +44,25 @@ def topic_2(conn, topic_num):
         match = re.search('^user:([^/]+)', name)
         if match:
             y_check = 0
-            if ip_or_user(match.groups()[0]) == 1:
-                curs.execute(db_change("select ip from history where ip = ? limit 1"), [match.groups()[0]])
+            if ip_or_user(match.group(1)) == 1:
+                curs.execute(db_change("select ip from history where ip = ? limit 1"), [match.group(1)])
                 u_data = curs.fetchall()
                 if u_data:
                     y_check = 1
                 else:
-                    curs.execute(db_change("select ip from topic where ip = ? limit 1"), [match.groups()[0]])
+                    curs.execute(db_change("select ip from topic where ip = ? limit 1"), [match.group(1)])
                     u_data = curs.fetchall()
                     if u_data:
                         y_check = 1
             else:
-                curs.execute(db_change("select id from user where id = ?"), [match.groups()[0]])
+                curs.execute(db_change("select id from user where id = ?"), [match.group(1)])
                 u_data = curs.fetchall()
                 if u_data:
                     y_check = 1
 
             if y_check == 1:
                 curs.execute(db_change('insert into alarm (name, data, date) values (?, ?, ?)'), [
-                    match.groups()[0],
+                    match.group(1),
                     ip + ' | <a href="/thread/' + topic_num + '#' + num + '">' + name + ' | ' + sub + ' | #' + num + '</a>',
                     today
                 ])

+ 2 - 2
route/view_read.py

@@ -36,7 +36,7 @@ def view_read_2(conn, name):
 
     m = re.search("^(.*)\/(.*)$", name)
     if m:
-        uppage = m.groups()[0]
+        uppage = m.group(1)
     else:
         uppage = 0
 
@@ -207,7 +207,7 @@ def view_read_2(conn, name):
 
     match = re.search("^user:([^/]*)", name)
     if match:
-        user_name = match.groups()[0]
+        user_name = match.group(1)
         div = '''
             <div id="get_user_info"></div>
             <script>load_user_info("''' + user_name + '''");</script>

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "master" : {
-        "r_ver" : "v3.1.8-master-15",
+        "r_ver" : "v3.1.8-master-16",
         "c_ver" : "3180200",
         "s_ver" : "8"
     }, "stable" : {