-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- console.log(arg1, arg2, …) - Require - Yak - few fixes
- Loading branch information
Showing
36 changed files
with
26,045 additions
and
24,322 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,63 @@ | |||
import urllib2 | |||
import hashlib | |||
|
|||
from puke.Console import * | |||
from puke.FileSystem import * | |||
|
|||
class Cache: | |||
|
|||
@staticmethod | |||
def fetchHttp(url): | |||
id = hashlib.sha256(url).hexdigest() | |||
|
|||
if Cache.check(id): | |||
return Cache.getPath(id) | |||
|
|||
try: | |||
handler = urllib2.build_opener() | |||
payload = handler.open(url).read() | |||
except Exception as error: | |||
console.error('HTTP fail %s (%s)' % (url, error)) | |||
|
|||
return Cache.write(id, payload, url) | |||
|
|||
|
|||
@staticmethod | |||
def write(id, payload, info = None): | |||
writefile(".pukecache/%s" % id, payload) | |||
|
|||
if info: | |||
writefile(".pukecache/%s.meta" % id, info) | |||
|
|||
return Cache.getPath(id) | |||
|
|||
@staticmethod | |||
def read(id): | |||
if not Cache.check(id): | |||
return None | |||
|
|||
return readfile(".pukecache/%s" % id) | |||
|
|||
@staticmethod | |||
def check(id): | |||
return fileexists(".pukecache/%s" % id) | |||
|
|||
@staticmethod | |||
def getPath(id): | |||
return ".pukecache/%s" % id | |||
|
|||
@staticmethod | |||
def getInfo(id): | |||
if not fileexists(".pukecache/%s.meta" % id): | |||
return "" | |||
|
|||
return readfile(".pukecache/%s.meta" % id) | |||
|
|||
|
|||
@staticmethod | |||
def clean(): | |||
try: | |||
rm(".pukecache/") | |||
return True | |||
except: | |||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.