Przeglądaj źródła

파일 관련에 re.I 붙임

2DU 9 lat temu
rodzic
commit
1e25de2e10
3 zmienionych plików z 24 dodań i 14 usunięć
  1. 2 1
      app.py
  2. 20 11
      mark.py
  3. 2 2
      views/upload.tpl

+ 2 - 1
app.py

@@ -198,7 +198,8 @@ def upload():
         else:
             file = request.files.file
             if(file):
-                exist = re.search('^(.+)(\.(?:[Jj][Pp][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg]|[Pp][Nn][Gg]))$', file.filename)
+                comp = re.compile("^(.+)(\.(?:jpg|gif|png|jpeg))$", re.I)
+                exist = comp.search(file.filename)
                 if(exist):
                     if((int(set_data['upload']) * 1024 * 1024) < request.content_length):
                         return(redirect('/error/17'))

+ 20 - 11
mark.py

@@ -438,7 +438,8 @@ def namumark(title, data):
             if(c):
                 if(not re.search("^파일:([^\n]*)", title)):
                     backlink_plus(title, '파일:' + c[0], 'file')
-
+                    
+                comp = re.compile("^(.+)(\.(?:jpg|gif|png|jpeg))$", re.I)
                 if(c[1]):
                     n = re.search("width=([^ \n&]*)", c[1])
                     e = re.search("height=([^ \n&]*)", c[1])
@@ -456,17 +457,19 @@ def namumark(title, data):
                         height = ''
                     
                     try:
-                        extension = re.search("^(.+)(\.(?:[Jj][Pp][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg]|[Pp][Nn][Gg]))$", c[0]).groups()
-
-                        img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", extension[1])
+                        extension = comp.search(c[0]).groups()
+                        
+                        comp = re.compile("\.(?P<in>jpg|gif|png|jpeg)", re.I)
+                        img = comp.sub("#\g<in>#", extension[1])
                         data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", '<a href="/w/파일:' + extension[0] + img + '"><img src="/image/' + sha224(extension[0]) + img + '" width="' + width + '" height="' + height + '"></a>', data, 1)
                     except:
                         data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", 'Error', data, 1)
                 else:
                     try:
-                        extension = re.search("^(.+)(\.(?:[Jj][Pp][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg]|[Pp][Nn][Gg]))$", c[0]).groups()
+                        extension = comp.search(c[0]).groups()
                         
-                        img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", extension[1])
+                        comp = re.compile("\.(?P<in>jpg|gif|png|jpeg)", re.I)
+                        img = comp.sub("#\g<in>#", extension[1])
                         data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", "<a href='/w/파일:" + extension[0] + img + "'><img src='/image/" + sha224(extension[0]) + img + "'></a>", data, 1)
                     except:
                         data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", 'Error', data, 1)
@@ -527,10 +530,13 @@ def namumark(title, data):
                 
             b = re.search("^http(?:s)?:\/\/", results[0])
             if(b):
-                c = re.search("(?:\.[Jj][Pp][Gg]|\.[Pp][Nn][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg])", results[0])
+                comp = re.compile("(?:\.(?:jpg|png|gif|jpeg))", re.I)
+                c = comp.search(results[0])
                 if(c):
                     img = results[0]
-                    img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", img)
+                    
+                    comp = re.compile("\.(?P<in>jpg|gif|png|jpeg)", re.I)
+                    img = comp.sub("#\g<in>#", img)
                     
                     data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + img + sharp + '">' + g + '</a>', data, 1)
                 else:
@@ -554,7 +560,7 @@ def namumark(title, data):
             break
             
     while(True):
-        com = re.compile("(http(?:s)?:\/\/(?:(?:(?:(?!\.[Jj][Pp][Gg]|\.[Pp][Nn][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg]|#[Jj][Pp][Gg]#|#[Pp][Nn][Gg]#|#[Gg][Ii][Ff]#|#[Jj][Pp][Ee][Gg]#|<\/(?:[^>]*)>).)*)(?:\.[Jj][Pp][Gg]|\.[Pp][Nn][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg])))(?:(?:(?:\?)width=((?:[0-9]*)(?:px|%)?))?(?:(?:\?|&)height=((?:[0-9]*)(?:px|%)?))?)")
+        com = re.compile("(http(?:s)?:\/\/(?:(?:(?:(?!\.(?:jpg|png|gif|jpeg)|#(?:jpg|png|gif|jpeg)#|<\/(?:[^>]*)>).)*)(?:\.(?:jpg|png|gif|jpeg))))(?:(?:(?:\?)width=((?:[0-9]*)(?:px|%)?))?(?:(?:\?|&)height=((?:[0-9]*)(?:px|%)?))?)", re.I)
         m = com.search(data)
         if(m):
             result = m.groups()
@@ -573,7 +579,9 @@ def namumark(title, data):
                 height = ''
 
             c = result[0]
-            c = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", c)
+            
+            comp = re.compile("\.(?P<in>jpg|gif|png|jpeg)", re.I)
+            c = comp.sub("#\g<in>#", c)
 
             data = com.sub("<img width='" + width + "' height='" + height + "' src='" + c + "'>", data, 1)
         else:
@@ -616,7 +624,8 @@ def namumark(title, data):
                 
         data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(year), data, 1)
     
-    data = re.sub("#(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])#", ".\g<in>", data)
+    comp = re.compile("#(?P<in>jpg|gif|png|jpeg)#", re.I)
+    data = comp.sub(".\g<in>", data)
     data = re.sub("-{4,11}", "<hr>", data)
     
     while(True):

+ 2 - 2
views/upload.tpl

@@ -13,8 +13,8 @@
 </h1>
 <div>
     <form action="" method=post enctype=multipart/form-data>
-        <input type=file name=file>
-        <input type=submit value=Upload>
+        <input class="btn" type="file" name="file">
+        <input class="btn btn-primary" type="submit" value="Upload">
     </form>
 </div>
 <span>{{number}}MB 이하 파일만 업로드 가능하고 확장자는 jpg, png, gif, jpeg만 가능합니다.</span>