Esempio n. 1
0
      data = f.read()
      data_by_url[url] = data
    except (urllib2.URLError, timeout_urllib2.Error, socket.error), e:
      print type(e), e
      if hasattr(e,'headers'):
        status = e.headers.status
      else:
        status = '500 Internal Server Error'
      start_response(status, response_headers)
      yield ['{"results":[], "error":true}']
      return

  start_response("200 OK", response_headers)
  yield data
  return

  yield "<hr>"

  yield "<table>"
  for k in sorted(environ.keys()):
    yield "<tr><td>" + k
    yield "<td>" + str(environ[k])
    #yield "<br>"
  yield "</table>"

if __name__=='__main__':
  import util; util.fix_stdio()
  from wsgiref.simple_server import make_server, demo_app
  httpd = make_server('', 8500, application)
  httpd.serve_forever()
Esempio n. 2
0
## To exactly save HTTP inputs/outputs of the backend service
## To exactly reproduce situations and behaviors
## e.g. for performance profiling

# python scotchy.py record
# python -mcProfile -s cumulative scotchy.py play
# anyall.org/chunk.py
# python -mcProfile -s cumulative scotchy.py play | chunk END.. | less
# python -mcProfile -s cumulative scotchy.py play | chunk END.. | head
# for x in 1 2 3; do python -mcProfile -s cumulative scotchy.py play | chunk END.. | head -1; done
import cPickle as pickle
from wsgiref.simple_server import make_server, demo_app
import scotch.recorder
import frontend
import util
util.fix_stdio()
recorder = scotch.recorder.Recorder(frontend.application, verbosity=1)
filename = 'recording.pickle'

import sys
if sys.argv[1] == 'record':
    try:
        httpd = make_server('', 8080, recorder)
        print "Serving HTTP on port 8080..."
        httpd.handle_request()
    finally:
        f = open(filename, 'w')
        pickle.dump(recorder.record_holder, f)
        f.close()
        print "SCOTCH: saved %d records to %s" % (len(
            recorder.record_holder), filename)
Esempio n. 3
0
    yield "</div>"
    yield "</table>"
    yield "<script>"

    yield "topics = "
    yield simplejson.dumps(bigass_topic_dict)
    yield ";"
    yield "load_default_topic();"
    yield "</script>"


def app_stringify(iter):
    for x in iter:
        yield util.stringify(x, 'utf8', 'xmlcharrefreplace')


def global_init():
    global background_model
    background_model = lang_model.TokyoLM()


application = util.chaincompose(the_app, app_stringify)

if __name__ == '__main__':
    import util
    util.fix_stdio(shutup=False)
    from wsgiref.simple_server import make_server
    httpd = make_server('', 8080, application)
    print "Serving HTTP on port 8080..."
    httpd.serve_forever()
Esempio n. 4
0
  return new_string.strip()

# fun: copy and paste outta http://en.wikipedia.org/wiki/Smart_quotes
EdgePunct      = r"""[  ' " “ ” ‘ ’ < > « » { } ( \) [ \]  ]""".replace(' ','')
#NotEdgePunct = r"""[^'"([\)\]]"""  # alignment failures?
NotEdgePunct = r"""[a-zA-Z0-9]"""
EdgePunctLeft  = r"""(\s|^)(%s+)(%s)""" % (EdgePunct, NotEdgePunct)
EdgePunctRight =   r"""(%s)(%s+)(\s|$)""" % (NotEdgePunct, EdgePunct)
EdgePunctLeft_RE = mycompile(EdgePunctLeft)
EdgePunctRight_RE= mycompile(EdgePunctRight)

def edge_punct_munge(s):
  s = EdgePunctLeft_RE.sub( r"\1\2 \3", s)
  s = EdgePunctRight_RE.sub(r"\1 \2\3", s)
  return s


def unprotected_tokenize(s):
  return s.split()

if __name__=='__main__':
  import util
  util.fix_stdio()
  for line in sys.stdin:
    print " ".join(tokenize(line[:-1]))
    #print "CUR\t" + " ".join(tokenize(line[:-1]))
    #print "WS\t" + " ".join(line[:-1].split())
    #print ansi.color(line.strip(),'red')
    #print ansi.color(" ".join(tokenize(line.strip())),'blue','bold')

Esempio n. 5
0
  yield "<div id=tweets>"
  yield "click on a topic on the left please"
  yield "</div>"
  yield "<div id=tweets_more>"
  yield "</div>"
  yield "</table>"
  yield "<script>"

  yield "topics = "
  yield simplejson.dumps(bigass_topic_dict)
  yield ";"
  yield "load_default_topic();"
  yield "</script>"

def app_stringify(iter):
  for x in iter:
    yield util.stringify(x, 'utf8', 'xmlcharrefreplace')

def global_init():
  global background_model
  background_model = lang_model.TokyoLM()

application = util.chaincompose(the_app, app_stringify)

if __name__=='__main__':
  import util; util.fix_stdio(shutup=False)
  from wsgiref.simple_server import make_server
  httpd = make_server('', 8080, application)
  print "Serving HTTP on port 8080..."
  httpd.serve_forever()