microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
minestarks/circuit-magic

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/pip/qsharp/_http.py

34lines · modecode

1# Copyright (c) Microsoft Corporation.
2# Licensed under the MIT License.
3
4"""
5_http.py
6
7This module provides HTTP utility functions for interacting with
8GitHub repositories.
9"""
10
11
12def fetch_github(owner: str, repo: str, ref: str, path: str) -> str:
13 """
14 Fetches the content of a file from a GitHub repository.
15
16 Args:
17 owner (str): The owner of the GitHub repository.
18 repo (str): The name of the GitHub repository.
19 ref (str): The reference (branch, tag, or commit) of the repository.
20 path (str): The path to the file within the repository.
21
22 Returns:
23 str: The content of the file as a string.
24
25 Raises:
26 urllib.error.HTTPError: If there is an error fetching the file from GitHub.
27 urllib.error.URLError: If there is an error with the URL.
28 """
29
30 import urllib
31
32 path_no_leading_slash = path[1:] if path.startswith("/") else path
33 url = f"https://raw.githubusercontent.com/{owner}/{repo}/{ref}/{path_no_leading_slash}"
34 return urllib.request.urlopen(url).read().decode("utf-8-sig")
35