def create_dictionaries_and_models(macros, sentences_dir, dictionaries_dir, models_dir): if not ('system' in macros['shortcuts'].values()): macros['shortcuts']['system'] = 'system' browser = mechanize.Browser() for filename in macros['shortcuts'].values(): browser.open("http://www.speech.cs.cmu.edu/tools/lmtool-new.html") browser.select_form(nr=0) browser.form.add_file(open(sentences_dir + filename), 'text/plain', sentences_dir + filename) browser.submit() for link in browser.links(): if link.url.endswith(".dic"): mechanize.urlretrieve(link.base_url + link.url, dictionaries_dir + filename + ".dic") if link.url.endswith(".lm"): mechanize.urlretrieve(link.base_url + link.url, models_dir + filename + ".lm")
def test_urlretrieve(self): timeout_log = self._monkey_patch_socket() timeout = 10. url = urljoin(self.uri, "/mechanize/") verif = CallbackVerifier(self) filename, headers = mechanize.urlretrieve(url, reporthook=verif.callback, timeout=timeout) timeout_log.stop() self._check_retrieve(url, filename, headers) timeout_log.verify(timeout)