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