def _prep_query(query): '''Prepare query for Wikipedia. Queries must capitalize (most) words, must be in unicode, and must not contain characters with accents (ü). For example, the query http://en.wikipedia.org/wiki/Olga_Kurylenko works, but the query http://en.wikipedia.org/wiki/olga_kurylenko does not. Args: query (str) : Original query Returns: Wikipedia-formatted query ''' # Ensure unicode query = UnicodeDammit(query).unicode # Replace accents (ü -> u) query = geotools.strip_accents(query) # Split and capitalize query terms terms = map( lambda s: s.capitalize() if s not in _no_cap else s, query.lower().split(' ') ) # Join query terms query = ' '.join(terms) # Return completed query return query