source file: /Library/Python/2.3/site-packages/CherryPy-3.0.1-py2.3.egg/cherrypy/_cpcgifs.py
file stats: 67 lines, 11 executed: 16.4% covered
1. import cgi 2. import cherrypy 3. 4. 5. class FieldStorage(cgi.FieldStorage): 6. def __init__(self, *args, **kwds): 7. try: 8. cgi.FieldStorage.__init__(self, *args, **kwds) 9. except ValueError, ex: 10. if str(ex) == 'Maximum content length exceeded': 11. raise cherrypy.HTTPError(status=413) 12. else: 13. raise ex 14. 15. def read_lines_to_eof(self): 16. """Internal: read lines until EOF.""" 17. while 1: 18. line = self.fp.readline(1<<16) 19. if not line: 20. self.done = -1 21. break 22. self.__write(line) 23. 24. def read_lines_to_outerboundary(self): 25. """Internal: read lines until outerboundary.""" 26. next = "--" + self.outerboundary 27. last = next + "--" 28. delim = "" 29. last_line_lfend = True 30. while 1: 31. line = self.fp.readline(1<<16) 32. if not line: 33. self.done = -1 34. break 35. if line[:2] == "--" and last_line_lfend: 36. strippedline = line.strip() 37. if strippedline == next: 38. break 39. if strippedline == last: 40. self.done = 1 41. break 42. odelim = delim 43. if line[-2:] == "\r\n": 44. delim = "\r\n" 45. line = line[:-2] 46. last_line_lfend = True 47. elif line[-1] == "\n": 48. delim = "\n" 49. line = line[:-1] 50. last_line_lfend = True 51. else: 52. delim = "" 53. last_line_lfend = False 54. self.__write(odelim + line) 55. 56. def skip_lines(self): 57. """Internal: skip lines until outer boundary if defined.""" 58. if not self.outerboundary or self.done: 59. return 60. next = "--" + self.outerboundary 61. last = next + "--" 62. last_line_lfend = True 63. while 1: 64. line = self.fp.readline(1<<16) 65. if not line: 66. self.done = -1 67. break 68. if line[:2] == "--" and last_line_lfend: 69. strippedline = line.strip() 70. if strippedline == next: 71. break 72. if strippedline == last: 73. self.done = 1 74. break 75. if line.endswith('\n'): 76. last_line_lfend = True 77. else: 78. last_line_lfend = False 79.