Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
main.DataHandler Class Reference
Inheritance diagram for main.DataHandler:

Public Member Functions

 get (self, name)
 
 getUserData (self, articleKeys=None)
 
 canData (self)
 
 canDataZip (self)
 

Detailed Description

Definition at line 293 of file main.py.

Member Function Documentation

◆ canData()

main.DataHandler.canData (   self)

Definition at line 343 of file main.py.

343 def canData(self):
344
345 def makeDartSafe(data):
346 return repr(unicode(data))[1:].replace('$', '\\$')
347
348 lines = [
349 '// TODO(jimhug): Work out correct copyright for this file.',
350 'class CannedData {'
351 ]
352
353 user = users.get_current_user()
354 prefs = UserData.get_by_key_name(user.user_id())
355 articleKeys = []
356 data = prefs.getEncodedData(articleKeys)
357 lines.append(' static const Map<String,String> data = const {')
358 for article in db.get(articleKeys):
359 key = makeDartSafe(urllib.quote(article.key().name()) + '.html')
360 lines.append(' %s:%s, ' % (key, makeDartSafe(article.content)))
361
362 lines.append(' "user.data":%s' % makeDartSafe(data))
363
364 lines.append(' };')
365
366 lines.append('}')
367 self.response.headers['Content-Type'] = 'application/dart'
368 self.response.out.write('\n'.join(lines))
369
const char * name
Definition fuchsia.cc:50

◆ canDataZip()

main.DataHandler.canDataZip (   self)

Definition at line 371 of file main.py.

371 def canDataZip(self):
372 # We need to zip into an in-memory buffer to get the right string encoding
373 # behavior.
374 data = StringIO.StringIO()
375 result = zipfile.ZipFile(data, 'w')
376
377 articleKeys = []
378 result.writestr('data/user.data',
379 self.getUserData(articleKeys).encode('utf-8'))
380 logging.info(' adding articles %s' % len(articleKeys))
381 images = []
382 for article in db.get(articleKeys):
383 article.ensureThumbnail()
384 path = 'data/' + article.key().name() + '.html'
385 result.writestr(path.encode('utf-8'),
386 article.content.encode('utf-8'))
387 if article.thumbnail:
388 path = 'data/' + article.key().name() + '.jpg'
389 result.writestr(path.encode('utf-8'), article.thumbnail)
390
391 result.close()
392 logging.info('writing CannedData.zip')
393 self.response.headers['Content-Type'] = 'multipart/x-zip'
394 disposition = 'attachment; filename=CannedData.zip'
395 self.response.headers['Content-Disposition'] = disposition
396 self.response.out.write(data.getvalue())
397 data.close()
398
399
static void encode(uint8_t output[16], const uint32_t input[4])
Definition SkMD5.cpp:240

◆ get()

main.DataHandler.get (   self,
  name 
)

Definition at line 295 of file main.py.

295 def get(self, name):
296 if name.endswith('.jpg'):
297 # Must be a thumbnail
298 key = urllib2.unquote(name[:-len('.jpg')])
299 article = Article.get_by_key_name(key)
300 self.response.headers['Content-Type'] = 'image/jpeg'
301 # cache images for 10 hours
302 self.response.headers['Cache-Control'] = 'public,max-age=36000'
303 article.ensureThumbnail()
304 self.response.out.write(article.thumbnail)
305 elif name.endswith('.html'):
306 # Must be article content
307 key = urllib2.unquote(name[:-len('.html')])
308 article = Article.get_by_key_name(key)
309 self.response.headers['Content-Type'] = 'text/html'
310 if article is None:
311 content = '<h2>Missing article</h2>'
312 else:
313 content = article.content
314 # cache article content for 10 hours
315 self.response.headers['Cache-Control'] = 'public,max-age=36000'
316 self.response.out.write(content)
317 elif name == 'user.data':
318 self.response.out.write(self.getUserData())
319 elif name == 'CannedData.dart':
320 self.canData()
321 elif name == 'CannedData.zip':
322 self.canDataZip()
323 else:
324 self.error(404)
325

◆ getUserData()

main.DataHandler.getUserData (   self,
  articleKeys = None 
)

Definition at line 326 of file main.py.

326 def getUserData(self, articleKeys=None):
327 user = users.get_current_user()
328 user_id = user.user_id()
329
330 key = 'data_' + user_id
331 # need to flush memcache fairly frequently...
332 data = memcache.get(key)
333 if data is None:
334 prefs = UserData.get_or_insert(user_id)
335 if prefs is None:
336 # TODO(jimhug): Graceful failure for unknown users.
337 pass
338 data = prefs.getEncodedData(articleKeys)
339 # TODO(jimhug): memcache.set(key, data)
340
341 return data
342

The documentation for this class was generated from the following file: