1 --- HTTPRequest.py Thu Jul 31 23:08:06 2003 2 +++ HTTPRequest.py Sun Feb 1 18:03:56 2004 3 @@ -240,6 +240,53 @@ 4 # @@ 2000-03-26 ce: maybe belongs in section below. clean up docs 5 return self._environ['REMOTE_USER'] 6 7 + ## Languages ## 8 + 9 + def _contentPreferences(self, accept_preference): 10 + """ 11 + Returns the preferences as requested by the user agent. The preferences are 12 + returned as a list of codes in the same order as they appeared in the 13 + appropriate environment variable. In other words, the explicit weighting 14 + criteria are ignored. 15 + 16 + As the 'accept_preference' parameter, values for language and charset 17 + preferences are appropriate. 18 + """ 19 + 20 + accept_defs = accept_preference.split(",") 21 + accept_prefs = [] 22 + for accept_def in accept_defs: 23 + t = accept_def.split(";") 24 + if len(t) >= 1: 25 + accept_prefs.append(t[0].strip()) 26 + return accept_prefs 27 + 28 + def contentLanguages(self): 29 + """ 30 + Returns the language preferences. 31 + """ 32 + 33 + try: 34 + return self._contentPreferences(self._environ["HTTP_ACCEPT_LANGUAGE"]) 35 + except KeyError: 36 + return [] 37 + 38 + def contentCharsets(self): 39 + """ 40 + Returns the character set preferences. 41 + """ 42 + 43 + try: 44 + return self._contentPreferences(self._environ["HTTP_ACCEPT_CHARSET"]) 45 + except KeyError: 46 + return [] 47 + 48 + def contentType(self): 49 + """ 50 + Returns the content type of the request. 51 + """ 52 + 53 + return self._environ.get('CONTENT_TYPE', None) 54 55 ## Remote info ## 56 57 @@ -503,7 +550,7 @@ 58 you want to be sure you get the entire body of the request. 59 """ 60 fs = self.fieldStorage() 61 - if rewind: 62 + if fs is not None and fs.file is not None and rewind: 63 fs.file.seek(0) 64 return fs.file 65