當前位置: 首頁>>代碼示例>>Python>>正文


Python Document.chunks方法代碼示例

本文整理匯總了Python中models.Document.chunks方法的典型用法代碼示例。如果您正苦於以下問題:Python Document.chunks方法的具體用法?Python Document.chunks怎麽用?Python Document.chunks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Document的用法示例。


在下文中一共展示了Document.chunks方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: list

# 需要導入模塊: from models import Document [as 別名]
# 或者: from models.Document import chunks [as 別名]
def list(request):
	if request.is_ajax():
		print "ajax entered"
		print request.FILES
		form = UploadForm(request.POST,request.FILES)
		if form.is_valid():
			print 'form validated'
			files = request.FILES.getlist('file')
			for file in files:
				path = MEDIA_ROOT+'ebooks/'+str(file)
				destination = open(path, 'wb+')
				for chunk in file.chunks():
					destination.write(chunk)
				destination.close()
			for file in files:
				path = MEDIA_ROOT+'ebooks/'+str(file)
				destination = open(path, 'wb+')
				a = destination.read()
				print a
				destination.close()
		return HttpResponse('done \m/');

	output = []
	error = []
	rlt = None
	if request.method == 'POST':
		form = UploadForm(request.POST, request.FILES)
		if form.is_valid():
			file = Document(file = request.FILES['file'])
			file.save()
			files = request.FILES.getlist('file')
			for file in files:
				path = MEDIA_ROOT+'ebooks/'+str(file)
				destination = open(path, 'wb+')
				for chunk in file.chunks():
					destination.write(chunk)
				destination.close()
			for file in files:
				path = MEDIA_ROOT+'ebooks/'+str(file)
				destination = open(path, 'r')
				a = destination.read()
				destination.close()
			for file in files:
				path = MEDIA_ROOT+'ebooks/'+str(file)
				a=b=''
				p = subprocess.Popen(['g++',path])
				#a,b = p.communicate()
				p.wait()
				print a
				print 'goo boy'
				a = os.linesep.join([s for s in a.splitlines() if s])
				b = os.linesep.join([s for s in b.splitlines() if s])
				output.append(a)
				error.append(b)
				if not b: 
					pr = subprocess.call(['./a.out'])
					file = open('output.txt','r')
					print file.read()
					file.close()
					file = open('1.txt','r')
					print file.read()
					file.close()	
					rlt = filecmp.cmp('output.txt','1.txt',shallow=False)
					print 'pramod'	
					print rlt
			"""
			import subprocess  

			basename = "CodeGenTest";  
			execname = basename;  
			srcname = basename + ".cpp";  

			codeList = [];
			codeList.append("#include<iostream>")
			codeList.append("#include <stdio.h>");  
			codeList.append("using namespace std;int main(int argc, char *argv[])\n{");  
			codeList.append("printf(\"Hello world.\\n\");");  
			codeList.append("int a;cin>>a;");  
			codeList.append("}");  

			# Convert codelist to string.  
			codeList.append("");  
			codeString = "\n".join(codeList);  
			
			# Print code to output source file  
			outfile=open(srcname,'w');  
			outfile.write(codeString);  
			outfile.close();
			
			print "Compile.";  
			cmd = ["g++", srcname, "-o", execname];  
			p = subprocess.Popen(cmd);  
			p.wait();  
			
			subprocess.call(["./"+execname,'<','input.txt','>','output.txt']);
			"""
	else:
		form = UploadForm()
	dir_path = os.path.join(MEDIA_ROOT,'ebooks/')
	files = []
#.........這裏部分代碼省略.........
開發者ID:knightwave,項目名稱:firstproject,代碼行數:103,代碼來源:views.py


注:本文中的models.Document.chunks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。