def _GetAspellIndex(root=None): RAD = RemoteAspellDictionary response, content = urlcacheopen(httpjoin(root or RAD.ROOT,'0index.html'), decode=False) if not response.ok: print 'Unhandled HTTP response code: %r' % response return () soup = soupify(content) results = {} for row in soup.find('a', attrs=dict(name='0.50')).findAllNext('tr'): contents = row.findAll('td') if len(contents) == 4: id, name_english, name_native, dictionary_path = contents id = id.find(href=True) if id is None: continue id = id['href'] if id not in results: dictionary_path = dictionary_path.find(href=True) if dictionary_path is None: continue dictionary_path = dictionary_path['href'] name_english = name_english.renderContents(None).decode('xml') name_native = name_native.renderContents(None).decode('xml').strip() or None results[id] = RAD(id, name_english, name_native, id, dictionary_path) return results.values()
def _GetAspellIndex(root=None): RAD = RemoteAspellDictionary response, content = urlcacheopen(httpjoin(root or RAD.ROOT, '0index.html'), decode=False) if not response.ok: print 'Unhandled HTTP response code: %r' % response return () soup = soupify(content) results = {} for row in soup.find('a', attrs=dict(name='0.50')).findAllNext('tr'): contents = row.findAll('td') if len(contents) == 4: id, name_english, name_native, dictionary_path = contents id = id.find(href=True) if id is None: continue id = id['href'] if id not in results: dictionary_path = dictionary_path.find(href=True) if dictionary_path is None: continue dictionary_path = dictionary_path['href'] name_english = name_english.renderContents(None).decode('xml') name_native = name_native.renderContents(None).decode( 'xml').strip() or None results[id] = RAD(id, name_english, name_native, id, dictionary_path) return results.values()
def compose_link( self, email='', subject='', body='', cc='', bcc='', ): kw = dict() if email: kw['to'] = email for name in 'subject body cc bcc'.split(): if vars()[name]: kw[name] = vars()[name] if kw: kw['mailto'] = 1 kw['n'] = '123456789' url = util.UrlQuery(util.httpjoin(self.base_url, '/mail/EditMessageLight.aspx'), fti='yes', **kw) log.info('compose_link returning: %s', url) return url
def compose(self, *a, **k): use_client = k.pop('use_client', True) url = self.compose_link(*a, **k) if self.mailclient and use_client and not url.startswith('http'): self._goto_hotmail_url(url, error = lambda *a: self.start_client_email(url, use_client = False)) else: return util.httpjoin(self.base_url, url, True)
def _send_email_form(self, to, subject, body, cc, bcc, callback=None): cfg = self.HM.Network.configuration import ClientForm form = ClientForm.HTMLForm(util.UrlQuery(util.httpjoin( self.inbox_url, '/mail/SendMessageLight.aspx'), _ec=1, n=ntok()), method="POST", request_class=self.RequestFactory) form.new_control('hidden', '__VIEWSTATE', {'value': ''}) form.new_control('hidden', cfg.CanaryToken, {'value': cfg.CanaryValue}) form.new_control('hidden', 'MsgPriority', {'value': '0'}) form.new_control('hidden', 'ToolbarActionItem', {'value': 'SendMessage'}) form.new_control('hidden', 'InfoPaneActionItem', {'value': ''}) form.new_control('hidden', 'folderCache', {'value': ''}) form.new_control('hidden', 'fDraftId', {'value': ''}) form.new_control('hidden', 'fMsgSentState', {'value': 'NOACTION'}) form.new_control('hidden', 'IsSpellChecked', {'value': 'false'}) form.new_control('hidden', 'fFrom', {'value': self.username}) form.new_control('hidden', 'cpselectedAutoCompleteTo', {'value': '[]'}) form.new_control('hidden', 'fTo', {'value': '"" <%s>;' % to}) form.new_control('hidden', 'cpselectedAutoCompleteCc', {'value': ''}) form.new_control('hidden', 'fCc', {'value': cc}) form.new_control('hidden', 'cpselectedAutoCompleteBcc', {'value': ''}) form.new_control('hidden', 'fBcc', {'value': bcc}) form.new_control('hidden', 'fSubject', {'value': subject}) form.new_control('hidden', 'fAttachment_data', {'value': ''}) form.new_control('hidden', 'isFirstPL', {'value': ''}) form.new_control('hidden', 'RTE_MessageType', {'value': 'PlainText'}) form.new_control('hidden', 'fMessageBody', {'value': body}) request = form.click() log.info('Request obj = %r, vars = %r', request, vars(request)) def check_success_send(resp): if resp is None: # assume it worked? return callback.success() data = resp.read() if 'SentMailConfirmation' in data: log.info('sent email!') callback.success() else: log.info('failed to send email: %r', data) callback.error() def check_error_send(exc): log.info('failed to send email: %r', exc) callback.error() util.threaded(self.open)(request, success=check_success_send, error=check_error_send)
def compose(self, *a, **k): use_client = k.pop('use_client', True) url = self.compose_link(*a, **k) if self.mailclient and use_client and not url.startswith('http'): self._goto_hotmail_url(url, error=lambda *a: self.start_client_email( url, use_client=False)) else: return util.httpjoin(self.base_url, url, True)
def _send_email_form(self, to, subject, body, cc, bcc, callback = None): cfg = self.HM.Network.configuration import ClientForm form = ClientForm.HTMLForm(util.UrlQuery(util.httpjoin(self.inbox_url, '/mail/SendMessageLight.aspx'), _ec = 1, n = ntok()), method="POST", request_class = self.RequestFactory) form.new_control('hidden', '__VIEWSTATE', {'value' : ''}) form.new_control('hidden', cfg.CanaryToken, {'value' : cfg.CanaryValue}) form.new_control('hidden', 'MsgPriority', {'value' : '0'}) form.new_control('hidden', 'ToolbarActionItem', {'value' : 'SendMessage'}) form.new_control('hidden', 'InfoPaneActionItem', {'value' : ''}) form.new_control('hidden', 'folderCache', {'value' : ''}) form.new_control('hidden', 'fDraftId', {'value' : ''}) form.new_control('hidden', 'fMsgSentState', {'value' : 'NOACTION'}) form.new_control('hidden', 'IsSpellChecked', {'value' : 'false'}) form.new_control('hidden', 'fFrom', {'value' : self.username}) form.new_control('hidden', 'cpselectedAutoCompleteTo', {'value' : '[]'}) form.new_control('hidden', 'fTo', {'value' : '"" <%s>;' % to}) form.new_control('hidden', 'cpselectedAutoCompleteCc', {'value' : ''}) form.new_control('hidden', 'fCc', {'value' : cc}) form.new_control('hidden', 'cpselectedAutoCompleteBcc', {'value' : ''}) form.new_control('hidden', 'fBcc', {'value' : bcc}) form.new_control('hidden', 'fSubject', {'value' : subject}) form.new_control('hidden', 'fAttachment_data', {'value' : ''}) form.new_control('hidden', 'isFirstPL', {'value' : ''}) form.new_control('hidden', 'RTE_MessageType', {'value' : 'PlainText'}) form.new_control('hidden', 'fMessageBody', {'value' : body}) request = form.click() log.info('Request obj = %r, vars = %r', request, vars(request)) def check_success_send(resp): if resp is None: # assume it worked? return callback.success() data = resp.read() if 'SentMailConfirmation' in data: log.info('sent email!') callback.success() else: log.info('failed to send email: %r', data) callback.error() def check_error_send(exc): log.info('failed to send email: %r', exc) callback.error() util.threaded(self.open)(request, success = check_success_send, error = check_error_send)
def post_data(self, login_url, post_url, data): with closing(self.http.open(login_url)) as resp: redirect = resp.content assert 'window.location.replace' in redirect redirect_url = self.check_for_redirect(redirect) if redirect_url is None: raise Exception("Expected redirect url, but it wasn't there. Data = %r", redirect) with closing(self.http.open(redirect_url)): pass with closing(self.http.open(util.httpjoin(redirect_url, post_url), data)): pass
def post_data(self, login_url, post_url, data): with closing(self.http.open(login_url)) as resp: redirect = resp.content assert 'window.location.replace' in redirect redirect_url = self.check_for_redirect(redirect) if redirect_url is None: raise Exception( "Expected redirect url, but it wasn't there. Data = %r", redirect) with closing(self.http.open(redirect_url)): pass with closing( self.http.open(util.httpjoin(redirect_url, post_url), data)): pass
def compose_link(self, email='', subject='', body='', cc='',bcc='',): kw = dict() if email: kw['to'] = email for name in 'subject body cc bcc'.split(): if vars()[name]: kw[name] = vars()[name] if kw: kw['mailto'] = 1 kw['n'] = '123456789' url = util.UrlQuery(util.httpjoin(self.base_url, '/mail/EditMessageLight.aspx'), fti='yes', **kw) log.info('compose_link returning: %s', url) return url
def DownloadAllDictionaries(infodict, towhere, root=None): if root is None: root = RemoteAspellDictionary.ROOT for id in infodict: name = infodict[id]['name_english'] bz2path = infodict[id]['location'] localpath = path(towhere) / bz2path bz2path = httpjoin(root,bz2path) localpath = localpath.expand() print ('Downloading %s (%s) from %s to %s... ' % (name, id, bz2path, localpath)), response, content = urlcacheopen(bz2path) print response.reason if response.ok: if not localpath.parent.isdir(): localpath.parent.makedirs() with open(localpath, 'wb') as f: f.write(content)
def DownloadAllDictionaries(infodict, towhere, root=None): if root is None: root = RemoteAspellDictionary.ROOT for id in infodict: name = infodict[id]['name_english'] bz2path = infodict[id]['location'] localpath = path(towhere) / bz2path bz2path = httpjoin(root, bz2path) localpath = localpath.expand() print('Downloading %s (%s) from %s to %s... ' % (name, id, bz2path, localpath)), response, content = urlcacheopen(bz2path) print response.reason if response.ok: if not localpath.parent.isdir(): localpath.parent.makedirs() with open(localpath, 'wb') as f: f.write(content)
def get_directory(self, root=None): return httpjoin(root or self.ROOT, self.directory)
def get_package_path(self, root=None): return httpjoin(root or self.ROOT, self.package_path)