Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

83 строки
1.8 KiB

  1. #!/usr/bin/python
  2. try:
  3. import sys, os
  4. sys.path.append(os.getcwd()+'/cgi-bin')
  5. def getTraceback():
  6. import sys, traceback, string
  7. type, value, tb = sys.exc_info()
  8. body = "Traceback (innermost last):\n"
  9. list = traceback.format_tb(tb, None) \
  10. + traceback.format_exception_only(type, value)
  11. body = body + "%-20s %s" % (string.join(list[:-1], ""), list[-1])
  12. return body
  13. import cgi
  14. import webnotes
  15. import webnotes.auth
  16. import webnotes.utils
  17. import webnotes.utils.file_manager
  18. import webnotes.db
  19. import webnotes.defs
  20. sys.path.append(webnotes.defs.modules_path)
  21. form = cgi.FieldStorage()
  22. webnotes.form_dict = {}
  23. for each in form.keys():
  24. webnotes.form_dict[each] = form.getvalue(each)
  25. n = form.getvalue('name')
  26. # authenticate
  27. webnotes.auth.HTTPRequest()
  28. # get file
  29. res = webnotes.utils.file_manager.get_file(n)
  30. fname = res[0]
  31. if hasattr(res[1], 'tostring'):
  32. fcontent = res[1].tostring()
  33. else:
  34. fcontent = res[1]
  35. if form.getvalue('thumbnail'):
  36. tn = webnotes.utils.cint(form.getvalue('thumbnail'))
  37. try:
  38. from PIL import Image
  39. import cStringIO
  40. fobj = cStringIO.StringIO(fcontent)
  41. image = Image.open(fobj)
  42. image.thumbnail((tn,tn*2), Image.ANTIALIAS)
  43. outfile = cStringIO.StringIO()
  44. if image.mode != "RGB":
  45. image = image.convert("RGB")
  46. image.save(outfile, 'JPEG')
  47. outfile.seek(0)
  48. fcontent = outfile.read()
  49. except:
  50. pass
  51. import mimetypes
  52. print "Content-Type: %s" % (mimetypes.guess_type(fname)[0] or 'application/unknown')
  53. print "Content-Disposition: filename="+fname.replace(' ', '_')
  54. print "Cache-Control: max-age=3600"
  55. print
  56. print fcontent
  57. except Exception, e:
  58. print "Content-Type: text/html"
  59. try:
  60. out = {'message':'', 'exc':getTraceback().replace('\n','<br>')}
  61. except:
  62. out = {'exc': e}
  63. print
  64. print str(out)