mark.py 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. from bottle import request, app
  2. from bottle.ext import beaker
  3. from urllib import parse
  4. import json
  5. import sqlite3
  6. import time
  7. import re
  8. import hashlib
  9. import html
  10. import datetime
  11. json_data = open('set.json').read()
  12. set_data = json.loads(json_data)
  13. conn = sqlite3.connect(set_data['db'] + '.db')
  14. curs = conn.cursor()
  15. session_opts = {
  16. 'session.type': 'file',
  17. 'session.data_dir': './app_session/',
  18. 'session.auto': 1
  19. }
  20. app = beaker.middleware.SessionMiddleware(app(), session_opts)
  21. def get_time():
  22. now = time.localtime()
  23. date = "%04d-%02d-%02d %02d:%02d:%02d" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
  24. return(date)
  25. def ip_check():
  26. session = request.environ.get('beaker.session')
  27. if(session.get('Now') == 1):
  28. ip = format(session['DREAMER'])
  29. else:
  30. if(request.environ.get('HTTP_X_FORWARDED_FOR')):
  31. ip = request.environ.get('HTTP_X_FORWARDED_FOR')
  32. else:
  33. ip = request.environ.get('REMOTE_ADDR')
  34. return(ip)
  35. def url_pas(data):
  36. return(parse.quote(data).replace('/','%2F'))
  37. def sha224(data):
  38. return(hashlib.sha224(bytes(data, 'utf-8')).hexdigest())
  39. def savemark(data):
  40. data = re.sub("\[date\(now\)\]", get_time(), data)
  41. if(not re.search("\.", ip_check())):
  42. name = '[[사용자:' + ip_check() + '|' + ip_check() + ']]'
  43. else:
  44. name = ip_check()
  45. data = re.sub("\[name\]", name, data)
  46. return(data)
  47. def send_p(d):
  48. d = html.escape(d)
  49. js_p = re.compile('javascript:', re.I)
  50. d = js_p.sub('', d)
  51. d = re.sub('&lt;a href="(?:[^"]*)"&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="' + url_pas('\g<in>') + '">\g<in></a>', d)
  52. return(d)
  53. def table_p(d, d2):
  54. alltable = 'style="'
  55. celstyle = 'style="'
  56. rowstyle = 'style="'
  57. row = ''
  58. cel = ''
  59. table_w = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", d)
  60. table_h = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", d)
  61. table_a = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", d)
  62. if(table_w):
  63. alltable += 'width: ' + table_w.groups()[0] + ';'
  64. if(table_h):
  65. alltable += 'height: ' + table_h.groups()[0] + ';'
  66. if(table_a):
  67. if(table_a.groups()[0] == 'right'):
  68. alltable += 'float: right;'
  69. elif(table_a.groups()[0] == 'center'):
  70. alltable += 'margin: auto;'
  71. table_t_a = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", d)
  72. if(table_t_a):
  73. if(table_t_a.groups()[0] == 'right'):
  74. alltable += 'text-align: right;'
  75. elif(table_t_a.groups()[0] == 'center'):
  76. alltable += 'text-align: center;'
  77. row_t_a = re.search("&lt;row\s?textalign=((?:(?!&gt;).)*)&gt;", d)
  78. if(row_t_a):
  79. if(row_t_a.groups()[0] == 'right'):
  80. rowstyle += 'text-align: right;'
  81. elif(row_t_a.groups()[0] == 'center'):
  82. rowstyle += 'text-align: center;'
  83. else:
  84. rowstyle += 'text-align: left;'
  85. table_cel = re.search("&lt;-((?:(?!&gt;).)*)&gt;", d)
  86. if(table_cel):
  87. cel = 'colspan="' + table_cel.groups()[0] + '"'
  88. else:
  89. cel = 'colspan="' + str(round(len(d2) / 2)) + '"'
  90. table_row = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", d)
  91. if(table_row):
  92. row = 'rowspan="' + table_row.groups()[0] + '"'
  93. row_bgcolor_2 = re.search("&lt;rowbgcolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  94. row_bgcolor_3 = re.search("&lt;rowbgcolor=(\w+)&gt;", d)
  95. if(row_bgcolor_2):
  96. rowstyle += 'background: ' + row_bgcolor_2.groups()[0] + ';'
  97. elif(row_bgcolor_3):
  98. rowstyle += 'background: ' + row_bgcolor_3.groups()[0] + ';'
  99. table_border_2 = re.search("&lt;table\s?bordercolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  100. table_border_3 = re.search("&lt;table\s?bordercolor=(\w+)&gt;", d)
  101. if(table_border_2):
  102. alltable += 'border: ' + table_border_2.groups()[0] + ' 2px solid;'
  103. elif(table_border_3):
  104. alltable += 'border: ' + table_border_3.groups()[0] + ' 2px solid;'
  105. table_bgcolor_2 = re.search("&lt;table\s?bgcolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  106. table_bgcolor_3 = re.search("&lt;table\s?bgcolor=(\w+)&gt;", d)
  107. if(table_bgcolor_2):
  108. alltable += 'background: ' + table_bgcolor_2.groups()[0] + ';'
  109. elif(table_bgcolor_3):
  110. alltable += 'background: ' + table_bgcolor_3.groups()[0] + ';'
  111. bgcolor_2 = re.search("&lt;bgcolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  112. bgcolor_3 = re.search("&lt;bgcolor=(\w+)&gt;", d)
  113. if(bgcolor_2):
  114. celstyle += 'background: ' + bgcolor_2.groups()[0] + ';'
  115. elif(bgcolor_3):
  116. celstyle += 'background: ' + bgcolor_3.groups()[0] + ';'
  117. st_bgcolor_2 = re.search("&lt;(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  118. st_bgcolor_3 = re.search("&lt;(\w+)&gt;", d)
  119. if(st_bgcolor_2):
  120. celstyle += 'background: ' + st_bgcolor_2.groups()[0] + ';'
  121. elif(st_bgcolor_3):
  122. celstyle += 'background: ' + st_bgcolor_3.groups()[0] + ';'
  123. n_width = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", d)
  124. n_height = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", d)
  125. if(n_width):
  126. celstyle += 'width: ' + n_width.groups()[0] + ';'
  127. if(n_height):
  128. celstyle += 'height: ' + n_height.groups()[0] + ';'
  129. text_right = re.search("&lt;\)&gt;", d)
  130. text_center = re.search("&lt;:&gt;", d)
  131. text_left = re.search("&lt;\(&gt;", d)
  132. if(text_right):
  133. celstyle += 'text-align: right;'
  134. elif(text_center):
  135. celstyle += 'text-align: center;'
  136. elif(text_left):
  137. celstyle += 'text-align: left;'
  138. alltable += '"'
  139. celstyle += '"'
  140. rowstyle += '"'
  141. return([alltable, rowstyle, celstyle, row, cel])
  142. def html_pas(data):
  143. data = re.sub('%H%', '<', data)
  144. data = re.sub('%\/H%', '>', data)
  145. d_list = re.findall('<(\/)?([^> ]+)( (?:[^>]+)?)?>', data)
  146. for i_list in d_list:
  147. if(i_list[0] == ''):
  148. if(i_list[1] in ['div', 'span', 'embed', 'iframe']):
  149. if(re.search('<\/' + i_list[1] + '>', data)):
  150. src = re.search('src=([^ ]*)', i_list[2])
  151. if(src):
  152. v_src = re.search('https:\/\/([^/\'" ]*)', src.groups()[0])
  153. if(v_src):
  154. if(not v_src.groups()[0] in ["www.youtube.com", "serviceapi.nmv.naver.com", "tv.kakao.com", "www.google.com"]):
  155. ot = re.sub('src=([^ ]*)', '', i_list[2])
  156. else:
  157. ot = i_list[2]
  158. else:
  159. ot = re.sub('src=([^ ]*)', '', i_list[2])
  160. else:
  161. ot = i_list[2]
  162. po = re.compile('position', re.I)
  163. data = re.sub('<(\/)?([^> ]+)( (?:[^>]+)?)?>', '%H%' + i_list[1] + po.sub('', ot) + '%/H%', data, 1)
  164. data = re.sub('<\/' + i_list[1] + '>', '%H%/' + i_list[1] + '%/H%', data, 1)
  165. data = html.escape(data)
  166. end = re.findall('%H%((?:(?!%/H%).)*)%/H%', data)
  167. for d_end in end:
  168. data = re.sub('%H%((?:(?!%/H%).)*)%/H%', '<' + re.sub('&quot;', '"', re.sub('&#x27;', "'", d_end)) + '>', data, 1)
  169. return(data)
  170. def mid_pas(data, fol_num, include, in_c):
  171. com = re.compile("{{{((?:(?!{{{|}}}).)*)}}}", re.DOTALL)
  172. while(1):
  173. is_it = com.search(data)
  174. if(is_it):
  175. it_d = is_it.groups()[0]
  176. big_a = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
  177. big = big_a.search(it_d)
  178. small_a = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
  179. small = small_a.search(it_d)
  180. color_b = re.compile("^(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))\s(.*)$", re.DOTALL)
  181. color_2 = color_b.search(it_d)
  182. color_c = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
  183. color_3 = color_c.search(it_d)
  184. back_a = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  185. back = back_a.search(it_d)
  186. back_b = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  187. back_2 = back_b.search(it_d)
  188. back_c = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
  189. back_3 = back_c.search(it_d)
  190. include_out_a = re.compile("^#!noin\s(.*)$", re.DOTALL)
  191. include_out = include_out_a.search(it_d)
  192. div_a = re.compile("^#!wiki\sstyle=(?:&quot;|&#x27;)((?:(?!&quot;|&#x27;).)*)(?:&quot;|&#x27;)\r\n(.*)$", re.DOTALL)
  193. div = div_a.search(it_d)
  194. html_a = re.compile("^#!html\s(.*)$", re.DOTALL)
  195. html = html_a.search(it_d)
  196. fol_a = re.compile("^#!folding\s((?:(?!\n).)*)\n?\s\n(.*)$", re.DOTALL)
  197. fol = fol_a.search(it_d)
  198. syn_a = re.compile("^#!syntax\s([^\n]*)\r\n(.*)$", re.DOTALL)
  199. syn = syn_a.search(it_d)
  200. if(big):
  201. big_d = big.groups()
  202. data = com.sub('<span style="font-size: ' + str(int(big_d[0]) * 20 + 100) + '%;">' + big_d[1] + '</span>', data, 1)
  203. elif(small):
  204. sm_d = small.groups()
  205. data = com.sub('<span style="font-size: ' + str(100 - int(sm_d[0]) * 10) + '%;">' + sm_d[1] + '</span>', data, 1)
  206. elif(color_2):
  207. c_d_2 = color_2.groups()
  208. data = com.sub('<span style="color: ' + c_d_2[0] + '">' + c_d_2[1] + '</span>', data, 1)
  209. elif(color_3):
  210. c_d_3 = color_3.groups()
  211. data = com.sub('<span style="color: ' + c_d_3[0] + '">' + c_d_3[1] + '</span>', data, 1)
  212. elif(back):
  213. back_d_1 = back.groups()
  214. data = com.sub('<span style="background: #' + back_d_1[0] + '">' + back_d_1[1] + '</span>', data, 1)
  215. elif(back_2):
  216. back_d_2 = back_2.groups()
  217. data = com.sub('<span style="background: #' + back_d_2[0] + '">' + back_d_2[1] + '</span>', data, 1)
  218. elif(back_3):
  219. back_d_3 = back_3.groups()
  220. data = com.sub('<span style="background: ' + back_d_3[0] + '">' + back_d_3[1] + '</span>', data, 1)
  221. elif(div):
  222. div_d = div.groups()
  223. data = com.sub('<div style="' + div_d[0] + '">' + div_d[1] + '</div>', data, 1)
  224. elif(html):
  225. data = com.sub(html.groups()[0], data, 1)
  226. elif(fol):
  227. fol_d = fol.groups()
  228. data = com.sub( "<div> \
  229. " + fol_d[0] + " \
  230. <div id='folding_" + str(fol_num + 1) + "' style='display: inline-block;'> \
  231. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>펼치기</a>] \
  232. </div> \
  233. <div id='folding_" + str(fol_num + 2) + "' style='display: none;'> \
  234. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>접기</a>] \
  235. </div> \
  236. <div id='folding_" + str(fol_num) + "' style='display: none;'> \
  237. <br> \
  238. " + fol_d[1] + " \
  239. </div> \
  240. </div>", data, 1)
  241. fol_num += 3
  242. elif(syn):
  243. syn_d = syn.groups()
  244. data = com.sub('<pre id="syntax"><code class="' + syn_d[0] + '">' + re.sub('\r\n', '<isbr>', re.sub(' ', '<space>', syn_d[1])) + '</code></pre>', data, 1)
  245. elif(include_out):
  246. if((include or in_c) == 1):
  247. data = com.sub("", data, 1)
  248. else:
  249. data = com.sub(include_out.groups()[0], data, 1)
  250. else:
  251. data = com.sub('<code>' + it_d + '</code>', data, 1)
  252. else:
  253. break
  254. com = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
  255. da_com = com.findall(data)
  256. for com_da in da_com:
  257. mid_data = re.sub("<\/span>", "}}}", com_da)
  258. mid_data = re.sub("<\/div>", "}}}", mid_data)
  259. mid_data = re.sub('<span class="font\-size\-(?P<in>[1-6])">', "{{{+\g<in> ", mid_data)
  260. mid_data = re.sub('<span class="font\-size\-small\-(?P<in>[1-6])">', "{{{-\g<in> ", mid_data)
  261. mid_data = re.sub('<span style="color:(?:#)?(?P<in>[^"]*)">', "{{{#\g<in> ", mid_data)
  262. mid_data = re.sub('<span style="background:(?:#)?(?P<in>[^"]*)">', "{{{@\g<in> ", mid_data)
  263. mid_data = re.sub('<div style="(?P<in>[^"]*)">', "{{{#!wiki style=\"\g<in>\"\n", mid_data)
  264. mid_data = mid_data.replace('<', '&lt;').replace('>', '&gt;')
  265. mid_data = re.sub("(?P<in>.)", "<nowiki>\g<in></nowiki>", mid_data)
  266. data = com.sub(mid_data, data, 1)
  267. return([data, fol_num])
  268. def toc_pas(data, title, num):
  269. i = [0, 0, 0, 0, 0, 0, 0]
  270. last = 0
  271. toc_c = -1
  272. toc_d = -1
  273. span = ''
  274. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  275. while(1):
  276. i[0] += 1
  277. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\r\n', data)
  278. if(m):
  279. result = m.groups()
  280. wiki = len(result[0])
  281. if(last < wiki):
  282. last = wiki
  283. else:
  284. last = wiki
  285. if(wiki == 1):
  286. i[2] = 0
  287. i[3] = 0
  288. i[4] = 0
  289. i[5] = 0
  290. i[6] = 0
  291. elif(wiki == 2):
  292. i[3] = 0
  293. i[4] = 0
  294. i[5] = 0
  295. i[6] = 0
  296. elif(wiki == 3):
  297. i[4] = 0
  298. i[5] = 0
  299. i[6] = 0
  300. elif(wiki == 4):
  301. i[5] = 0
  302. i[6] = 0
  303. elif(wiki == 5):
  304. i[6] = 0
  305. if(wiki == 1):
  306. i[1] += 1
  307. elif(wiki == 2):
  308. i[2] += 1
  309. elif(wiki == 3):
  310. i[3] += 1
  311. elif(wiki == 4):
  312. i[4] += 1
  313. elif(wiki == 5):
  314. i[5] += 1
  315. else:
  316. i[6] += 1
  317. toc = str(i[1]) + '.' + str(i[2]) + '.' + str(i[3]) + '.' + str(i[4]) + '.' + str(i[5]) + '.' + str(i[6]) + '.'
  318. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  319. toc = re.sub("0\.", '', toc)
  320. toc = re.sub("#\.", '.', toc)
  321. toc = re.sub("\.$", '', toc)
  322. if(toc_c == -1):
  323. margin = 'style="margin-top: 30px;"'
  324. toc_c = toc.count('.')
  325. else:
  326. toc_d = toc.count('.')
  327. if(toc_c == toc_d):
  328. margin = 'style="margin-top: 30px;"'
  329. else:
  330. if(toc_d < toc_c):
  331. margin = 'style="margin-top: 30px;"'
  332. else:
  333. margin = ''
  334. toc_c = toc_d
  335. test = re.search('([0-9]*)(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?', toc)
  336. if(test):
  337. g = test.groups()
  338. if(g[4]):
  339. span = '<span style="margin-left: 5px;"></span>' * 4
  340. elif(g[3]):
  341. span = '<span style="margin-left: 5px;"></span>' * 3
  342. elif(g[2]):
  343. span = '<span style="margin-left: 5px;"></span>' * 2
  344. elif(g[1]):
  345. span = '<span style="margin-left: 5px;"></span>'
  346. else:
  347. span = ''
  348. rtoc += span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  349. c = re.sub(" $", "", result[1])
  350. d = c
  351. c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
  352. edit_d = ''
  353. if(num != 0):
  354. edit_d = ' <span style="font-size:11px;">[<a href="/edit/' + url_pas(title) + '/section/' + str(i[0]) + '">편집</a>]</span>'
  355. data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<tablenobr><h' + str(wiki) + ' id="' + c + '" ' + margin + '><a href="#toc" id="s-' + toc + '">' + toc + '.<span style="margin-left: 5px;"></span></a> ' + d + edit_d + '</h' + str(wiki) + '><hr style="margin-top: -5px;">', data, 1)
  356. else:
  357. rtoc += '</div>'
  358. break
  359. data = re.sub("\[목차\]", rtoc, data)
  360. return(data)
  361. def backlink_plus(name, link, backtype, num):
  362. if(num == 1):
  363. curs.execute("delete from back where title = ? and link = ? and type = ?", [link, name, backtype])
  364. curs.execute("insert into back (title, link, type) values (?, ?, ?)", [link, name, backtype])
  365. def cat_plus(name, link, num):
  366. if(num == 1):
  367. curs.execute("delete from cat where title = ? and cat = ?", [link, name])
  368. curs.execute("insert into cat (title, cat) values (?, ?)", [link, name])
  369. def namumark(title, data, num, in_c):
  370. data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", data))
  371. data = html_pas(data)
  372. data = '\r\n' + data + '\r\n'
  373. fol_num = 0
  374. var_d = mid_pas(data, fol_num, 0, in_c)
  375. data = var_d[0]
  376. fol_num = var_d[1]
  377. include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:(?:,\s?(?:(?!\)\]).)*))+)?\)\]")
  378. while(1):
  379. m = include.search(data)
  380. if(m):
  381. results = m.groups()
  382. if(results[0] == title):
  383. data = include.sub("<b>" + results[0] + "</b>", data, 1)
  384. else:
  385. curs.execute("select data from data where title = ?", [results[0]])
  386. in_con = curs.fetchall()
  387. backlink_plus(title, results[0], 'include', num)
  388. if(in_con):
  389. in_data = in_con[0][0]
  390. in_data = include.sub("", in_data)
  391. in_data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", in_data))
  392. in_data = html_pas(in_data)
  393. var_d = mid_pas(in_data, fol_num, 1, in_c)
  394. in_data = var_d[0]
  395. fol_num = var_d[1]
  396. if(results[1]):
  397. a = results[1]
  398. while(1):
  399. g = re.search("([^= ,]*)\=([^,]*)", a)
  400. if(g):
  401. result = g.groups()
  402. in_data = re.sub("@" + result[0] + "@", result[1], in_data)
  403. a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
  404. else:
  405. break
  406. in_data = toc_pas(in_data, results[0], num)
  407. data = include.sub('\n<nobr><a href="/w/' + url_pas(results[0]) + '">[' + results[0] + ' 이동]</a><div>' + in_data + '</div><nobr>\n', data, 1)
  408. else:
  409. data = include.sub("<a class=\"not_thing\" href=\"/w/" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
  410. else:
  411. break
  412. data = re.sub("\r\n##\s?([^\n]*)\r\n", "\r\n", data)
  413. data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
  414. data = savemark(data)
  415. d_re = re.findall('\r\n#(?:redirect|넘겨주기) ([^\n]+)', data)
  416. for d in d_re:
  417. view = d.replace('\\', '')
  418. sh = ''
  419. s_d = re.search('#((?:(?!x27;|#).)+)$', d)
  420. if(s_d):
  421. href = re.sub('#((?:(?!x27;|#).)+)$', '', d)
  422. sh = '#' + s_d.groups()[0]
  423. else:
  424. href = d
  425. data = re.sub('\r\n#(?:redirect|넘겨주기) ([^\n]+)', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(href.replace('\\', '').replace('&#x27;', "'")) + '/from/' + url_pas(title) + sh + '" />', data, 1)
  426. data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", data)
  427. while(1):
  428. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  429. if(m):
  430. result = m.groups()
  431. blockquote = result[0]
  432. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  433. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  434. else:
  435. break
  436. if(not re.search('\[목차\]', data)):
  437. if(not re.search('\[목차\(없음\)\]', data)):
  438. data = re.sub("(?P<in>(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g<in>", data, 1)
  439. else:
  440. data = re.sub("\[목차\(없음\)\]", "", data)
  441. data = re.sub("(\n)(?P<in>\r\n(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "\g<in>", data)
  442. data = toc_pas(data, title, num)
  443. category = ''
  444. while(1):
  445. m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
  446. if(m):
  447. g = m.groups()
  448. if(title != g[0]):
  449. cat_plus(title, g[0], num)
  450. if(category == ''):
  451. curs.execute("select title from data where title = ?", [g[0]])
  452. exists = curs.fetchall()
  453. if(exists):
  454. red = ""
  455. else:
  456. red = 'class="not_thing"'
  457. category += '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  458. else:
  459. curs.execute("select title from data where title = ?", [g[0]])
  460. exists = curs.fetchall()
  461. if(exists):
  462. red = ""
  463. else:
  464. red = 'class="not_thing"'
  465. category += ' / ' + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  466. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
  467. else:
  468. break
  469. data = re.sub("&#x27;&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;&#x27;).)*)&#x27;&#x27;&#x27;", '<b>\g<in></b>', data)
  470. data = re.sub("&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;).)*)&#x27;&#x27;", '<i>\g<in></i>', data)
  471. data = re.sub('(?:~~|--)(?P<in>(?:(?!~~|--).)+)(?:~~|--)', '<s>\g<in></s>', data)
  472. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  473. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  474. data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
  475. data = re.sub('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '$\g<in>$', data)
  476. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table> \
  477. <tbody> \
  478. <tr> \
  479. <td> \
  480. \g<in> \
  481. </td> \
  482. </tr> \
  483. </tbody> \
  484. </table>', data)
  485. data = re.sub('\[ruby\((?P<in>[^\,]*)\,\s?(?P<out>[^\)]*)\)\]', '<ruby> \
  486. \g<in> \
  487. <rp>(</rp> \
  488. <rt>\g<out></rt> \
  489. <rp>)</rp> \
  490. </ruby>', data)
  491. test = re.findall('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', data)
  492. if(test):
  493. for wiki in test:
  494. if(wiki[1]):
  495. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[1] + '</a>', data, 1)
  496. else:
  497. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[0] + '</a>', data, 1)
  498. data = re.sub("\[br\]",'<br>', data)
  499. while(1):
  500. com = re.compile("\[youtube\(([^, )]*)(,[^)]*)?\)\]")
  501. m = com.search(data)
  502. if(m):
  503. src = ''
  504. width = '560'
  505. height = '315'
  506. time = '0'
  507. result = m.groups()
  508. if(result[0]):
  509. yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9\-_]*))$', result[0])
  510. if(yudt):
  511. if(yudt.groups()[0]):
  512. src = yudt.groups()[0]
  513. elif(yudt.groups()[1]):
  514. src = yudt.groups()[1]
  515. elif(yudt.groups()[2]):
  516. src = yudt.groups()[2]
  517. else:
  518. src = ''
  519. if(result[1]):
  520. mdata = re.search('width=([0-9%]*)', result[1])
  521. if(mdata):
  522. width = mdata.groups()[0]
  523. mdata = re.search('height=([0-9%]*)', result[1])
  524. if(mdata):
  525. height = mdata.groups()[0]
  526. mdata = re.search('time=([0-9]*)', result[1])
  527. if(mdata):
  528. time = mdata.groups()[0]
  529. data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + src + '?start=' + time + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
  530. else:
  531. break
  532. data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
  533. a = re.findall('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', data)
  534. for i in a:
  535. b = re.search('(.*)\/', title)
  536. if(b):
  537. m = b.groups()
  538. if(i):
  539. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + i + ']]', data, 1)
  540. else:
  541. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + ']]', data, 1)
  542. else:
  543. if(i):
  544. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + i + ']]', data, 1)
  545. else:
  546. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + ']]', data, 1)
  547. data = re.sub('\[\[(?P<in>\/[^\]|]*)(?P<out>\|(?:[^\]]*))?\]\]', '[[' + title + '\g<in>\g<out>]]', data)
  548. link = re.compile('\[\[((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]')
  549. d_da = link.findall(data)
  550. for d in d_da:
  551. if(re.search('^(?:파일|외부):', d[0])):
  552. width = ''
  553. height = ''
  554. align = ''
  555. span = ['', '']
  556. try:
  557. w_d = re.search('width=([0-9]+(?:[a-z%]+)?)', d[1])
  558. if(w_d):
  559. width = 'width="' + w_d.groups()[0] + '" '
  560. h_d = re.search('height=([0-9]+(?:[a-z%]+)?)', d[1])
  561. if(h_d):
  562. height = 'height="' + h_d.groups()[0] + '" '
  563. a_d = re.search('align=(center|right)', d[1])
  564. if(a_d):
  565. span[0] = '<span style="display: block; text-align: ' + a_d.groups()[0] + ';">'
  566. span[1] = '</span>'
  567. except:
  568. pass
  569. f_d = re.search('^파일:([^.]+)\.(.+)$', d[0])
  570. if(f_d):
  571. if(not re.search("^파일:([^\n]*)", title)):
  572. backlink_plus(title, d[0], 'file', num)
  573. img = span[0] + '<img src="/image/' + sha224(f_d.groups()[0]) + '.' + f_d.groups()[1] + '" ' + width + height + '>' + span[1]
  574. data = link.sub(img, data, 1)
  575. else:
  576. img = span[0] + '<img src="' + re.sub('^외부:', '', d[0]) + '" ' + width + height + '>' + span[1]
  577. data = link.sub(img, data, 1)
  578. elif(re.search('^https?:\/\/', d[0])):
  579. view = d[0]
  580. try:
  581. if(re.search('(.+)', d[1])):
  582. view = d[1]
  583. except:
  584. pass
  585. data = link.sub('<a class="out_link" rel="nofollow" href="' + d[0] + '">' + view + '</a>', data, 1)
  586. else:
  587. view = d[0].replace('\\', '')
  588. try:
  589. if(re.search('(.+)', d[1])):
  590. view = d[1]
  591. except:
  592. pass
  593. sh = ''
  594. s_d = re.search('#((?:(?!x27;|#).)+)$', d[0])
  595. if(s_d):
  596. href = re.sub('#((?:(?!x27;|#).)+)$', '', d[0])
  597. sh = '#' + s_d.groups()[0]
  598. else:
  599. href = d[0]
  600. if(d[0] == title):
  601. data = link.sub('<b>' + view + '</b>', data, 1)
  602. elif(re.search('^#', d[0])):
  603. data = link.sub('<a href="' + url_pas(href.replace('\\', '')) + sh + '">' + view + '</a>', data, 1)
  604. else:
  605. backlink_plus(title, href.replace('\\', ''), '', num)
  606. curs.execute("select title from data where title = ?", [href.replace('\\', '')])
  607. if(not curs.fetchall()):
  608. no = 'class="not_thing"'
  609. else:
  610. no = ''
  611. data = link.sub('<a ' + no + ' href="/w/' + url_pas(href.replace('\\', '').replace('&#x27;', "'")) + sh + '">' + view + '</a>', data, 1)
  612. while(1):
  613. m = re.search("((?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
  614. if(m):
  615. result = m.groups()
  616. end = str(result[0])
  617. while(1):
  618. isspace = re.search("( +)\*\s([^\n]*)", end)
  619. if(isspace):
  620. spacebar = isspace.groups()
  621. up = len(spacebar[0]) * 20
  622. end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
  623. else:
  624. break
  625. end = re.sub("\n", '', end)
  626. data = re.sub("(?:(?:(?:( +)\*\s([^\n]*))\n?)+)", '<ul style="margin-top: 10px;" id="list">' + end + '</ul>', data, 1)
  627. else:
  628. break
  629. now_time = get_time()
  630. data = re.sub('\[date\]', now_time, data)
  631. time_data = re.search('^([0-9]{4}-[0-9]{2}-[0-9]{2})', now_time)
  632. time = time_data.groups()
  633. age_data = re.findall('\[age\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', data)
  634. for age in age_data:
  635. old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
  636. will = datetime.datetime.strptime(age, '%Y-%m-%d')
  637. e_data = old - will
  638. data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(int(int(e_data.days) / 365)), data, 1)
  639. dday_data = re.findall('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', data)
  640. for dday in dday_data:
  641. old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
  642. will = datetime.datetime.strptime(dday, '%Y-%m-%d')
  643. e_data = old - will
  644. if(re.search('^-', str(e_data.days))):
  645. e_day = str(e_data.days)
  646. else:
  647. e_day = '+' + str(e_data.days)
  648. data = re.sub('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', e_day, data, 1)
  649. data = re.sub("-{4,11}", "<hr>", data)
  650. while(1):
  651. b = re.search("(<\/h[0-9]>|\n)( +)", data)
  652. if(b):
  653. result = b.groups()
  654. up = re.sub(' ', '<span id="in"></span>', result[1])
  655. if(re.search('<\/h[0-9]>', result[0])):
  656. data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
  657. else:
  658. data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
  659. else:
  660. break
  661. a = 1
  662. tou = "<hr style='margin-top: 30px;' id='footnote'><div><br>"
  663. namu = []
  664. while(1):
  665. b = re.search("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", data)
  666. if(b):
  667. results = b.groups()
  668. if(not results[1] and results[0]):
  669. i = 0
  670. while(1):
  671. try:
  672. if(namu[i] == results[0]):
  673. none_this = 0
  674. break
  675. else:
  676. i += 2
  677. except:
  678. none_this = 1
  679. break
  680. if(none_this == 0):
  681. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  682. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  683. </sup> \
  684. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  685. <a onclick='folding(" + str(fol_num) + ");' href='#fn-" + str(a) + "'>[" + results[0] + "]</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>[X]</a> " + namu[i + 1] + " \
  686. </div>", data, 1)
  687. else:
  688. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  689. <a href='javascript:void(0);' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  690. </sup>", data, 1)
  691. else:
  692. if(results[0]):
  693. namu += [results[0]]
  694. namu += [results[1]]
  695. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + results[0] + "]</a> " + results[1] + "</span><br>"
  696. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  697. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  698. </sup> \
  699. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  700. <a onclick='folding(" + str(fol_num) + ");' href='#fn-" + str(a) + "'>[" + results[0] + "]</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>[X]</a> " + results[1] + " \
  701. </div>", data, 1)
  702. else:
  703. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + str(a) + "]</a> " + results[1] + "</span><br>"
  704. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", '<sup> \
  705. <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');" id="rfn-' + str(a) + '">[' + str(a) + ']</a> \
  706. </sup> \
  707. <div class="popup" style="display: none;" id="folding_' + str(fol_num) + '"> \
  708. <a onclick="folding(' + str(fol_num) + ');" href="#fn-' + str(a) + '">[' + str(a) + ']</a> <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');">[X]</a> ' + results[1] + ' \
  709. </div>', data, 1)
  710. a += 1
  711. fol_num += 2
  712. else:
  713. tou += '</div>'
  714. if(tou == "<hr style='margin-top: 30px;' id='footnote'><div><br></div>"):
  715. tou = ""
  716. break
  717. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  718. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  719. data = re.sub("\[각주\]", "<br>" + tou, data)
  720. data += tou
  721. if(category):
  722. data += '<div style="margin-top: 30px;" id="cate">분류: ' + category + '</div>'
  723. data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
  724. while(1):
  725. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  726. if(y):
  727. a = y.groups()
  728. mid_data = re.sub("\|\|", "#table#", a[0])
  729. mid_data = re.sub("\r\n", "<br>", mid_data)
  730. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  731. else:
  732. break
  733. data = re.sub("#table#", "||", data)
  734. data = re.sub("<tablenobr>", "\r\n", data)
  735. while(1):
  736. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  737. if(m):
  738. results = m.groups()
  739. table = results[0]
  740. while(1):
  741. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  742. if(a):
  743. row = ''
  744. cel = ''
  745. celstyle = ''
  746. rowstyle = ''
  747. alltable = ''
  748. table_d = ''
  749. result = a.groups()
  750. if(result[1]):
  751. table_d = table_p(result[1], result[0])
  752. alltable = table_d[0]
  753. rowstyle = table_d[1]
  754. celstyle = table_d[2]
  755. row = table_d[3]
  756. cel = table_d[4]
  757. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "> \
  758. <tbody> \
  759. <tr " + rowstyle + "> \
  760. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  761. else:
  762. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  763. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table> \
  764. <tbody> \
  765. <tr> \
  766. <td " + cel + ">", table, 1)
  767. else:
  768. break
  769. table = re.sub("\|\|$", "</td> \
  770. </tr> \
  771. </tbody> \
  772. </table>", table)
  773. while(1):
  774. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  775. if(b):
  776. row = ''
  777. cel = ''
  778. celstyle = ''
  779. rowstyle = ''
  780. table_d = ''
  781. result = b.groups()
  782. if(result[1]):
  783. table_d = table_p(result[1], result[0])
  784. rowstyle = table_d[1]
  785. celstyle = table_d[2]
  786. row = table_d[3]
  787. cel = table_d[4]
  788. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  789. </tr> \
  790. <tr " + rowstyle + "> \
  791. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  792. else:
  793. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  794. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  795. </tr> \
  796. <tr> \
  797. <td " + cel + ">", table, 1)
  798. else:
  799. break
  800. while(1):
  801. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  802. if(c):
  803. row = ''
  804. cel = ''
  805. celstyle = ''
  806. table_d = ''
  807. result = c.groups()
  808. if(result[1]):
  809. table_d = table_p(result[1], result[0])
  810. celstyle = table_d[2]
  811. row = table_d[3]
  812. cel = table_d[4]
  813. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  814. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  815. else:
  816. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  817. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  818. <td " + cel + ">", table, 1)
  819. else:
  820. break
  821. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  822. else:
  823. break
  824. data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
  825. data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
  826. data = re.sub("<nowiki>(?P<in>.)<\/nowiki>", "\g<in>", data)
  827. data = re.sub("<space>", " ", data)
  828. data = re.sub('<\/blockquote>(?:(?:\r)?\n){2}<blockquote>', '</blockquote><blockquote>', data)
  829. data = re.sub('<\/blockquote>(?:(?:\r)?\n)<br><blockquote>', '</blockquote><blockquote>', data)
  830. data = re.sub('\n', '<br>', data)
  831. data = re.sub('<isbr>', '\r\n', data)
  832. data = re.sub('^(?:<br>|\r|\n| )+', '', data)
  833. data = re.sub('^<div style="margin-top: 30px;" id="cate">', '<div id="cate">', data)
  834. conn.commit()
  835. return(data)