Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# encoding: utf-8 

2from . import * 

3 

4def htmlDocument( 

5 contentType=False, 

6 content='', 

7 attachmentSaveAsName=False): 

8 """ 

9 *The doctype and html tags* 

10 

11 **Key Arguments** 

12 

13 - ``content`` -- the head and body of the html page 

14 - ``attachmentSaveAsName`` -- save file as this name instead of opening in browser 

15  

16 

17 **Return** 

18 

19 - ``contentType`` -- the content type [ "text/html" ] 

20 - ``doctype`` -- the HTML5 doctype 

21  

22 """ 

23 

24 if attachmentSaveAsName is not False: 

25 contentType = """Content-Disposition: attachment; filename=%(attachmentSaveAsName)s""" % locals( 

26 ) 

27 elif not contentType: 

28 contentType = "" 

29 else: 

30 contentType = "Content-type: %(contentType)s" % locals() 

31 

32 content = content.strip() 

33 

34 if "text/plain" in contentType or "text/csv" in contentType or attachmentSaveAsName is not False: 

35 htmlDocument = \ 

36 """%(contentType)s\n 

37%(content)s 

38""" % locals() 

39 else: 

40 htmlDocument = \ 

41 """%(contentType)s\n 

42 <!DOCTYPE html> 

43 <html lang="en"> 

44 %(content)s 

45 </html> 

46 """ \ 

47 % locals() 

48 return htmlDocument.strip()