def test_quoting(self): self.assertEqual(r'Quote \" in text', javascript_quote('Quote " in text')) self.assertEqual(r'\\\"\b\f\n\r\t\'', javascript_quote('\\"\b\f\n\r\t\'')) self.assertEqual(r'\u0002\u001e', javascript_quote('\x02\x1e')) self.assertEqual(r'\u0026\u003c\u003e', javascript_quote('&<>'))
def _gantt_options(self, options): opt = '' if (options['linkStyle']): linkStyle = options['linkStyle'] else: linkStyle = 'standard' opt += self.GanttID + '.setLinkStyle("%s")\n' % linkStyle opt += self.GanttID + '.setShowRes(%s);\n' % options['res'] opt += self.GanttID + '.setShowDur(%s);\n' % options['dur'] opt += self.GanttID + '.setShowComp(%s);\n' % options['comp'] if (options['scrollTo']): opt += self.GanttID + '.setScrollDate("%s");\n' % options[ 'scrollTo'] w = options['lwidth'] if w: opt += self.GanttID + '.setLeftWidth(%s);\n' % w opt += self.GanttID+'.setCaptionType("%s");\n' % \ javascript_quote(options['caption']) opt += self.GanttID + '.setShowStartDate(%s);\n' % options['startDate'] opt += self.GanttID + '.setShowEndDate(%s);\n' % options['endDate'] opt += self.GanttID+'.setDateInputFormat("%s");\n' % \ javascript_quote(self.jsDateFormat) opt += self.GanttID+'.setDateDisplayFormat("%s");\n' % \ javascript_quote(options['dateDisplay']) opt += self.GanttID + '.setFormatArr(%s);\n' % ','.join( '"%s"' % javascript_quote(f) for f in options['formats'].split('|')) opt += self.GanttID + '.setPopupFeatures("location=1,scrollbars=1");\n' return opt
def _gantt_options(self, options): opt = '' opt += self.GanttID+'.setShowRes(%s);\n' % options['res'] opt += self.GanttID+'.setShowDur(%s);\n' % options['dur'] opt += self.GanttID+'.setShowComp(%s);\n' % options['comp'] if (options['scrollTo']): opt += self.GanttID+'.setScrollDate("%s");\n' % options['scrollTo'] w = options['lwidth'] if w: opt += self.GanttID+'.setLeftWidth(%s);\n' % w opt += self.GanttID+'.setCaptionType("%s");\n' % \ javascript_quote(options['caption']) opt += self.GanttID+'.setShowStartDate(%s);\n' % options['startDate'] opt += self.GanttID+'.setShowEndDate(%s);\n' % options['endDate'] opt += self.GanttID+'.setDateInputFormat("%s");\n' % \ javascript_quote(self.jsDateFormat) opt += self.GanttID+'.setDateDisplayFormat("%s");\n' % \ javascript_quote(options['dateDisplay']) opt += self.GanttID+'.setFormatArr(%s);\n' % ','.join( '"%s"' % javascript_quote(f) for f in options['formats'].split('|')) opt += self.GanttID+'.setPopupFeatures("location=1,scrollbars=1");\n' return opt
def test_quoting(self): self.assertEqual(r'Quote \" in text', javascript_quote('Quote " in text')) self.assertEqual(r'\\\"\b\f\n\r\t\'', javascript_quote('\\"\b\f\n\r\t\'')) self.assertEqual(r'\u0002\u001e', javascript_quote('\x02\x1e')) self.assertEqual(r'\u0026\u003c\u003e', javascript_quote('&<>'))
def _begin_gantt(self, options): if options['format']: defaultFormat = options['format'] else: defaultFormat = options['formats'].split('|')[0] showdep = options['showdep'] text = '' text += '<div style="position:relative" class="gantt" ' + \ 'id="GanttChartDIV_'+self.GanttID+'"></div>\n' text += '<script language="javascript">\n' text += 'var '+self.GanttID+' = new JSGantt.GanttChart("'+ \ self.GanttID+'",document.getElementById("GanttChartDIV_'+ \ self.GanttID+'"), "%s", "%s");\n' % \ (javascript_quote(defaultFormat), showdep) text += 'var t;\n' text += 'if (window.addEventListener){\n' text += ' window.addEventListener("resize", ' + \ 'function() { ' + self.GanttID+'.Draw(); ' if options['showdep']: text += self.GanttID + '.DrawDependencies();' text += '}, false);\n' text += '} else {\n' text += ' window.attachEvent("onresize", ' + \ 'function() { '+self.GanttID+'.Draw(); ' if options['showdep']: text += self.GanttID + '.DrawDependencies();' text += '});\n' text += '}\n' return text
def _begin_gantt(self, options): if options['format']: defaultFormat = options['format'] else: defaultFormat = options['formats'].split('|')[0] showdep = options['showdep'] text = '' text += '<div style="position:relative" class="gantt" ' + \ 'id="GanttChartDIV_'+self.GanttID+'"></div>\n' text += '<script language="javascript">\n' text += 'var '+self.GanttID+' = new JSGantt.GanttChart("'+ \ self.GanttID+'",document.getElementById("GanttChartDIV_'+ \ self.GanttID+'"), "%s", "%s");\n' % \ (javascript_quote(defaultFormat), showdep) text += 'var t;\n' text += 'if (window.addEventListener){\n' text += ' window.addEventListener("resize", ' + \ 'function() { ' + self.GanttID+'.Draw(); ' if options['showdep']: text += self.GanttID+'.DrawDependencies();' text += '}, false);\n' text += '} else {\n' text += ' window.attachEvent("onresize", ' + \ 'function() { '+self.GanttID+'.Draw(); ' if options['showdep']: text += self.GanttID+'.DrawDependencies();' text += '});\n' text += '}\n' return text
def filter_stream(self, req, method, filename, stream, data): if self.olark_identity: template = Chrome(self.env).load_template('olark.html') shortname = self.env.path.split("/")[-1] jsblock = template.generate(visitor_name=javascript_quote("%s (%s) in %s" % (req.session.get('name'), req.authname, shortname)), identity=self.olark_identity) stream |= Transformer("//body").append(jsblock) return stream
def test(self, req, author, content, ip): i = req.args.getfirst(self.name) h = req.args.getfirst(self.name_hidden) r = self.getlink(req) if i and h: i = shorten_line(javascript_quote(i), 50) h = shorten_line(javascript_quote(h), 50) return -abs(self.karma_points), \ N_("Both trap fields says this is spam (%s, %s)"), i, h elif i: i = shorten_line(javascript_quote(i), 50) return -abs(self.karma_points), \ N_("Invisible trap field says this is spam (%s)"), i elif h: h = shorten_line(javascript_quote(h), 50) return -abs(self.karma_points), \ N_("Hidden trap field says this is spam (%s)"), h elif r: r = shorten_line(javascript_quote(r), 50) return -abs(self.karma_points), \ N_("Register trap field starts with HTTP URL (%s)"), r
def _get_keywords_string(self, req): keywords = set(self.sticky_tags_opt) # prevent duplicates if self.tags_enabled: # Use TagsPlugin >= 0.7 performance-enhanced API. tags = TagSystem(self.env).get_all_tags(req) keywords.update(tags.keys()) if keywords: keywords = sorted(keywords) keywords = ','.join( ("'%s'" % javascript_quote(_keyword) for _keyword in keywords)) else: keywords = '' return keywords
def _get_keywords_string(self, req): keywords = set(self.sticky_tags_opt) # prevent duplicates if self.tags_enabled: # Use TagsPlugin >= 0.7 performance-enhanced API. tags = TagSystem(self.env).get_all_tags(req) keywords.update(tags.keys()) if keywords: keywords = sorted(keywords) keywords = ','.join(("'%s'" % javascript_quote(_keyword) for _keyword in keywords)) else: keywords = '' return keywords
def _get_keywords_string(self, req): # Using a set ensures no duplicates keywords = set(self.keywords_opt) if tagsplugin_is_installed: # '-invalid_keyword' is a workaround for a TagsPlugin regression, # see th:#7856 and th:#7857 query_result = TagSystem(self.env).query(req, '-invalid_keyword') for resource, tags in query_result: keywords.update(tags) if keywords: keywords = sorted(keywords) keywords = ','.join(("'%s'" % javascript_quote(_keyword) for _keyword in keywords)) else: keywords = '' return keywords
def to_json(value): """Encode `value` to JSON.""" if isinstance(value, basestring): return '"%s"' % javascript_quote(value) elif value is None: return 'null' elif value is False: return 'false' elif value is True: return 'true' elif isinstance(value, (int, long)): return str(value) elif isinstance(value, float): return repr(value) elif isinstance(value, (list, tuple)): return '[%s]' % ','.join(to_json(each) for each in value) elif isinstance(value, dict): return '{%s}' % ','.join('%s:%s' % (to_json(k), to_json(v)) for k, v in sorted(value.iteritems())) else: raise TypeError('Cannot encode type %s' % value.__class__.__name__)
def _format_ticket(self, ticket, options): # Translate owner to full name def _owner(ticket): if self.pm.isMilestone(ticket): owner_name = '' else: owner_name = ticket['owner'] if options['userMap']: # Build the map the first time we use it if self.user_map is None: self.user_map = {} for username, name, email in self.env.get_known_users( ): self.user_map[username] = name # Map the user name if self.user_map.get(owner_name): owner_name = self.user_map[owner_name] return owner_name task = '' # pID, pName if self.pm.isMilestone(ticket): if ticket['id'] > 0: # Put ID number on inchpebbles name = 'MS:%s (#%s)' % (ticket['summary'], ticket['id']) else: # Don't show bogus ID of milestone pseudo tickets. name = 'MS:%s' % ticket['summary'] else: name = "#%d:%s (%s %s)" % \ (ticket['id'], ticket['summary'], ticket['status'], ticket['type']) task += 't = new JSGantt.TaskItem(%s,%d,"%s",' % \ (self.GanttID, ticket['id'], javascript_quote(name)) # pStart, pEnd task += '"%s",' % self.pm.start(ticket).strftime(self.pyDateFormat) task += '"%s",' % self.pm.finish(ticket).strftime(self.pyDateFormat) # pDisplay task += '"%s",' % javascript_quote(self._task_display(ticket, options)) # pLink task += '"%s",' % javascript_quote(ticket['link']) # pMile if self.pm.isMilestone(ticket): task += '1,' else: task += '0,' # pRes (owner) task += '"%s",' % javascript_quote(_owner(ticket)) # pComp (percent complete); integer 0..100 task += '"%s",' % self.pm.percentComplete(ticket) # pGroup (has children) if self.pm.children(ticket): task += '%s,' % 1 else: task += '%s,' % 0 # pParent (parent task ID) # If there's no parent, don't link to it if self.pm.parent(ticket) == None: task += '%s,' % 0 else: task += '%s,' % self.pm.parent(ticket) # open if int(ticket['level']) < int(options['openLevel']) and \ ((options['expandClosedTickets'] != 0) or \ (ticket['status'] != 'closed')): openGroup = 1 else: openGroup = 0 task += '%d,' % openGroup # predecessors pred = [str(s) for s in self.pm.predecessors(ticket)] if len(pred): task += '"%s",' % javascript_quote(','.join(pred)) else: task += '"%s",' % javascript_quote(','.join('')) # caption # FIXME - if caption isn't set to caption, use "" because the # description could be quite long and take a long time to make # safe and display. task += '"%s (%s %s)"' % (javascript_quote( ticket['description']), javascript_quote( ticket['status']), javascript_quote(ticket['type'])) task += ');\n' task += self.GanttID + '.AddTaskItem(t);\n' return task
def test_quoting(self): self.assertEqual(r"Quote \" in text", javascript_quote('Quote " in text')) self.assertEqual(r"\\\"\b\f\n\r\t\'", javascript_quote("\\\"\b\f\n\r\t'")) self.assertEqual(r"\u0002\u001e", javascript_quote("\x02\x1e")) self.assertEqual(r"\u0026\u003c\u003e", javascript_quote("&<>"))
def _format_ticket(self, ticket, options): # Translate owner to full name def _owner(ticket): if self.pm.isMilestone(ticket): owner_name = '' else: owner_name = ticket['owner'] if options['userMap']: # Build the map the first time we use it if self.user_map is None: self.user_map = {} for username, name, email in self.env.get_known_users(): self.user_map[username] = name # Map the user name if self.user_map.get(owner_name): owner_name = self.user_map[owner_name] return owner_name task = '' # pID, pName if self.pm.isMilestone(ticket): if ticket['id'] > 0: # Put ID number on inchpebbles name = 'MS:%s (#%s)' % (ticket['summary'], ticket['id']) else: # Don't show bogus ID of milestone pseudo tickets. name = 'MS:%s' % ticket['summary'] else: name = "#%d:%s (%s %s)" % \ (ticket['id'], ticket['summary'], ticket['status'], ticket['type']) task += 't = new JSGantt.TaskItem(%s,%d,"%s",' % \ (self.GanttID, ticket['id'], javascript_quote(name)) # pStart, pEnd task += '"%s",' % self.pm.start(ticket).strftime(self.pyDateFormat) task += '"%s",' % self.pm.finish(ticket).strftime(self.pyDateFormat) # pDisplay task += '"%s",' % javascript_quote(self._task_display(ticket, options)) # pLink task += '"%s",' % javascript_quote(ticket['link']) # pMile if self.pm.isMilestone(ticket): task += '1,' else: task += '0,' # pRes (owner) task += '"%s",' % javascript_quote(_owner(ticket)) # pComp (percent complete); integer 0..100 task += '"%s",' % self.pm.percentComplete(ticket) # pGroup (has children) if self.pm.children(ticket): task += '%s,' % 1 else: task += '%s,' % 0 # pParent (parent task ID) # If there's no parent, don't link to it if self.pm.parent(ticket) == None: task += '%s,' % 0 else: task += '%s,' % self.pm.parent(ticket) # open if ticket['level'] < options['openLevel'] and \ ((options['expandClosedTickets'] != 0) or \ (ticket['status'] != 'closed')): openGroup = 1 else: openGroup = 0 task += '%d,' % openGroup # predecessors pred = [str(s) for s in self.pm.predecessors(ticket)] if len(pred): task += '"%s",' % javascript_quote(','.join(pred)) else: task += '"%s",' % javascript_quote(','.join('')) # caption # FIXME - if caption isn't set to caption, use "" because the # description could be quite long and take a long time to make # safe and display. task += '"%s (%s %s)"' % (javascript_quote(ticket['description']), javascript_quote(ticket['status']), javascript_quote(ticket['type'])) task += ');\n' task += self.GanttID+'.AddTaskItem(t);\n' return task