1# Copyright 2009 Google Inc. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Create URL's for a given set of text."""
16
17
18NOTE_MAP = {
19    'NXDOMAIN': 'http://code.google.com/p/namebench/wiki/FAQ#What_does_"NXDOMAIN_hijacking"_mean?',
20    'cache poisoning': 'http://www.kb.cert.org/vuls/id/800113',
21    'Vulnerable to poisoning attacks': 'http://www.kb.cert.org/vuls/id/800113',
22    'Wrong result': 'http://code.google.com/p/namebench/wiki/FAQ#What_does_"Incorrect_result_for..."_mean?',
23    'is hijacked': 'http://code.google.com/p/namebench/wiki/FAQ#What_does_"Incorrect_result_for..."_mean?',
24    'appears incorrect': 'http://code.google.com/p/namebench/wiki/FAQ#What_does_"Incorrect_result_for..."_mean?',
25}
26
27
28def GetUrlForNote(note):
29  if not note:
30    return None
31  if not isinstance(note, str):
32    print "Odd: Got a non-string note: %s (%s)" % (note, type(note))
33    return None
34  url = None
35  for keyword in NOTE_MAP:
36    if keyword in note:
37      url = NOTE_MAP[keyword]
38  return url
39
40
41def CreateNoteUrlTuples(notes):
42  note_tuples = []
43  for note in notes:
44    note_tuples.append({'text': note, 'url': GetUrlForNote(note)})
45  return note_tuples
46
47
48