Example #1
0
def parse_mapjs(mapjs):
  branchId,latitude,longitude=findall('javascript:showInfoWindow\(([^,]*),([^,]*),([^,]*)',mapjs)[0]
  latitude,longitude=[float(sub('[^0-9.-]','',l)) for l in [latitude,longitude]]
  return {
    "branchId":loads(branchId)['branchId']
  , "latitude":latitude
  , "longitude":longitude
  }
 def _parse_response(self, file_h, sock):
     response_body = ''
     while 1:
         if sock:
             response = sock.recv(1024)
         else:
             response = file_h.read(1024)
         if not response:
             break
         response_body += response
         if self.verbose:
             print 'body: %s' % response
     if response_body == '':
         # Notification
         return None
     return_obj = loads(response_body)
     return return_obj
    def getCK_plone_menu_styles(self):
        """
        return javascript for ckeditor
        plone menu styles
        """
        request = self.request
        response = request.RESPONSE
        cke_properties = self.cke_properties
        styles = demjson.loads(cke_properties.getProperty('menuStyles', '[]'))
        for style in styles:
            if 'name' in style:
                style['name'] = self.context.translate(_(style['name']))
        menu_styles_js_string = """
styles = jQuery.parseJSON('%s');
CKEDITOR.stylesSet.add('plone', styles);""" % demjson.dumps(styles)
        response.setHeader(
            'Cache-control', 'pre-check=0,post-check=0,must-revalidate,'
            's-maxage=0,max-age=0,no-cache')
        response.setHeader('Content-Type', 'application/x-javascript')

        return JavascriptPacker('safe').pack(menu_styles_js_string)
Example #4
0
    def getCK_plone_menu_styles(self):
        """
        return javascript for ckeditor
        plone menu styles
        """
        request = self.request
        response = request.RESPONSE
        cke_properties = self.cke_properties
        styles = demjson.loads(cke_properties.getProperty("menuStyles", "[]"))
        for style in styles:
            if "name" in style:
                style["name"] = self.context.translate(_(style["name"]))
        menu_styles_js_string = """
styles = jQuery.parseJSON('%s');
CKEDITOR.stylesSet.add('plone', styles);""" % demjson.dumps(
            styles
        )
        response.setHeader("Cache-control", "pre-check=0,post-check=0,must-revalidate," "s-maxage=0,max-age=0,no-cache")
        response.setHeader("Content-Type", "application/x-javascript")

        return JavascriptPacker("safe").pack(menu_styles_js_string)
Example #5
0
def validate_json(jsonstr):
    """Validates that json is a valid JSON string (by loading it)."""
    try:
        json.loads(jsonstr)
    except ValueError as e:
        raise JSONSyntaxError(str(e))