本文整理汇总了Python中tempfile.NamedTemporaryFile.readline方法的典型用法代码示例。如果您正苦于以下问题:Python NamedTemporaryFile.readline方法的具体用法?Python NamedTemporaryFile.readline怎么用?Python NamedTemporaryFile.readline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tempfile.NamedTemporaryFile
的用法示例。
在下文中一共展示了NamedTemporaryFile.readline方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _regread
# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import readline [as 别名]
def _regread(self,path):
"""Read contents of given key from the registry.
The result is a generator of (key,name,data,type) tuples. For
the keys themselves each of name, data and type will be None.
"""
tf = NamedTemporaryFile()
self._run_regedit("/E",tf.name,path)
tf.seek(0)
tf.readline()
(key,name,data,type) = (None,None,None,None)
for ln in tf:
if not ln:
continue
if ln.startswith("["):
key = ln.strip().strip("[]").strip("\"")
(name,data,type) = (None,None,None)
else:
val_re = r'^"?(\@|[^"]+)"?="?(([a-zA-Z0-9\(\)]+:)?)([^"]+)"?$'
m = re.match(val_re,ln.strip())
if not m:
continue
(name,type,_,data) = m.groups()
if name == "@":
name = ""
type = _unmap_type(type)
data = _unmap_data(data,type)
yield (key,name,data,type)
示例2: createBlogData
# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import readline [as 别名]
def createBlogData(blogFile=None):
if blogFile == None:
# edit temp blog data file
blogFile = NamedTemporaryFile(suffix='.txt', prefix='blogger_py')
editor = os.environ.get('EDITOR', Editor)
stat = os.spawnlp(os.P_WAIT, editor, editor, blogFile.name)
if stat != 0:
raise EditError, 'edit tempfile failed: %s %s' % \
(editor, blogFile.name)
# read blog data from temp file, publish a public post.
title = blogFile.readline().rstrip('\r\n')
label = blogFile.readline().strip()
if label == '':
_title = title.split(':') # title == 'LABEL: string'
if len(_title) >= 2:
label = _title[0]
content = blogFile.read()
_parts = docutils.core.publish_parts(source=content, writer_name='html')
body = _parts['body']
title = title.decode('utf-8')
saveBlogFile(blogFile.name)
blogFile.close() # blogFile will delete automatically
return title, body, label
示例3: Gtk2_GetSaveFilename
# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import readline [as 别名]
def Gtk2_GetSaveFilename(master, name, title, icon, **kw):
''' Calls Gnome open file dialog.
Parameteres:
master - parent window
name - application name
title - dialog title
**kw:
initialdir - absolute path to initial dir
initialfile - file name
Returns: tuple of utf8 and system encoded file names
'''
initialdir = check_initialdir(kw['initialdir'])
initialfile = ''
if kw['initialfile']: initialfile = kw['initialfile']
filetypes = convert_for_gtk2(kw['filetypes'])
name += ' - ' + title
tmpfile = NamedTemporaryFile()
execline = ''
if sk1.LANG: execline += 'export LANG=' + sk1.LANG + ';'
path = os.path.join(initialdir, initialfile)
execline += 'python %s/gtk/save_file_dialog.py ' % (PATH,)
execline += ' caption="' + name + '" path="' + path + '" '
execline += ' filetypes="' + filetypes + '" window-icon="' + icon + '"'
os.system(execline + '>' + tmpfile.name)
result = tmpfile.readline().strip()
return (result, result)
示例4: get_system_fonts
# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import readline [as 别名]
def get_system_fonts():
"""
Returns list of four fonts, used in sK1 UI:
[small_font,normal_font,large_font,fixed_font]
Each font is a list like:
[font_family,font_style,font_size]
where:
font_family - string representation of font family
font_style - list of font styles like 'bold' and 'italic'
font_size - font size integer value
Currently Gtk binding is implemented. Win32 and MacOS X
implementation will be later.
"""
tmpfile = NamedTemporaryFile()
command = "import gtk;w = gtk.Window();w.realize();style=w.get_style(); print style.font_desc.to_string();"
os.system('python -c "%s" >%s 2>/dev/null' % (command, tmpfile.name))
font = tmpfile.readline().strip()
normal_font = process_gtk_font_string(font)
small_font = copy.deepcopy(normal_font)
small_font[2] -= 1
large_font = copy.deepcopy(normal_font)
large_font[2] += 2
if not 'bold' in large_font[1]:
large_font[1].append('bold')
fixed_font = copy.deepcopy(normal_font)
fixed_font[0] = 'monospace'
return [small_font, normal_font, large_font, fixed_font]
示例5: TombOutputThread
# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import readline [as 别名]
class TombOutputThread(QtCore.QThread):
line_received = QtCore.pyqtSignal(QtCore.QString)
error_received = QtCore.pyqtSignal(QtCore.QString)
progressed = QtCore.pyqtSignal(int) #value in percent
def __init__(self):
QtCore.QThread.__init__(self)
self.buffer = NamedTemporaryFile()
def run(self):
while True:
where = self.buffer.tell()
line = self.buffer.readline()
if not line:
time.sleep(1)
self.buffer.seek(where)
else:
#ansi color escapes messes this up, but it'ok anyway
self.line_received.emit(line)
self.parse_line(line)
def parse_line(self, line):
#This could be simplified, and s/search/match, if --no-color supported
#see #59
#TODO: this should be moved to tomblib.parse
parsed = parse_line(line)
if parsed and parsed['type'] == 'error':
self.error_received.emit(parsed.content)
示例6: import_gtk_colors
# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import readline [as 别名]
def import_gtk_colors(self):
"""
Imports system gtk color scheme using pygtk binding.
"""
colors={}
tmpfile=NamedTemporaryFile()
command="import gtk;w = gtk.Window();w.realize();style=w.get_style();"
command+="print style.base[gtk.STATE_NORMAL].to_string(),"+ \
" style.base[gtk.STATE_ACTIVE].to_string(),"+ \
" style.base[gtk.STATE_PRELIGHT].to_string(),"+ \
" style.base[gtk.STATE_SELECTED].to_string(),"+ \
" style.base[gtk.STATE_INSENSITIVE].to_string();"
command+="print style.text[gtk.STATE_NORMAL].to_string(),"+ \
" style.text[gtk.STATE_ACTIVE].to_string(),"+ \
" style.text[gtk.STATE_PRELIGHT].to_string(),"+ \
" style.text[gtk.STATE_SELECTED].to_string(),"+ \
" style.text[gtk.STATE_INSENSITIVE].to_string();"
command+="print style.fg[gtk.STATE_NORMAL].to_string(),"+ \
" style.fg[gtk.STATE_ACTIVE].to_string(),"+ \
" style.fg[gtk.STATE_PRELIGHT].to_string(),"+ \
" style.fg[gtk.STATE_SELECTED].to_string(),"+ \
" style.fg[gtk.STATE_INSENSITIVE].to_string();"
command+="print style.bg[gtk.STATE_NORMAL].to_string(),"+ \
" style.bg[gtk.STATE_ACTIVE].to_string(),"+ \
" style.bg[gtk.STATE_PRELIGHT].to_string(),"+ \
" style.bg[gtk.STATE_SELECTED].to_string(),"+ \
" style.bg[gtk.STATE_INSENSITIVE].to_string();"
os.system('python -c "%s" >%s 2>/dev/null'%(command, tmpfile.name))
for type in ["base","text","fg","bg"]:
line=tmpfile.readline().strip().split()
colors[type+' normal']=gtk_to_tk_color(line[0])
colors[type+' active']=gtk_to_tk_color(line[1])
colors[type+' prelight']=gtk_to_tk_color(line[2])
colors[type+' selected']=gtk_to_tk_color(line[3])
colors[type+' insensitive']=gtk_to_tk_color(line[4])
tmpfile.close()
self.map_gtk_colors(colors)
示例7: FileStore
# 需要导入模块: from tempfile import NamedTemporaryFile [as 别名]
# 或者: from tempfile.NamedTemporaryFile import readline [as 别名]
class FileStore(object):
def __init__(self, proxy, processId, mode= 'r'):
'''
Gives r+w access to file on static instance via local tempfile.NamedTemproraryFile
'''
self.proxy= proxy
self.processId= processId
self.mode= mode
self.tmpFile= NamedTemporaryFile(mode= 'r+', prefix= self.processId, delete= True)
if 'r' in mode:
self.__get__()
def __get__(self):
'''
Get contents of static instance file and save to local temp file
'''
data= self.proxy.getFileContents(self.processId)
self.tmpFile.write(data.tostring())
self.tmpFile.seek(0)
def __post__(self):
'''
Posts contents of local temp file to static instance file
'''
self.tmpFile.seek(0)
data= self.tmpFile.read()
self.proxy.setFileContents(self.processId, data)
self.tmpFile.seek(0)
def getName(self):
return self.processId
def getLocalName(self):
return self.tmpFile.name
def write(self, data):
'''
Writes data to local tempfile
'''
if 'w' not in self.mode:
raise Exception('file open for read only')
self.tmpFile.write(dumps(data))
def read(self, size= -1):
'''
Reads data from local tempfile. See file read() for more details.
'''
if 'r' not in self.mode:
raise Exception('file open for write only')
return loads(self.tmpFile.read(size))
def readlines(self):
'''
Reads lines from local tempfile. See file readlines() for more detals.
'''
if 'r' not in self.mode:
raise Exception('file open for write only')
return loads(self.tmpFile.readlines())
def readline(self):
'''
Reads line from local tempfile. See file readline() for more details.
'''
if 'r' not in self.mode:
raise Exception('file open for write only')
return loads(self.tmpFile.readline())
def close(self, delete= False):
'''
Saves the contents of the local tempfile and then closes/destroys the local tempfile. See self.__post__() and python tempfile for more details.
'''
if 'w' in self.mode:
self.__post__()
elif 'r' in self.mode:
# if delete requested -- remove file form static instance
if delete:
self.proxy.deleteFile(self.processId)
self.tmpFile.close()