forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
46 lines (36 loc) · 1.3 KB
/
Copy pathfile.py
File metadata and controls
46 lines (36 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
"""
github3.gists.file
------------------
Module containing the logic for the GistFile object.
"""
from __future__ import unicode_literals
from ..models import GitHubCore
class GistFile(GitHubCore):
"""This represents the file object returned by interacting with gists.
It stores the raw url of the file, the file name, language, size and
content.
"""
def _update_attributes(self, attributes):
#: The raw URL for the file at GitHub.
self.raw_url = attributes.get('raw_url')
#: The name of the file.
self.filename = attributes.get('filename')
#: The name of the file.
self.name = attributes.get('filename')
#: The language associated with the file.
self.language = attributes.get('language')
#: The size of the file.
self.size = attributes.get('size')
#: The content of the file.
self.original_content = attributes.get('content')
def _repr(self):
return '<Gist File [{0}]>'.format(self.name)
def content(self):
"""Retrieve contents of file from key 'raw_url' if there is no
'content' key in Gist object.
"""
resp = self._get(self.raw_url)
if self._boolean(resp, 200, 404):
return resp.content
return None