2011-09-15 3 views
0

안녕하세요. 내 서버에있는 다른 서버의 원격 .ical 파일을 처리하고 요청한 사용자에게 다시 넘길 필요가 있습니다.파이썬으로 원격 iCal 처리하기

그래서 내가해야 할 일이다

  • 가와 다시 몇 가지 정규식 (하지 질문)
  • 손을 함께
  • 프로세스 파일을 파일 가져 오기 (urllib2가 함께 할 수있다) 특정 헤더 <-내 주요 문제는 내가 PHP를 사용하여이 작업을 수행하는 방법을 알고 것

:

header('Content-type: text/calendar; charset=utf-8'); 
header('Content-Disposition: inline; filename=calendar.ics'); 
echo $ical; 
exit; 

그러나 파이썬에서 같은 작업을 수행하는 방법은 무엇입니까?

답변

1

웹 관련 내용과 마찬가지로, a WSGI application으로 시작합니다.

def app(environ, start_response): 
    calendar = get_processed_file() 

    start_response('200 OK', [ 
     ('Content-Type', 'text/icalendar; charset=utf-8'), 
     ('Content-Disposition', 'inline; filename=calendar.ics'), 
    ]) 
    yield calendar 

그런 다음 배포하려면 핸들러를 사용하십시오. 일반 CGI는

import wsgiref 
wsgiref.CGIHandler().run(app) 

이 WSGI에 대한 자세한 재료 http://www.wsgi.org/를 참조 할 것.

관련 문제