コード例 #1
0
def shield(package, type):
	if type == "title":
		url = "https://img.shields.io/badge/ContentDB-{}-{}" \
			.format(urlescape(package.title), urlescape("#375a7f"))
	elif type == "downloads":
		#api_url = abs_url_for("api.package", author=package.author.username, name=package.name)
		api_url = "https://content.minetest.net" + url_for("api.package", author=package.author.username, name=package.name)
		url = "https://img.shields.io/badge/dynamic/json?color={}&label=ContentDB&query=downloads&suffix=+downloads&url={}" \
			.format(urlescape("#375a7f"), urlescape(api_url))
	else:
		abort(404)

	return redirect(url)
コード例 #2
0
def filter_soup(soup, target=None, page=None):
    """replace underscores with dashes in h1,h2,etc. for backwards compatibility"""

    badge_links = soup.find_all(name="a", title=BADGE_REGEX)

    for b in badge_links:
        badge_label = b.string
        if not badge_label:
            badge_label = "".join(b.strings)
        if not badge_label:
            logging.warning("Badge link with no string: %s" % b)
            continue
        if ":" not in badge_label:
            logging.warning("Badge link specified with no ':' in link: %s" % b.string)
            continue

        badge_color = BADGE_REGEX.match(b["title"]).group(1).lower()
        badge_left, badge_right = [urlescape(s.strip()).replace("-","--")
                                   for s in badge_label.split(":", 1)]
        badge_url = "https://img.shields.io/badge/%s-%s-%s.svg" % (
                    badge_left, badge_right, badge_color)

        img = soup.new_tag("img", src=badge_url, alt=badge_label)
        img["class"]="dactyl_badge"
        b.clear()
        b.append(img)
        b["title"] = badge_label
        if not b["href"]:
            del b["href"]
コード例 #3
0
ファイル: filter_badges.py プロジェクト: sirpenev/dactyl
def filter_soup(soup, **kwargs):
    """replace underscores with dashes in h1,h2,etc. for backwards compatibility"""

    badge_links = soup.find_all(name="a", title=BADGE_REGEX)

    for b in badge_links:
        badge_label = b.string
        if not badge_label:
            badge_label = "".join(b.strings)
        if not badge_label:
            logging.warning("Badge link with no string: %s" % b)
            continue
        if ":" not in badge_label:
            logging.warning("Badge link specified with no ':' in link: %s" %
                            b.string)
            continue

        badge_color = BADGE_REGEX.match(b["title"]).group(1).lower()
        badge_left, badge_right = [
            urlescape(s.strip()).replace("-", "--")
            for s in badge_label.split(":", 1)
        ]
        badge_url = "https://img.shields.io/badge/%s-%s-%s.svg" % (
            badge_left, badge_right, badge_color)

        img = soup.new_tag("img", src=badge_url, alt=badge_label)
        img["class"] = "dactyl_badge"
        b.clear()
        b.append(img)
        b["title"] = badge_label
        if not b["href"]:
            del b["href"]
コード例 #4
0
ファイル: test_md_api.py プロジェクト: clarin-eric/pyFF
    def test_api_resources(self):
        """"""
        with RequestsInterceptor(self.app, host='127.0.0.1', port=80) as url:
            r1 = requests.post(f'{url}/api/call/update')
            assert r1.status_code == 200

            r2 = requests.get(f'{url}/api/resources')
            assert 'application/json' in r2.headers['content-type']
            # assert "version" in r.text
            assert r2.status_code == 200
            data = r2.json()

            expected = [{
                'Resource':
                f'file://{self.test01}',
                'HTTP Response Headers': {
                    'Content-Length': 3633
                },
                'Status Code':
                '200',
                'Reason':
                None,
                'State':
                'Ready',
                'Entities': ['https://idp.example.com/saml2/idp/metadata.php'],
                'Validation Errors': {},
                'Expiration Time':
                data[0]['Expiration Time'],  # '2021-04-14 15:21:33.150742',
                'Expired':
                False,
                'Valid':
                True,
                'Parser':
                'SAML',
                'Last Seen':
                data[0]['Last Seen'],  # '2021-04-14 14:21:33.150781',
            }]
            assert data == expected

            # Now check the timestamps
            now = datetime.now(tz=timezone.utc)

            exp = datetime.fromisoformat(data[0]['Expiration Time'])
            assert (exp - now).total_seconds() > 3590
            assert (exp - now).total_seconds() < 3610

            last_seen = datetime.fromisoformat(data[0]['Last Seen'])
            assert (last_seen - now).total_seconds() < 60

            assert os.path.exists(
                os.path.join(config.local_copy_dir,
                             urlescape(f'file://{self.test01}')))
コード例 #5
0
ファイル: utils.py プロジェクト: terencehonles/mailarchive
    from urlparse import urlsplit


try:
    basestring
except NameError:
    basestring = str

try:
    unicode
except NameError:
    unicode = str


# these really should not have to be specified at all
DEFAULT_FORMATTERS = {"url-param-value": lambda s: urlescape(s.encode("utf-8"))}


class Path(unicode):
    "a path can either be a package resource or an actual file system path"

    def __new__(cls, value="", pkg_resource=False):
        return super(Path, cls).__new__(cls, value)

    def __init__(self, value="", pkg_resource=False):
        self.pkg_resource = pkg_resource

    def __add__(self, other):
        if self.pkg_resource:
            return Path(str(self) + "/" + other, pkg_resource=True)
        else:
コード例 #6
0
 def local_copy_fn(self):
     return os.path.join(config.local_copy_dir, urlescape(self.url))