1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 Parking place handling.
24 """
25 from geom import Point
26 from utils import get_from_id
27
28
29
30
31
33 """
34 A C{Parking} object sub-classes L{Point} and adds a description to describe
35 a parking place.
36
37 @ivar description: description of the parking place
38 @type description: C{string}
39 """
40 - def __init__(self, id, description, lat, lon):
41 """
42 Save the passed-in data.
43
44 @param id: id of the parking place
45 @type id: C{string}
46 @param description: description of the parking place
47 @type description: C{string}
48 @param lat: latitude of parking place
49 @type lat: C{float}
50 @param lon: longitude of parking place
51 @type lon: C{float}
52 """
53 Point.__init__(self, lat, lon, id=id)
54 self.description = description
55
57 """
58 Take the C{Element} for a parking place and turn it into a L{Parking}
59 object.
60
61 @param xml_parking: C{Element} for a parking place
62 @type xml_parking: C{Element}
63
64 @return: L{Parking} object
65 @rtype: L{Parking}
66 """
67 return Parking(id = xml_parking.attrib['id'],
68 description = xml_parking.findtext('description'),
69 lat = xml_parking.findtext('lat'),
70 lon = xml_parking.findtext('lon'))
71
73 """
74 Get all the parking place elements in the given C{Element} tree and create
75 a list of them with L{Parking} objects.
76
77 @param xml_tree: root of C{Element} tree that has parking places in it
78 @type xml_tree: C{Element} or C{ElementTree}
79
80 @return: parking places in a list and a dictionary
81 @rtype: (C{list},C{dict}) of L{Parking}
82 """
83 xml_parking_places = xml_tree.findall('parking')
84 parking_list = []
85 parking_dict = {}
86 for xml_parking in xml_parking_places:
87 new_parking = _parse_parking_xml(xml_parking)
88 parking_list.append(new_parking)
89 parking_dict[new_parking.id] = new_parking
90
91 return parking_list, parking_dict
92
93
94
95
96
98 """
99 Process the parking place reference for the give ride and generate a full
100 L{Parking} object for it.
101
102 @param xml_ride: root of C{Element} tree for this ride
103 @type xml_ride: C{Element}
104 @param xml_parking_places: C{list} of C{Element} trees for parking places
105 @type xml_parking_places: C{list} of C{Element} trees
106
107 @return: L{Parking} object for the ride
108 @rtype: L{Parking}
109 """
110 xml_ride_parking = xml_ride.find('parking_ref')
111 xml_parking = get_from_id(xml_parking_places, xml_ride_parking.attrib['id'])
112 ret = _parse_parking_xml(xml_parking)
113 ret.description = " ".join(ret.description.split())
114 return ret
115