forked from semk/GitFS
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGFile.py
84 lines (66 loc) · 2.2 KB
/
GFile.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python2
# GFile.py -*- python -*-
# Copyright (c) 2013 Ross Biro
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
"""GFile implements a file like object that allows for putting bi-directional filters
into the stream to modify the input/output, similiar to unix shell pipes.
"""
import os
class GFile(object):
@staticmethod
def open(name, mode='r', buffering=-1):
return GFile(open(name, mode, buffering))
def __init__(self, f):
self.closed = False
self.encoding = None
self.errors = None
self.mode = None
self.name = None
self.newlines = None
self.softspace = 0
self.file = f
def close(self):
self.file.close()
def flush(self):
self.file.flush()
def fileno(self):
return self.file.fileno()
def isatty(self):
return self.file.isatty()
def next(self):
l = self.readline()
if l != '':
return l
raise StopIteration
def read(self, size=None):
return self.file.read(size)
def readline(self, size=None):
return self.file.readline(size)
def readlines(self, sizehint=None):
return self.file.readlines(sizehint)
def seek(self, offset, whence=os.SEEK_SET):
return self.file.seek(offset, whence)
def tell(self):
return self.file.tell()
def truncate(self):
return self.file.truncate()
def write(self, str):
return self.file.write(str)
def writelines(self, seq):
return self.file.writelines(seq)
def writeln(self, str):
return self.file.write(str+'\n')