OLD | NEW |
1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 import re | 6 import re |
7 import json | 7 import json |
8 from webapp2 import * | 8 from webapp2 import * |
9 from datetime import datetime, timedelta | 9 from datetime import datetime, timedelta |
10 from google.appengine.ext import blobstore | 10 from google.appengine.ext import blobstore |
11 from google.appengine.ext.webapp import blobstore_handlers | 11 from google.appengine.ext.webapp import blobstore_handlers |
12 from google.appengine.api import memcache | 12 from google.appengine.api import memcache |
13 import cloudstorage | 13 import cloudstorage |
14 | 14 |
15 ONE_HOUR = 60 * 60 | 15 ONE_HOUR = 60 * 60 |
16 ONE_DAY = ONE_HOUR * 24 | 16 ONE_DAY = ONE_HOUR * 24 |
17 ONE_WEEK = ONE_DAY * 7 | 17 ONE_WEEK = ONE_DAY * 7 |
18 | 18 |
19 # for redirects below | 19 # for redirects below |
20 ONLY_DART_LIB = re.compile("^dart:([a-zA-Z0-9_]+)$") | 20 ONLY_DART_LIB = re.compile("^dart:([a-zA-Z0-9_]+)$") |
21 LIB_NAME_AND_CLASS_NAME = re.compile("^dart:([^\.]+)\.(.+)$") | 21 LIB_NAME_AND_CLASS_NAME = re.compile("^dart[:-]([^\.]+)\.(.+)$") |
22 | 22 |
23 class VersionInfo(object): | 23 class VersionInfo(object): |
24 """Small helper class holding information about the last version seen and the | 24 """Small helper class holding information about the last version seen and the |
25 last time the version was checked for.""" | 25 last time the version was checked for.""" |
26 def __init__(self, update_interval): | 26 def __init__(self, update_interval): |
27 # The most recent version for this channel. | 27 # The most recent version for this channel. |
28 self.version = None | 28 self.version = None |
29 # The time this version was found. | 29 # The time this version was found. |
30 self.last_check = None | 30 self.last_check = None |
31 self.update_interval = update_interval | 31 self.update_interval = update_interval |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 def redir_dev_path(handler, *args, **kwargs): | 258 def redir_dev_path(handler, *args, **kwargs): |
259 postfix = kwargs['path'][1:] | 259 postfix = kwargs['path'][1:] |
260 return redir_channel_latest('dev', postfix) | 260 return redir_channel_latest('dev', postfix) |
261 | 261 |
262 def redir_be_path(handler, *args, **kwargs): | 262 def redir_be_path(handler, *args, **kwargs): |
263 postfix = kwargs['path'][1:] | 263 postfix = kwargs['path'][1:] |
264 return redir_channel_latest('be', postfix) | 264 return redir_channel_latest('be', postfix) |
265 | 265 |
266 # /apidocs/channels/stable/dartdoc-viewer/home => /stable | 266 # /apidocs/channels/stable/dartdoc-viewer/home => /stable |
267 # /apidocs/channels/stable/dartdoc-viewer/dart:math => /stable/dart-math/dart-ma
th-library.html | 267 # /apidocs/channels/stable/dartdoc-viewer/dart:math => /stable/dart-math/dart-ma
th-library.html |
268 # /apidocs/channels/stable/dartdoc-viewer/dart:async.Future => /stable/dart-asyn
c/Future.html | 268 # /apidocs/channels/stable/dartdoc-viewer/dart[:-]async.Future => /stable/dart-a
sync/Future-class.html |
269 def redir_name(handler, *args, **kwargs): | 269 def redir_name(handler, *args, **kwargs): |
270 channel = kwargs['channel'] | 270 channel = kwargs['channel'] |
271 postfix = kwargs['path'][1:] | 271 postfix = kwargs['path'][1:] |
272 | 272 |
273 # /apidocs/channels/stable/dartdoc-viewer/home => /stable | 273 # /apidocs/channels/stable/dartdoc-viewer/home => /stable |
274 # /apidocs/channels/stable/dartdoc-viewer/ => /stable | 274 # /apidocs/channels/stable/dartdoc-viewer/ => /stable |
275 # /apidocs/channels/stable/dartdoc-viewer => /stable | 275 # /apidocs/channels/stable/dartdoc-viewer => /stable |
276 if postfix == 'home' or postfix == '': | 276 if postfix == 'home' or postfix == '': |
277 return '/%s' % (channel) | 277 return '/%s' % (channel) |
278 | 278 |
279 # /apidocs/channels/stable/dartdoc-viewer/dart:math => /stable/dart-math/dart-
math-library.html | 279 # /apidocs/channels/stable/dartdoc-viewer/dart:math => /stable/dart-math/dart-
math-library.html |
280 is_lib_page = ONLY_DART_LIB.match(postfix) | 280 is_lib_page = ONLY_DART_LIB.match(postfix) |
281 if is_lib_page: | 281 if is_lib_page: |
282 name = postfix.replace(':', '-') | 282 name = postfix.replace(':', '-') |
283 return '/%s/%s/%s-library.html' % (channel, name, name) | 283 return '/%s/%s/%s-library.html' % (channel, name, name) |
284 | 284 |
285 # /apidocs/channels/stable/dartdoc-viewer/dart:async.Future => /stable/dart-as
ync/Future-class.html | 285 # /apidocs/channels/stable/dartdoc-viewer/dart[:-]async.Future => /stable/dart
-async/Future-class.html |
286 is_lib_and_class = LIB_NAME_AND_CLASS_NAME.match(postfix) | 286 is_lib_and_class = LIB_NAME_AND_CLASS_NAME.match(postfix) |
287 if is_lib_and_class: | 287 if is_lib_and_class: |
288 lib_name = 'dart-' + is_lib_and_class.group(1) | 288 lib_name = 'dart-' + is_lib_and_class.group(1) |
289 class_name = is_lib_and_class.group(2) | 289 class_name = is_lib_and_class.group(2) |
290 return '/%s/%s/%s-class.html' % (channel, lib_name, class_name) | 290 return '/%s/%s/%s-class.html' % (channel, lib_name, class_name) |
291 | 291 |
292 self.error(404) | 292 abort(404) |
293 | 293 |
294 def redir_bare_lib_name(handler, *args, **kwargs): | 294 def redir_bare_lib_name(handler, *args, **kwargs): |
295 version = kwargs['version'] | 295 version = kwargs['version'] |
296 libname = kwargs['libname'] | 296 libname = kwargs['libname'] |
297 | 297 |
298 # /1.12.0/dart-async => /1.12.0/dart-async/dart-async-library.html | 298 # /1.12.0/dart-async => /1.12.0/dart-async/dart-async-library.html |
299 return '/%s/dart-%s/dart-%s-library.html' % (version, libname, libname) | 299 return '/%s/dart-%s/dart-%s-library.html' % (version, libname, libname) |
300 | 300 |
301 # /dart_core.html => /stable/dart-core/dart-core-library.html | 301 # /dart_core.html => /stable/dart-core/dart-core-library.html |
302 def redir_legacy_lib(handler, *args, **kwargs): | 302 def redir_legacy_lib(handler, *args, **kwargs): |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 defaults={'_uri': '/stable'}), | 395 defaults={'_uri': '/stable'}), |
396 | 396 |
397 Route('/<version:[\w.-]+>/dart-<libname:\w+>', RedirectHandler, | 397 Route('/<version:[\w.-]+>/dart-<libname:\w+>', RedirectHandler, |
398 defaults={'_uri': redir_bare_lib_name}), | 398 defaults={'_uri': redir_bare_lib_name}), |
399 | 399 |
400 Route('/', RedirectHandler, defaults={'_uri': '/stable'}), | 400 Route('/', RedirectHandler, defaults={'_uri': '/stable'}), |
401 | 401 |
402 Route('<path:.*>', ApiDocs) | 402 Route('<path:.*>', ApiDocs) |
403 ], | 403 ], |
404 debug=True) | 404 debug=True) |
OLD | NEW |