<s> from __future__ import with_statement <EOL> from email . utils import parseaddr <EOL> from lamson import view , queue <EOL> from lamson . routing import route , stateless <EOL> import logging <EOL> from config import settings <EOL> from app . model import post <EOL> from markdown import markdown <EOL> @ route ( "<STR_LIT>" ) <EOL> @ stateless <EOL> def POSTING ( message , post_name = None , host = None ) : <EOL> user , address = parseaddr ( message [ '<STR_LIT>' ] ) <EOL> user = user or address <EOL> post_url = "<STR_LIT>" % ( address , post_name ) <EOL> index_q = queue . Queue ( "<STR_LIT>" ) <EOL> post_keys = sorted ( index_q . keys ( ) , reverse = True ) <EOL> old_keys = post_keys [ <NUM_LIT:50> : ] <EOL> del post_keys [ <NUM_LIT:50> : ] <EOL> posts = [ ] <EOL> for key in post_keys : <EOL> msg = index_q . get ( key ) <EOL> if msg [ '<STR_LIT>' ] == post_url : <EOL> index_q . remove ( key ) <EOL> else : <EOL> posts . append ( msg ) <EOL> message [ '<STR_LIT>' ] = post_url <EOL> index_q . push ( message ) <EOL> posts . insert ( <NUM_LIT:0> , message ) <EOL> index = view . render ( locals ( ) , "<STR_LIT>" ) <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> f . write ( index . encode ( "<STR_LIT:utf-8>" ) ) <EOL> f . close ( ) <EOL> for old in old_keys : index_q . remove ( old ) <EOL> @ route ( "<STR_LIT>" ) <EOL> @ stateless <EOL> def COMMENTING ( message , user_id = None , domain = None , post_name = None , host = None ) : <EOL> address = user_id + '<STR_LIT:@>' + domain <EOL> user_dir = post . get_user_dir ( address ) <EOL> if post . user_exists ( address ) : <EOL> comments = queue . Queue ( "<STR_LIT>" % user_dir ) <EOL> comments . push ( message ) <EOL> contents = markdown ( message . body ( ) ) <EOL> comment_file = "<STR_LIT>" % ( user_dir , post_name ) <EOL> snippet = view . render ( locals ( ) , "<STR_LIT>" ) <EOL> with open ( comment_file , "<STR_LIT:a>" ) as out : <EOL> out . write ( snippet ) <EOL> else : <EOL> logging . warning ( "<STR_LIT>" , address ) </s>
