我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用github.InputFileContent()。
def create_private_gist(config, main_github_token, filename, content, description): g = Github(main_github_token) g_user = g.get_user() gist = g_user.create_gist(False, {filename: github.InputFileContent(content)}, description) # gists have a list of files associated with them, we just want the first one # gist.files = {'filename': GistFile(filename), ...} gist_file = [x for x in gist.files.values()][0] config["gist_raw_contents_url"] = gist_file.raw_url # The structure of the url is: # https://gist.githubusercontent.com/<username>/<gist guid>/raw/<file guid>/<filename.txt> # # Since we're only uploading one file and we want to make the URL as concise as possible, # it turns out we can actually trim off everything after /raw/ and it'll still give us what # we want. config["gist_raw_contents_url"] = config["gist_raw_contents_url"].split("/raw/")[0] + "/raw" print("[*] Private gist content at:") print("- %s" % config["gist_raw_contents_url"]) return config # Return the content that will placed in the private gist
def testCreateGist(self): gist = self.user.create_gist(True, {"foobar.txt": github.InputFileContent("File created by PyGithub")}, "Gist created by PyGithub") self.assertEqual(gist.description, "Gist created by PyGithub") self.assertEqual(list(gist.files.keys()), ["foobar.txt"]) self.assertEqual(gist.files["foobar.txt"].content, "File created by PyGithub")
def testCreateGistWithoutDescription(self): gist = self.user.create_gist(True, {"foobar.txt": github.InputFileContent("File created by PyGithub")}) self.assertEqual(gist.description, None) self.assertEqual(list(gist.files.keys()), ["foobar.txt"]) self.assertEqual(gist.files["foobar.txt"].content, "File created by PyGithub")
def testEditWithAllParameters(self): gist = self.g.get_gist("2729810") gist.edit("Description edited by PyGithub", {"barbaz.txt": github.InputFileContent("File also created by PyGithub")}) self.assertEqual(gist.description, "Description edited by PyGithub") self.assertEqual(gist.updated_at, datetime.datetime(2012, 5, 19, 7, 6, 10)) self.assertEqual(set(gist.files.keys()), set(["foobar.txt", "barbaz.txt"]))
def testRenameFile(self): gist = self.g.get_gist("5339374") self.assertEqual(list(gist.files.keys()), ["bar.txt"]) gist.edit(files={"bar.txt": github.InputFileContent(gist.files["bar.txt"].content, new_name="baz.txt")}) self.assertEqual(list(gist.files.keys()), ["baz.txt"])
def testCreateGist(self): gist = self.user.create_gist(True, {"foobar.txt": github.InputFileContent("File created by PyGithub")}, "Gist created by PyGithub") self.assertEqual(gist.description, "Gist created by PyGithub") self.assertEqual(gist.files.keys(), ["foobar.txt"]) self.assertEqual(gist.files["foobar.txt"].content, "File created by PyGithub")
def testCreateGistWithoutDescription(self): gist = self.user.create_gist(True, {"foobar.txt": github.InputFileContent("File created by PyGithub")}) self.assertEqual(gist.description, None) self.assertEqual(gist.files.keys(), ["foobar.txt"]) self.assertEqual(gist.files["foobar.txt"].content, "File created by PyGithub")
def testRenameFile(self): gist = self.g.get_gist("5339374") self.assertEqual(gist.files.keys(), ["bar.txt"]) gist.edit(files={"bar.txt": github.InputFileContent(gist.files["bar.txt"].content, new_name="baz.txt")}) self.assertEqual(gist.files.keys(), ["baz.txt"])