mark.py 43 KB

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