From 383f929adb1ebdffbfa4fb28acca59d0d716da4d Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 13 Apr 2017 22:06:24 +0300 Subject: Drop yarnhelper.py, it is now useless --- yarnhelper.py | 73 ----------------------------------------------------- yarnhelper_tests.py | 33 ------------------------ 2 files changed, 106 deletions(-) delete mode 100644 yarnhelper.py delete mode 100644 yarnhelper_tests.py diff --git a/yarnhelper.py b/yarnhelper.py deleted file mode 100644 index 9b47fde..0000000 --- a/yarnhelper.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright 2016 Lars Wirzenius -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# =*= License: GPL-3+ =*= - - -import email -import imaplib -import os -import subprocess -import urlparse - -import requests -import yaml - - -class YarnHelper(object): - - def construct_aliased_http_request( - self, address, method, url, data=None, headers=None): - - if headers is None: - headers = {} - - parts = list(urlparse.urlparse(url)) - headers['Host'] = parts[1] - parts[1] = address - aliased_url = urlparse.urlunparse(parts) - - r = requests.Request(method, aliased_url, data=data, headers=headers) - return r.prepare() - - def http_get(self, address, url): # pragma: no cover - r = self.construct_aliased_http_request(address, 'GET', url) - s = requests.Session() - resp = s.send(r) - return resp.status_code, resp.content - - def get_password_with_pass(self, pass_home, pass_name): # pragma: no cover - p = subprocess.Popen( - ['env', 'HOME={}'.format(pass_home), 'pass', 'show', pass_name], - stdout=subprocess.PIPE) - stdout, stderr = p.communicate() - password = stdout.rstrip() - return password - - def iterate_mails_in_imap_mailbox( - self, address, user, password, callback, exp): # pragma: no cover - m = imaplib.IMAP4_SSL(address) - m.login(user, password) - m.select('INBOX', False) - typ, data = m.search(None, 'ALL') - for num in data[0].split(): - typ, data = m.fetch(num, '(RFC822)') - typ, text = data[0] - msg = email.message_from_string(text) - callback(m, num, msg) - if exp: - m.expunge() - m.close() - m.logout() diff --git a/yarnhelper_tests.py b/yarnhelper_tests.py deleted file mode 100644 index 40dc89e..0000000 --- a/yarnhelper_tests.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2016 Lars Wirzenius -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# =*= License: GPL-3+ =*= - - -import os -import unittest - -import yarnhelper - - -class HttpTests(unittest.TestCase): - - def test_constructs_aliased_request(self): - h = yarnhelper.YarnHelper() - server = 'new.example.com' - url = 'http://www.example.com/path' - r = h.construct_aliased_http_request(server, 'GET', url) - self.assertEqual(r.url, 'http://new.example.com/path') - self.assertEqual(r.headers['Host'], 'www.example.com') -- cgit v1.2.1