class Test_str_functions(Test_url): def setUp(self): super().setUp() self.url = Chibi_url('http://a.4cdn.org/{board}/threads.json') def test_format(self): result = self.url.format(board='a') self.assertIsInstance(result, Chibi_url) self.assertEqual(result, "http://a.4cdn.org/a/threads.json") def test_format_with_params(self): url = self.url + {'param1': 'value1'} result = url.format(board='a') self.assertIsInstance(result, Chibi_url) self.assertEqual(result, "http://a.4cdn.org/a/threads.json?param1=value1") self.assertEqual(result.params, {'param1': 'value1'}) def test_format_shoudl_add_meta(self): url = self.url.format(board='a') self.assertEqual(url.kw, {'board': 'a'}) def test_format_should_conservate_meta(self): url = Chibi_url(self.url, cosa1="cosa1") url = url.format(board='a') self.assertEqual(url.kw, {'board': 'a', "cosa1": "cosa1"}) def test_format_should_conservate_response_class(self): url = Chibi_url(self.url, response_class=Mock) url = url.format(board='a') self.assertEqual(url.response_class, Mock)
def _format(args): block = args.block boot = f"{block}p1" root = f"{block}p2" Vfat(boot).run() Ext4(root).run() if args.version == "4": image_url = Chibi_url( 'http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-4-latest.tar.gz') else: raise NotImplementedError( f"la version de rasp {args.version} no esta implementada") image_path = args.backup_path + 'image' if not image_path.exists: image_path.mkdir() image = image_path + image_url.base_name if not image.exists: image = image_url.download(path=image_path) spell_card = Spell_card( block=args.block, mount_path=args.backup_path, ) Bsdtar('-xpf', image, '-C', spell_card.root).run() tmp_boot = spell_card.root + 'boot' + '*' tmp_boot.move(spell_card.boot)
def __init__(self, url=None, *args, parent=None, **kw): if url is None: url = self.url if not isinstance(url, Chibi_url): url = Chibi_url(url.strip()) self.url = url self.urls = [] self.processing_order = [] self.parent = parent for k, v in kw.items(): setattr(self, k, v)
class Test_download_lenna(TestCase): def setUp(self): self.download_folder = Chibi_temp_path() self.lenna_url = Chibi_url('http://www.lenna.org/len_std.jpg') def test_download_lenna(self): lenna = self.lenna_url.download(self.download_folder) self.assertTrue(lenna.exists) self.assertGreater(lenna.properties.size, 10000) def test_download_wiith_file_name(self): lenna = self.lenna_url.download(self.download_folder + 'helloooo_lenna.png') self.assertEqual(lenna.base_name, 'helloooo_lenna.png') self.assertTrue(lenna.exists) self.assertGreater(lenna.properties.size, 10000)
def __init__(self, url=None, *args, book=None, **kw): self.urls = [] if url is None: url = Chibi_url('https://nhentai.net') self.url = url self.enable_full_scan = False self.processing_order = [self.episode_class]
def append(self, url): result = super().append(url) if result: return result url = Chibi_url(url) if re_main.match(str(url.url)): self.enable_full_scan = True return result
class Test_methods(Test_url): def setUp(self): self.url = Chibi_url('http://ifconfig.me') def test_get(self): response = self.url.get() self.assertTrue(response) self.assertIsInstance(response, Response) self.assertTrue(response.is_text) self.assertIsInstance(response.native, str) self.assertTrue(response.native) def test_post(self): response = self.url.post() self.assertTrue(response) self.assertIsInstance(response, Response) self.assertTrue(response.is_json) self.assertIsInstance(response.native, Chibi_atlas) self.assertTrue(response.native)
class Test_headers(Test_url): def setUp(self): super().setUp() self.url = Chibi_url('http://a.4cdn.org/{board}/threads.json') def test_headers_by_default_should_be_a_empty_dict(self): self.assertIsInstance(self.url.headers, dict) self.assertEqual(self.url.headers, {}) def test_should_add_the_content_type(self): self.url.headers.content_type = 'application/json' self.assertEqual(self.url.headers.content_type, 'application/json') @patch('requests.get') def test_should_send_the_auth_using_get(self, requests): self.url.headers.content_type = 'application/json' self.url.get() self.assertEqual(requests.call_args[1]['headers'], self.url.headers) @patch('requests.post') def test_should_send_the_auth_using_post(self, requests): self.url.headers.content_type = 'application/json' self.url.post() self.assertEqual(requests.call_args[1]['headers'], self.url.headers) @patch('requests.post') def test_should_be_parse_data_with_content_type(self, requests): self.url.headers.content_type = 'application/json' self.url.post({'data': 'asdf'}) j = requests.call_args[0][1] self.assertEqual(j, '{"data": "asdf"}')
class Test_auth(Test_url): def setUp(self): super().setUp() self.url = Chibi_url('http://a.4cdn.org/{board}/threads.json') def test_when_add_a_auth_class_should_create_a_new_object(self): url_other = self.url + HTTPBasicAuth('some_user', 'some_password') self.assertIsNot(self.url, url_other) self.assertEqual(str(self.url), str(url_other)) self.assertIsNotNone(url_other.auth) self.assertIsNone(self.url.auth) def test_using_iadd_should_add_iternaly_the_auth(self): auth = HTTPBasicAuth('some_user', 'some_password') self.url += auth self.assertIsNotNone(self.url.auth) self.assertEqual(self.url.auth, auth) def test_add_parmas_to_the_url_shoudl_carry_the_auth(self): auth = HTTPBasicAuth('some_user', 'some_password') self.url += auth other_url = self.url + {'param1': 'value1'} self.assertNotEqual(self.url, other_url) self.assertEqual(self.url.auth, other_url.auth) @patch('requests.get') def test_should_send_the_auth_using_get(self, requests): self.url += HTTPBasicAuth('some_user', 'some_password') self.url.get() self.assertEqual(requests.call_args[1]['auth'], self.url.auth) @patch('requests.post') def test_should_send_the_auth_using_post(self, requests): self.url += HTTPBasicAuth('some_user', 'some_password') self.url.post() self.assertEqual(requests.call_args[1]['auth'], self.url.auth)
class Find_pdfs(Response): def parse_native(self): native = super().parse_native() links = map( lambda a: a.attrs.get('href', ''), native.find_all('a'), ) links = filter(lambda a: a.endswith('.pdf'), links) links = map(lambda link: Pdf_url(self.url + link), links) links = filter(lambda link: link.base_name.startswith('Tabla_casos'), links) return list(links) class Pdf_url(Chibi_url): def get(self, *args, **kw): temp_dir = Chibi_temp_path() pdf = self.download(temp_dir) data = pdf_to_dicts(pdf) response = Response(response=object(), url=self) response._native = data return response list_of_pdf = Chibi_url( "https://www.gob.mx/salud/documentos/" "coronavirus-covid-19-comunicado-tecnico-diario-238449", response_class=Find_pdfs)
def setUp(self): self.url = Chibi_url('http://ifconfig.me')
from chibi_requests import Chibi_url well_know = Chibi_url("https://{domain}/.well-known/jwks.json") auth_token = Chibi_url('https://{domain}/oauth/token') user = Chibi_url('https://{domain}/api/v2/users/{user_id}') user_info = Chibi_url('https://{domain}/userinfo')
def setUp(self): self.download_folder = Chibi_temp_path() self.lenna_url = Chibi_url('http://www.lenna.org/len_std.jpg')
def setUp(self): self.url = Chibi_url("https://google.com")
def parse_info(self): image = Chibi_url( self.soup.find("section", id="image-container").img.get('src')) return Chibi_atlas(image=image, )
# -*- coding: utf-8 -*- from chibi_requests import Chibi_url from chibi_gob_mx.response import Catalog catalog = Chibi_url('https://api.datos.gob.mx/v1/api-catalog', response_class=Catalog)
def setUp(self): super().setUp() self.response_class = Mock self.url = Chibi_url("https://google.com", response_class=self.response_class)
def test_meta_with_values(self): url = Chibi_url("https://www.google.com", cosa1="cosa1", cosa2="cosa2") self.assertEqual(url.kw, {'cosa1': 'cosa1', 'cosa2': 'cosa2'})
def test_format_should_conservate_meta(self): url = Chibi_url(self.url, cosa1="cosa1") url = url.format(board='a') self.assertEqual(url.kw, {'board': 'a', "cosa1": "cosa1"})
class Meta: unknown = INCLUDE @pre_load(pass_many=True) def pre_load(self, data, **kw): threads = reduce((lambda x, y: x + y), (page['threads'] for page in data)) return threads class Response_threads(Response): serializer = Four_chan_schema threads = Chibi_url('http://a.4cdn.org/{board}/threads.json', response_class=Response_threads).format(board='w') class Test_four_chan_with_schema(TestCase): def test_should_work(self): response = threads.get() native = response.native self.assertIsInstance(native, list) self.assertTrue(native) for n in native: self.assertIn('id', n) self.assertIsInstance(n['id'], int) self.assertIn('replies', n) self.assertIsInstance(n['replies'], int)
def test_format_should_conservate_response_class(self): url = Chibi_url(self.url, response_class=Mock) url = url.format(board='a') self.assertEqual(url.response_class, Mock)
def _parse_cover(self): container = self.soup.find("div", id="bigcontainer") url = Chibi_url(container.img.attrs["data-src"]) # url += self.url.session return url
def setUp(self): super().setUp() self.url = Chibi_url('http://a.4cdn.org/{board}/threads.json')
from chibi_requests import Chibi_url precios = Chibi_url('http://api.datos.gob.mx/v1/profeco.precios')
def get_repo_name(url): url = Chibi_url(url) name = url.base_name.rsplit('.git', 1)[0]