40 engine = OpenSearchEngine() |
40 engine = OpenSearchEngine() |
41 |
41 |
42 while not self.isStartElement() and not self.atEnd(): |
42 while not self.isStartElement() and not self.atEnd(): |
43 self.readNext() |
43 self.readNext() |
44 |
44 |
45 if self.name() != "OpenSearchDescription" or \ |
45 if ( |
46 self.namespaceUri() != "http://a9.com/-/spec/opensearch/1.1/": |
46 self.name() != "OpenSearchDescription" or |
|
47 self.namespaceUri() != "http://a9.com/-/spec/opensearch/1.1/" |
|
48 ): |
47 self.raiseError(QCoreApplication.translate( |
49 self.raiseError(QCoreApplication.translate( |
48 "OpenSearchReader", |
50 "OpenSearchReader", |
49 "The file is not an OpenSearch 1.1 file.")) |
51 "The file is not an OpenSearch 1.1 file.")) |
50 return engine |
52 return engine |
51 |
53 |
64 elif self.name() == "Url": |
66 elif self.name() == "Url": |
65 type_ = self.attributes().value("type") |
67 type_ = self.attributes().value("type") |
66 url = self.attributes().value("template") |
68 url = self.attributes().value("template") |
67 method = self.attributes().value("method") |
69 method = self.attributes().value("method") |
68 |
70 |
69 if type_ == "application/x-suggestions+json" and \ |
71 if ( |
70 engine.suggestionsUrlTemplate(): |
72 type_ == "application/x-suggestions+json" and |
|
73 engine.suggestionsUrlTemplate() |
|
74 ): |
71 continue |
75 continue |
72 |
76 |
73 if (not type_ or |
77 if ( |
74 type_ == "text/html" or |
78 (not type_ or |
75 type_ == "application/xhtml+xml") and \ |
79 type_ == "text/html" or |
76 engine.searchUrlTemplate(): |
80 type_ == "application/xhtml+xml") and |
|
81 engine.searchUrlTemplate() |
|
82 ): |
77 continue |
83 continue |
78 |
84 |
79 if not url: |
85 if not url: |
80 continue |
86 continue |
81 |
87 |
82 parameters = [] |
88 parameters = [] |
83 |
89 |
84 self.readNext() |
90 self.readNext() |
85 |
91 |
86 while not (self.isEndElement() and self.name() == "Url"): |
92 while not (self.isEndElement() and self.name() == "Url"): |
87 if not self.isStartElement() or \ |
93 if ( |
88 (self.name() != "Param" and self.name() != "Parameter"): |
94 not self.isStartElement() or |
|
95 (self.name() != "Param" and |
|
96 self.name() != "Parameter") |
|
97 ): |
89 self.readNext() |
98 self.readNext() |
90 continue |
99 continue |
91 |
100 |
92 key = self.attributes().value("name") |
101 key = self.attributes().value("name") |
93 value = self.attributes().value("value") |
102 value = self.attributes().value("value") |
100 |
109 |
101 if type_ == "application/x-suggestions+json": |
110 if type_ == "application/x-suggestions+json": |
102 engine.setSuggestionsUrlTemplate(url) |
111 engine.setSuggestionsUrlTemplate(url) |
103 engine.setSuggestionsParameters(parameters) |
112 engine.setSuggestionsParameters(parameters) |
104 engine.setSuggestionsMethod(method) |
113 engine.setSuggestionsMethod(method) |
105 elif not type_ or \ |
114 elif ( |
106 type_ == "text/html" or \ |
115 not type_ or |
107 type_ == "application/xhtml+xml": |
116 type_ == "text/html" or |
|
117 type_ == "application/xhtml+xml" |
|
118 ): |
108 engine.setSearchUrlTemplate(url) |
119 engine.setSearchUrlTemplate(url) |
109 engine.setSearchParameters(parameters) |
120 engine.setSearchParameters(parameters) |
110 engine.setSearchMethod(method) |
121 engine.setSearchMethod(method) |
111 |
122 |
112 elif self.name() == "Image": |
123 elif self.name() == "Image": |
113 engine.setImageUrl(self.readElementText()) |
124 engine.setImageUrl(self.readElementText()) |
114 |
125 |
115 if engine.name() and \ |
126 if ( |
116 engine.description() and \ |
127 engine.name() and |
117 engine.suggestionsUrlTemplate() and \ |
128 engine.description() and |
118 engine.searchUrlTemplate() and \ |
129 engine.suggestionsUrlTemplate() and |
119 engine.imageUrl(): |
130 engine.searchUrlTemplate() and |
|
131 engine.imageUrl() |
|
132 ): |
120 break |
133 break |
121 |
134 |
122 return engine |
135 return engine |