annotate SrvTxtUtils.py @ 621:a7b287122ce8

relax certificate checking even more.
author casties
date Thu, 11 Dec 2014 17:24:21 +0100
parents a71ae589d342
children bc68ca0d2c0a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
458
48b135b089c8 more renovation
casties
parents:
diff changeset
1 """Utility methods for handling XML, reading HTTP, etc"""
48b135b089c8 more renovation
casties
parents:
diff changeset
2
490
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
3 from App.ImageFile import ImageFile
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
4 from App.Common import rfc1123_date
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
5
458
48b135b089c8 more renovation
casties
parents:
diff changeset
6 import sys
490
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
7 import os
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
8 import stat
458
48b135b089c8 more renovation
casties
parents:
diff changeset
9 import urllib
48b135b089c8 more renovation
casties
parents:
diff changeset
10 import logging
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
11 import time
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
12 import re
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
13 import datetime
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
14 try:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
15 import httplib2
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
16 httplib = 'httplib2'
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
17 except:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
18 logging.warn("Unable to import httplib2! Falling back to urllib2!")
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
19 import urllib2
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
20 httplib = 'urllib2'
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
21
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
22 import xml.etree.ElementTree as ET
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
23
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
24 srvTxtUtilsVersion = "1.12.3"
458
48b135b089c8 more renovation
casties
parents:
diff changeset
25
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
26 map_months = {'en': [u"",
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
27 u"January",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
28 u"February",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
29 u"March",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
30 u"April",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
31 u"May",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
32 u"June",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
33 u"July",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
34 u"August",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
35 u"September",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
36 u"October",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
37 u"November",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
38 u"December"],
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
39 'de': [u"",
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
40 u"Januar",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
41 u"Februar",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
42 u"M\u00e4rz",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
43 u"April",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
44 u"Mai",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
45 u"Juni",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
46 u"Juli",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
47 u"August",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
48 u"September",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
49 u"Oktober",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
50 u"November",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
51 u"Dezember"]}
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
52
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
53 map_weekdays_short = {'en': [
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
54 u"Mo",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
55 u"Tu",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
56 u"We",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
57 u"Th",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
58 u"Fr",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
59 u"Sa",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
60 u"Su",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
61 ],
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
62 'de': [
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
63 u"Mo",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
64 u"Di",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
65 u"Mi",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
66 u"Do",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
67 u"Fr",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
68 u"Sa",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
69 u"So",
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
70 ]}
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
71
458
48b135b089c8 more renovation
casties
parents:
diff changeset
72
48b135b089c8 more renovation
casties
parents:
diff changeset
73 def getInt(number, default=0):
48b135b089c8 more renovation
casties
parents:
diff changeset
74 """returns always an int (0 in case of problems)"""
48b135b089c8 more renovation
casties
parents:
diff changeset
75 try:
48b135b089c8 more renovation
casties
parents:
diff changeset
76 return int(number)
48b135b089c8 more renovation
casties
parents:
diff changeset
77 except:
48b135b089c8 more renovation
casties
parents:
diff changeset
78 return int(default)
48b135b089c8 more renovation
casties
parents:
diff changeset
79
490
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
80 def getAt(array, idx, default=None):
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
81 """returns element idx from array or default (in case of problems)"""
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
82 try:
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
83 return array[idx]
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
84 except:
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
85 return default
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
86
514
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
87 def unicodify(s):
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
88 """decode str (utf-8 or latin-1 representation) into unicode object"""
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
89 if not s:
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
90 return u""
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
91 if isinstance(s, str):
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
92 try:
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
93 return s.decode('utf-8')
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
94 except:
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
95 return s.decode('latin-1')
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
96 else:
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
97 return s
514
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
98
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
99 def utf8ify(s):
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
100 """encode unicode object or string into byte string in utf-8 representation.
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
101 assumes string objects to be utf-8"""
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
102 if not s:
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
103 return ""
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
104 if isinstance(s, str):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
105 return s
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
106 else:
614
d16da6e739ef fix problem with utf8ify trying to encode ints.
casties
parents: 613
diff changeset
107 return s.encode('utf-8')
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
108
514
c55e376be01b search works even with unicode...
casties
parents: 490
diff changeset
109
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
110 def getTextFromNode(node, recursive=False, length=0):
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
111 """Return all text content of a (etree) node.
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
112
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
113 :param recursive: descend subnodes
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
114
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
115 :returns: text string
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
116 """
458
48b135b089c8 more renovation
casties
parents:
diff changeset
117 if node is None:
490
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
118 return ''
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
119
458
48b135b089c8 more renovation
casties
parents:
diff changeset
120 # ElementTree:
490
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
121 text = node.text or ''
458
48b135b089c8 more renovation
casties
parents:
diff changeset
122 for e in node:
490
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
123 if recursive:
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
124 text += getText(e)
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
125 else:
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
126 text += e.text or ''
458
48b135b089c8 more renovation
casties
parents:
diff changeset
127 if e.tail:
48b135b089c8 more renovation
casties
parents:
diff changeset
128 text += e.tail
48b135b089c8 more renovation
casties
parents:
diff changeset
129
48b135b089c8 more renovation
casties
parents:
diff changeset
130 # 4Suite:
48b135b089c8 more renovation
casties
parents:
diff changeset
131 #nodelist=node.childNodes
48b135b089c8 more renovation
casties
parents:
diff changeset
132 #text = ""
48b135b089c8 more renovation
casties
parents:
diff changeset
133 #for n in nodelist:
48b135b089c8 more renovation
casties
parents:
diff changeset
134 # if n.nodeType == node.TEXT_NODE:
48b135b089c8 more renovation
casties
parents:
diff changeset
135 # text = text + n.data
48b135b089c8 more renovation
casties
parents:
diff changeset
136
48b135b089c8 more renovation
casties
parents:
diff changeset
137 return text
48b135b089c8 more renovation
casties
parents:
diff changeset
138
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
139 getText = getTextFromNode
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
140
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
141 def getPlaintext(text, length=0, wordwrap=False, ignoretags=[]):
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
142 """Return plain text content by filtering out XML tags.
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
143
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
144 :param text: string or etree node
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
145 :param length: length of text to return (0=all)
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
146 :param wordwrap: try not to break the last word (may return shorter string)
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
147 :returns: text string
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
148 """
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
149 if text is None:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
150 return ''
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
151
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
152 try:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
153 if isinstance(text, basestring):
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
154 xmltext = utf8ify("<div>%s</div>"%text)
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
155 dom = ET.fromstring(xmltext)
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
156 else:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
157 dom = text
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
158
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
159 plaintext = ''
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
160 for elem in dom.iter():
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
161 if elem.tag in ignoretags:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
162 # ignore tag
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
163 continue
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
164
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
165 if elem.text:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
166 plaintext += elem.text
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
167 if elem.tail:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
168 plaintext += elem.tail
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
169
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
170 if length > 0 and len(plaintext) > length:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
171 break
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
172
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
173 text = plaintext
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
174
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
175 except Exception, e:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
176 logging.warn("getPlaintext: error parsing text! Returning everything. %s"%e)
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
177
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
178 if length > 0 and len(text) > length:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
179 # try to not break words
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
180 if wordwrap and text[length] not in [' ', '.', '?', '!']:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
181 # search the last blank
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
182 length = text.rfind(' ', 0, length)
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
183
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
184 return text[:length] + '...'
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
185
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
186 return text
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
187
458
48b135b089c8 more renovation
casties
parents:
diff changeset
188
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
189 def serialize(node):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
190 """returns a string containing an XML snippet of (etree) node"""
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
191 s = ET.tostring(node, 'UTF-8')
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
192 # snip off XML declaration
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
193 if s.startswith('<?xml'):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
194 i = s.find('?>')
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
195 return s[i+3:]
458
48b135b089c8 more renovation
casties
parents:
diff changeset
196
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
197 return s
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
198
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
199
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
200 def getMonthName(mon, lang):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
201 """returns the name of the month mon in the language lang"""
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
202 return map_months[lang.lower()][mon]
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
203
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
204
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
205 def getWeekdayName(day, lang, short=True):
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
206 """returns the name of the weekday day in the language lang"""
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
207 return map_weekdays_short[lang.lower()][day]
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
208
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
209
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
210 def getDateString(date=None, lang='en', short=False, withYear=True, monthNames=True, abbrev=False):
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
211 """Return formatted date string."""
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
212 if date is None:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
213 return None
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
214
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
215 ds = None
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
216 if callable(date.day):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
217 # callable members
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
218 day = date.day()
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
219 month = date.month()
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
220 year = date.year()
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
221 else:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
222 # data members
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
223 day = date.day
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
224 month = date.month
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
225 year = date.year
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
226
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
227 if lang.lower() == 'en':
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
228 if short:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
229 ds = "%s/%s/%s"%(year,month,day)
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
230 else:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
231 ds = "%s %s"%(getMonthName(month, lang), day)
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
232 if withYear:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
233 ds += ", %s"%year
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
234
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
235 elif lang.lower() == 'de':
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
236 if short:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
237 ds = "%s.%s.%s"%(day,month,year)
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
238 else:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
239 ds = "%s. %s"%(day, getMonthName(month, lang))
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
240 if withYear:
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
241 ds += " %s"%year
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
242
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
243 elif lang.lower() == 'iso':
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
244 ds = date.isoformat()
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
245
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
246 return ds
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
247
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
248
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
249 def getDate(date):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
250 """return date object from date or datetime date."""
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
251 if isinstance(date, datetime.datetime):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
252 # strip time
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
253 return date.date()
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
254
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
255 return date
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
256
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
257
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
258 def getDatetime(date):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
259 """return datetime object from date or datetime date."""
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
260 if isinstance(date, datetime.date):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
261 # add time 0:00
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
262 return datetime.datetime.combine(date, datetime.time())
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
263
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
264 return date
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
265
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
266
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
267 def getHttpData(url, data=None, num_tries=3, timeout=10, username=None, password=None, cache=None, insecure=False, noExceptions=False):
458
48b135b089c8 more renovation
casties
parents:
diff changeset
268 """returns result from url+data HTTP request"""
48b135b089c8 more renovation
casties
parents:
diff changeset
269 # we do GET (by appending data to url)
48b135b089c8 more renovation
casties
parents:
diff changeset
270 if isinstance(data, str) or isinstance(data, unicode):
48b135b089c8 more renovation
casties
parents:
diff changeset
271 # if data is string then append
48b135b089c8 more renovation
casties
parents:
diff changeset
272 url = "%s?%s"%(url,data)
48b135b089c8 more renovation
casties
parents:
diff changeset
273 elif isinstance(data, dict) or isinstance(data, list) or isinstance(data, tuple):
48b135b089c8 more renovation
casties
parents:
diff changeset
274 # urlencode
48b135b089c8 more renovation
casties
parents:
diff changeset
275 url = "%s?%s"%(url,urllib.urlencode(data))
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
276
458
48b135b089c8 more renovation
casties
parents:
diff changeset
277 errmsg = None
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
278 if httplib == 'httplib2':
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
279 # use httplib2
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
280 for cnt in range(num_tries):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
281 try:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
282 logging.debug("getHttp(lib2)Data(#%s %ss) url=%s"%(cnt+1,timeout,url))
621
a7b287122ce8 relax certificate checking even more.
casties
parents: 620
diff changeset
283 h = httplib2.Http(cache=cache, timeout=float(timeout), disable_ssl_certificate_validation=True)
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
284 if username:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
285 h.add_credentials(username, password)
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
286
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
287 resp, data = h.request(url)
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
288 return data
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
289
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
290 except httplib2.HttpLib2Error, e:
620
a71ae589d342 use https for annotations and fix bug when logging httplib errors.
casties
parents: 614
diff changeset
291 logging.error("getHttp(lib2)Data: HTTP error(%s): %s"%(getattr(e, 'code','?'),e))
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
292 errmsg = str(e)
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
293 # stop trying
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
294 break
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
295
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
296 else:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
297 # use urllib2
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
298 response = None
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
299 for cnt in range(num_tries):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
300 try:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
301 logging.debug("getHttpData(#%s %ss) url=%s"%(cnt+1,timeout,url))
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
302 if sys.version_info < (2, 6):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
303 # set timeout on socket -- ugly :-(
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
304 import socket
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
305 socket.setdefaulttimeout(float(timeout))
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
306 response = urllib2.urlopen(url)
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
307 else:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
308 # timeout as parameter
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
309 response = urllib2.urlopen(url,timeout=float(timeout))
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
310 # check result?
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
311 data = response.read()
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
312 response.close()
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
313 return data
458
48b135b089c8 more renovation
casties
parents:
diff changeset
314
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
315 except urllib2.HTTPError, e:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
316 logging.error("getHttpData: HTTP error(%s): %s"%(e.code,e))
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
317 errmsg = str(e)
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
318 # stop trying
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
319 break
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
320 except urllib2.URLError, e:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
321 logging.error("getHttpData: URLLIB error(%s): %s"%(e.reason,e))
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
322 errmsg = str(e)
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
323 # stop trying
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
324 #break
458
48b135b089c8 more renovation
casties
parents:
diff changeset
325
546
2928037f9a75 ASSIGNED - # 249: Annotations shared in groups
casties
parents: 528
diff changeset
326 if noExceptions:
2928037f9a75 ASSIGNED - # 249: Annotations shared in groups
casties
parents: 528
diff changeset
327 return None
2928037f9a75 ASSIGNED - # 249: Annotations shared in groups
casties
parents: 528
diff changeset
328
458
48b135b089c8 more renovation
casties
parents:
diff changeset
329 raise IOError("ERROR fetching HTTP data from %s: %s"%(url,errmsg))
48b135b089c8 more renovation
casties
parents:
diff changeset
330 #return None
48b135b089c8 more renovation
casties
parents:
diff changeset
331
490
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
332
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
333 def refreshingImageFileIndexHtml(self, REQUEST, RESPONSE):
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
334 """index_html method for App.ImageFile that updates the file info for each request."""
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
335 stat_info = os.stat(self.path)
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
336 self.size = stat_info[stat.ST_SIZE]
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
337 self.lmt = float(stat_info[stat.ST_MTIME]) or time.time()
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
338 self.lmh = rfc1123_date(self.lmt)
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
339 # call original method
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
340 return ImageFile.index_html(self, REQUEST, RESPONSE)
6f116b86a226 more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents: 464
diff changeset
341
585
83eeed69793f new annotator layer for images.
casties
parents: 553
diff changeset
342
613
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
343 def shortenString(s, l, ellipsis='...'):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
344 """returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis."""
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
345 if len(s) <= l:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
346 return s
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
347
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
348 l1 = int((l - len(ellipsis)) / 2)
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
349 return "%s%s%s"%(s[:l1],ellipsis,s[-l1:])
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
350
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
351
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
352 def sqlName(s, lc=True, more=''):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
353 """returns restricted ASCII-only version of string"""
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
354 if s is None:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
355 return ""
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
356
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
357 if not isinstance(s, basestring):
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
358 # make string object
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
359 s = str(s)
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
360
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
361 # remove '
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
362 s = s.replace("'","")
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
363 # all else -> "_"
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
364 s = re.sub('[^A-Za-z0-9_'+more+']','_',s)
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
365 if lc:
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
366 return s.lower()
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
367
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
368 return s
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
369
c57d80a649ea CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents: 585
diff changeset
370