- add sources.
[platform/framework/web/crosswalk.git] / src / components / test / data / autofill / merge / tools / autofill_merge_common.py
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5
6 class UnknownColumnNameException(Exception):
7   """Exception type raised when encountering an unknown column name."""
8   def __init__(self, column_name):
9     self.column_name = column_name
10   def __str__(self):
11     return repr(self.column_name)
12
13
14 def SerializeProfiles(profiles):
15   """Returns a serialized string for the given |profiles|.
16
17   |profiles| should be a list of (field_type, value) string pairs.
18
19   """
20
21   lines = []
22   for profile in profiles:
23     # Include a fixed string to separate profiles.
24     lines.append("---")
25     for (field_type, value) in profile:
26       if field_type == "ignored":
27         continue;
28
29       lines.append("%s: %s" % (field_type, value))
30
31   return '\n'.join(lines)
32
33
34 def ColumnNameToFieldType(column_name):
35   """Converts the given |column_name| to the corresponding AutofillField type.
36
37   |column_name| should be a string drawn from the column names of the
38   autofill_profiles table in the Chromium "Web Data" database.
39
40   """
41
42   column_name = column_name.lower()
43   field_type = "unknown"
44   if column_name in ["guid", "label", "country", "date_modified"]:
45     field_type = "ignored"
46   elif column_name == "first_name":
47     field_type = "NAME_FIRST"
48   elif column_name == "middle_name":
49     field_type = "NAME_MIDDLE"
50   elif column_name == "last_name":
51     field_type = "NAME_LAST"
52   elif column_name == "email":
53     field_type = "EMAIL_ADDRESS"
54   elif column_name == "company_name":
55     field_type = "COMPANY_NAME"
56   elif column_name == "address_line_1":
57     field_type = "ADDRESS_HOME_LINE1"
58   elif column_name == "address_line_2":
59     field_type = "ADDRESS_HOME_LINE2"
60   elif column_name == "city":
61     field_type = "ADDRESS_HOME_CITY"
62   elif column_name == "state":
63     field_type = "ADDRESS_HOME_STATE"
64   elif column_name == "zipcode":
65     field_type = "ADDRESS_HOME_ZIP"
66   elif column_name == "country_code":
67     field_type = "ADDRESS_HOME_COUNTRY"
68   elif column_name == "phone":
69     field_type = "PHONE_HOME_WHOLE_NUMBER"
70   else:
71     raise UnknownColumnNameException(column_name)
72
73   return field_type