| 920 | LATEST = "latest" # Sort results by most recent. |
| 921 | |
| 922 | class Result(dict): |
| 923 | |
| 924 | def __init__(self, url): |
| 925 | """ An item in a list of results returned by SearchEngine.search(). |
| 926 | All dictionary entries are available as unicode string attributes. |
| 927 | - url : the URL of the referred web content, |
| 928 | - title : the title of the content at the URL, |
| 929 | - text : the content text, |
| 930 | - language: the content language, |
| 931 | - author : for news items and images, the author, |
| 932 | - date : for news items, the publication date. |
| 933 | """ |
| 934 | dict.__init__(self) |
| 935 | self.url = url |
| 936 | |
| 937 | @property |
| 938 | def description(self): |
| 939 | return self.text # Backwards compatibility. |
| 940 | |
| 941 | def download(self, *args, **kwargs): |
| 942 | """ Download the content at the given URL. |
| 943 | By default it will be cached - see URL.download(). |
| 944 | """ |
| 945 | return URL(self.url).download(*args, **kwargs) |
| 946 | |
| 947 | def __getattr__(self, k): |
| 948 | return self.get(k, u"") |
| 949 | def __getitem__(self, k): |
| 950 | return self.get(k, u"") |
| 951 | def __setattr__(self, k, v): |
| 952 | dict.__setitem__(self, u(k), v is not None and u(v) or u"") # Store strings as unicode. |
| 953 | def __setitem__(self, k, v): |
| 954 | dict.__setitem__(self, u(k), v is not None and u(v) or u"") |
| 955 | |
| 956 | def setdefault(self, k, v): |
| 957 | dict.setdefault(self, u(k), u(v)) |
| 958 | def update(self, *args, **kwargs): |
| 959 | map = dict() |
| 960 | map.update(*args, **kwargs) |
| 961 | dict.update(self, [(u(k), u(v)) for k, v in map.items()]) |
| 962 | |
| 963 | def __repr__(self): |
| 964 | return "Result(%s)" % dict.__repr__(self) |
| 965 | |
| 966 | class Results(list): |
| 967 |
no outgoing calls
no test coverage detected
searching dependent graphs…