def test_cut(self): self.assertEqual(cut('a string to be mangled', 'a'), ' string to be mngled') self.assertEqual(cut('a string to be mangled', 'ng'), 'a stri to be maled') self.assertEqual(cut('a string to be mangled', 'strings'), 'a string to be mangled')
def grammar(value, arg): "Removes all | separators, creates line breaks and adds grammar description" separator = '|' subvalue = cut(value, separator) event_type_object = arg grammar_text = event_type_object.text_field.split(separator) grammar_text_len = grammar_text.__len__() # check whether a event type is given # also check whether user requested to not add grammar descriptions if (grammar_text[0] != "None") and (grammar_text[0] != "none") and (arg is not None): x = '' y = 0 for i in subvalue.splitlines(): if y < grammar_text_len: strg = ' ' + '(' + grammar_text[y] + ')' else: strg = '' x += i + strg + ' \r\n' y += 1 subvalue = x value = urlize(subvalue) value = linebreaks(value) return value
def format_result(self, request, item): context = RequestContext(request) return { 'id': item.id, 'title': item.title, 'desc': cut(truncatewords(striptags(item.description), 15), ' ') }
def getZip(latlng): # grab some lat/long coords from wherever. For this example, # I just opened a javascript console in the browser and ran: # # navigator.geolocation.getCurrentPosition(function(p) { # console.log(p); # }) # latLngVar = defaultfilters.cut(latlng, " ") # Did the geocoding request comes from a device with a # location sensor? Must be either true or false. sensor = 'true' # Hit Google's reverse geocoder directly # NOTE: I *think* their terms state that you're supposed to # use google maps if you use their api for anything. base = "http://maps.googleapis.com/maps/api/geocode/json?" params = "latlng={latlng}&sensor={sen}".format( latlng = latLngVar, sen = "true" ) url = "{base}{params}".format(base=base, params=params) response = requests.get(url) jsonObj = json.loads(response.content) fullAddress = jsonObj['results'][0]['formatted_address'] return str(fullAddress)
def test_non_string_input(self): # Filters shouldn't break if passed non-strings self.assertEqual(addslashes(123), '123') self.assertEqual(linenumbers(123), '1. 123') self.assertEqual(lower(123), '123') self.assertEqual(make_list(123), ['1', '2', '3']) self.assertEqual(slugify(123), '123') self.assertEqual(title(123), '123') self.assertEqual(truncatewords(123, 2), '123') self.assertEqual(upper(123), '123') self.assertEqual(urlencode(123), '123') self.assertEqual(urlize(123), '123') self.assertEqual(urlizetrunc(123, 1), '123') self.assertEqual(wordcount(123), 1) self.assertEqual(wordwrap(123, 2), '123') self.assertEqual(ljust('123', 4), '123 ') self.assertEqual(rjust('123', 4), ' 123') self.assertEqual(center('123', 5), ' 123 ') self.assertEqual(center('123', 6), ' 123 ') self.assertEqual(cut(123, '2'), '13') self.assertEqual(escape(123), '123') self.assertEqual(linebreaks_filter(123), '<p>123</p>') self.assertEqual(linebreaksbr(123), '123') self.assertEqual(removetags(123, 'a'), '123') self.assertEqual(striptags(123), '123')
def fix_json_string(string): """ Marks a string as not requiring further HTML escaping prior to output. """ string = safe(string) string = string.replace('"\\"',"'").replace('\\"\"', "'") # fix quotes string = cut(string,"\"") # keep fixing string = safe(string) # keep fixing return string
def test_non_string_input(self): self.assertEqual(cut(123, '2'), '13')
def test_non_string_input(self): self.assertEqual(cut(123, "2"), "13")
def test_non_matching_string(self): self.assertEqual( cut("a string to be mangled", "strings"), "a string to be mangled" )
def test_character(self): self.assertEqual(cut('a string to be mangled', 'a'), ' string to be mngled')
def test_non_matching_string(self): self.assertEqual(cut('a string to be mangled', 'strings'), 'a string to be mangled')
def test_characters(self): self.assertEqual(cut('a string to be mangled', 'ng'), 'a stri to be maled')
def test_characters(self): self.assertEqual(cut("a string to be mangled", "ng"), "a stri to be maled")
def test_character(self): self.assertEqual(cut("a string to be mangled", "a"), " string to be mngled")