Exemplo n.º 1
0
    def __call__(self, environ, start_response):
        # Read JSON POST input to jsonfilter.json if matching mime type
        response = {'status': '200 OK', 'headers': []}

        def json_start_response(status, headers):
            response['status'] = status
            response['headers'].extend(headers)

        environ['jsonfilter.mime_type'] = self.mime_type
        if environ.get('REQUEST_METHOD', '') == 'POST':
            if environ.get('CONTENT_TYPE', '') == self.mime_type:
                args = [_ for _ in [environ.get('CONTENT_LENGTH')] if _]
                data = environ['wsgi.input'].read(*map(int, args))
                environ['jsonfilter.json'] = simplejson.loads(data)
        res = simplejson.dumps(self.app(environ, json_start_response))
        jsonp = cgi.parse_qs(environ.get('QUERY_STRING', '')).get('jsonp')
        if jsonp:
            content_type = 'text/javascript'
            res = ''.join(jsonp + ['(', res, ')'])
        elif 'Opera' in environ.get('HTTP_USER_AGENT', ''):
            # Opera has bunk XMLHttpRequest support for most mime types
            content_type = 'text/plain'
        else:
            content_type = self.mime_type
        headers = [
            ('Content-type', content_type),
            ('Content-length', len(res)),
        ]
        headers.extend(response['headers'])
        start_response(response['status'], headers)
        return [res]
Exemplo n.º 2
0
 def __call__(self, environ, start_response):
     # Read JSON POST input to jsonfilter.json if matching mime type
     response = {'status': '200 OK', 'headers': []}
     def json_start_response(status, headers):
         response['status'] = status
         response['headers'].extend(headers)
     environ['jsonfilter.mime_type'] = self.mime_type
     if environ.get('REQUEST_METHOD', '') == 'POST':
         if environ.get('CONTENT_TYPE', '') == self.mime_type:
             args = [_ for _ in [environ.get('CONTENT_LENGTH')] if _]
             data = environ['wsgi.input'].read(*map(int, args))
             environ['jsonfilter.json'] = simplejson.loads(data)
     res = simplejson.dumps(self.app(environ, json_start_response))
     jsonp = cgi.parse_qs(environ.get('QUERY_STRING', '')).get('jsonp')
     if jsonp:
         content_type = 'text/javascript'
         res = ''.join(jsonp + ['(', res, ')'])
     elif 'Opera' in environ.get('HTTP_USER_AGENT', ''):
         # Opera has bunk XMLHttpRequest support for most mime types
         content_type = 'text/plain'
     else:
         content_type = self.mime_type
     headers = [
         ('Content-type', content_type),
         ('Content-length', len(res)),
     ]
     headers.extend(response['headers'])
     start_response(response['status'], headers)
     return [res]
Exemplo n.º 3
0
async def get_reddit_top(subreddit, client, counter):
    data1 = await get_json(
        client, 'https://www.reddit.com/r/' + subreddit +
        '/top.json?sort=top&t=day&limit=5')
    if data1:
        j = loads(data1.decode("utf-8"))
        print(j)
    counter.decrement()
Exemplo n.º 4
0
	def get(self):
		char_json_list = CharJson.all().fetch(100)
		alphabet = {}
		for char_json in char_json_list:
			alphabet[char_json.chr] = simplejson.loads(char_json.json)
			
		js_string = "document.alphabet={"
		letters = []
		for (character, char_defn) in alphabet.iteritems():
			
			letter_string = None
			if len(character) == 1:
				letter_string = "A%x:{" % ord(character)
			elif character[0] == '&' and character[-1] == ';':
				# Unescape the character.
				special_char = unescape(character)
				if len(special_char) == 1:
					letter_string = "A%x:{" % ord(special_char)
					
			if letter_string is None:
				logging.error("Character in datastore '%s' could not be cast to hex" % character)
				continue
				
			letter_string += "W:%s,P:[" % char_defn["width"]
			
			point_list = []
			for point_dict in char_defn["points"]:
				point_string = "[%s,%s,%s,%s]" % (point_dict["x"],
												  point_dict["y"],
												  point_dict["s"],
												  point_dict["f"])
				point_list.append(point_string)
			full_point_string = ",".join(point_list)
			
			letter_string += full_point_string
			letter_string += "]}"
			letters.append(letter_string)
		
		js_string += ",".join(letters)
		js_string += "};"
		
		self.response.headers["Content-Type"] = "text"
		self.response.out.write( js_string )
Exemplo n.º 5
0
	def get(self):
	
		chr_to_edit = self.request.get("chr")
		if len(chr_to_edit) != 1:
			raise Exception("Bad length of character: '%s'." % chr_to_edit)
			
		template_values = {'chr_to_edit': chr_to_edit}
			
		char_json = CharJson.all().filter('chr =', chr_to_edit).get()

		if char_json:
			try:
				json = simplejson.loads(char_json.json)
				points = json['points']
				width = json['width']
				template_values['points_list'] = points
				template_values['chr_width'] = width
			except:
				pass

		path = os.path.join(os.path.dirname(__file__), 'secret-character-editor', 'editor_template.html')
		self.response.out.write(template.render(path, template_values))