| | 14 | |
| | 15 | >>> addslashes('"double quotes" and \\'single quotes\\'') |
| | 16 | '\\\\"double quotes\\\\" and \\\\\\'single quotes\\\\\\'' |
| | 17 | |
| | 18 | >>> capfirst('hello world') |
| | 19 | 'Hello world' |
| | 20 | |
| | 21 | >>> fix_ampersands('Jack & Jill & Jeroboam') |
| | 22 | 'Jack & Jill & Jeroboam' |
| | 23 | |
| | 24 | >>> linenumbers('line 1\\nline 2') |
| | 25 | '1. line 1\\n2. line 2' |
| | 26 | |
| | 27 | >>> linenumbers('\\n'.join(['x'] * 10)) |
| | 28 | '01. x\\n02. x\\n03. x\\n04. x\\n05. x\\n06. x\\n07. x\\n08. x\\n09. x\\n10. x' |
| | 29 | |
| | 30 | >>> lower('TEST') |
| | 31 | 'test' |
| | 32 | |
| | 33 | >>> lower(u'\\xcb') # uppercase E umlaut |
| | 34 | u'\\xeb' |
| | 35 | |
| | 36 | >>> make_list('abc') |
| | 37 | ['a', 'b', 'c'] |
| | 38 | |
| | 39 | >>> make_list(1234) |
| | 40 | ['1', '2', '3', '4'] |
| | 41 | |
| | 42 | >>> slugify(' Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/') |
| | 43 | 'jack-jill-like-numbers-123-and-4-and-silly-characters' |
| | 44 | |
| | 45 | >>> stringformat(1, '03d') |
| | 46 | '001' |
| | 47 | |
| | 48 | >>> stringformat(1, 'z') |
| | 49 | '' |
| | 50 | |
| | 51 | >>> title('a nice title, isn\\'t it?') |
| | 52 | "A Nice Title, Isn't It?" |
| | 53 | |
| | 54 | |
| | 55 | >>> truncatewords('A sentence with a few words in it', 1) |
| | 56 | 'A ...' |
| | 57 | |
| | 58 | >>> truncatewords('A sentence with a few words in it', 5) |
| | 59 | 'A sentence with a few ...' |
| | 60 | |
| | 61 | >>> truncatewords('A sentence with a few words in it', 100) |
| | 62 | 'A sentence with a few words in it' |
| | 63 | |
| | 64 | >>> truncatewords('A sentence with a few words in it', 'not a number') |
| | 65 | 'A sentence with a few words in it' |
| | 66 | |
| | 67 | |
| | 68 | >>> upper('Mixed case input') |
| | 69 | 'MIXED CASE INPUT' |
| | 70 | |
| | 71 | >>> upper(u'\\xeb') # lowercase e umlaut |
| | 72 | u'\\xcb' |
| | 73 | |
| | 74 | |
| | 75 | >>> urlencode('jack & jill') |
| | 76 | 'jack%20%26%20jill' |
| | 77 | |
| | 78 | |
| | 79 | >>> urlizetrunc('http://short.com/', 20) |
| | 80 | '<a href="http://short.com/" rel="nofollow">http://short.com/</a>' |
| | 81 | |
| | 82 | >>> urlizetrunc('http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 20) |
| | 83 | '<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google.co...</a>' |
| | 84 | |
| | 85 | >>> wordcount('') |
| | 86 | 0 |
| | 87 | |
| | 88 | >>> wordcount('oneword') |
| | 89 | 1 |
| | 90 | |
| | 91 | >>> wordcount('lots of words') |
| | 92 | 3 |
| | 93 | |
| | 94 | >>> wordwrap('this is a long paragraph of text that really needs to be wrapped I\\'m afraid', 14) |
| | 95 | "this is a long\\nparagraph of\\ntext that\\nreally needs\\nto be wrapped\\nI'm afraid" |
| | 96 | |
| | 97 | >>> ljust('test', 10) |
| | 98 | 'test ' |
| | 99 | |
| | 100 | >>> ljust('test', 3) |
| | 101 | 'test' |
| | 102 | |
| | 103 | >>> rjust('test', 10) |
| | 104 | ' test' |
| | 105 | |
| | 106 | >>> rjust('test', 3) |
| | 107 | 'test' |
| | 108 | |
| | 109 | >>> center('test', 6) |
| | 110 | ' test ' |
| | 111 | |
| | 112 | >>> cut('a string to be mangled', 'a') |
| | 113 | ' string to be mngled' |
| | 114 | |
| | 115 | >>> cut('a string to be mangled', 'ng') |
| | 116 | 'a stri to be maled' |
| | 117 | |
| | 118 | >>> cut('a string to be mangled', 'strings') |
| | 119 | 'a string to be mangled' |
| | 120 | |
| | 121 | >>> escape('<some html & special characters > here') |
| | 122 | '<some html & special characters > here' |
| | 123 | |
| | 124 | >>> linebreaks('line 1') |
| | 125 | '<p>line 1</p>' |
| | 126 | |
| | 127 | >>> linebreaks('line 1\\nline 2') |
| | 128 | '<p>line 1<br />line 2</p>' |
| | 129 | |
| | 130 | >>> removetags('some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags', 'script img') |
| | 131 | 'some <b>html</b> with alert("You smell") disallowed tags' |
| | 132 | |
| | 133 | >>> striptags('some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags') |
| | 134 | 'some html with alert("You smell") disallowed tags' |
| | 135 | |
| | 136 | >>> dictsort([{'age': 23, 'name': 'Barbara-Ann'},\ |
| | 137 | {'age': 63, 'name': 'Ra Ra Rasputin'},\ |
| | 138 | {'name': 'Jonny B Goode', 'age': 18}], 'age') |
| | 139 | [{'age': 18, 'name': 'Jonny B Goode'},\ |
| | 140 | {'age': 23, 'name': 'Barbara-Ann'},\ |
| | 141 | {'age': 63, 'name': 'Ra Ra Rasputin'}] |
| | 142 | |
| | 143 | >>> dictsortreversed([{'age': 23, 'name': 'Barbara-Ann'},\ |
| | 144 | {'age': 63, 'name': 'Ra Ra Rasputin'},\ |
| | 145 | {'name': 'Jonny B Goode', 'age': 18}], 'age') |
| | 146 | [{'age': 63, 'name': 'Ra Ra Rasputin'},\ |
| | 147 | {'age': 23, 'name': 'Barbara-Ann'},\ |
| | 148 | {'age': 18, 'name': 'Jonny B Goode'}] |
| | 149 | |
| | 150 | >>> first([0,1,2]) |
| | 151 | 0 |
| | 152 | |
| | 153 | >>> first('') |
| | 154 | '' |
| | 155 | |
| | 156 | >>> first('test') |
| | 157 | 't' |
| | 158 | |
| | 159 | >>> join([0,1,2], 'glue') |
| | 160 | '0glue1glue2' |
| | 161 | |
| | 162 | >>> length('1234') |
| | 163 | 4 |
| | 164 | |
| | 165 | >>> length([1,2,3,4]) |
| | 166 | 4 |
| | 167 | |
| | 168 | >>> length_is([], 0) |
| | 169 | True |
| | 170 | |
| | 171 | >>> length_is([], 1) |
| | 172 | False |
| | 173 | |
| | 174 | >>> length_is('a', 1) |
| | 175 | True |
| | 176 | |
| | 177 | >>> length_is('a', 10) |
| | 178 | False |
| | 179 | |
| | 180 | >>> slice_('abcdefg', '0') |
| | 181 | '' |
| | 182 | |
| | 183 | >>> slice_('abcdefg', '1') |
| | 184 | 'a' |
| | 185 | |
| | 186 | >>> slice_('abcdefg', '-1') |
| | 187 | 'abcdef' |
| | 188 | |
| | 189 | >>> slice_('abcdefg', '1:2') |
| | 190 | 'b' |
| | 191 | |
| | 192 | >>> slice_('abcdefg', '1:3') |
| | 193 | 'bc' |
| | 194 | |
| | 195 | >>> slice_('abcdefg', '0::2') |
| | 196 | 'aceg' |
| | 197 | |
| | 198 | >>> unordered_list(['item 1', []]) |
| | 199 | '\\t<li>item 1</li>' |
| | 200 | |
| | 201 | >>> unordered_list(['item 1', [['item 1.1', []]]]) |
| | 202 | '\\t<li>item 1\\n\\t<ul>\\n\\t\\t<li>item 1.1</li>\\n\\t</ul>\\n\\t</li>' |
| | 203 | |
| | 204 | >>> unordered_list(['item 1', [['item 1.1', []], ['item 1.2', []]]]) |
| | 205 | '\\t<li>item 1\\n\\t<ul>\\n\\t\\t<li>item 1.1</li>\\n\\t\\t<li>item 1.2</li>\\n\\t</ul>\\n\\t</li>' |
| | 206 | |
| | 207 | >>> add('1', '2') |
| | 208 | 3 |
| | 209 | |
| | 210 | >>> get_digit(123, 1) |
| | 211 | 3 |
| | 212 | |
| | 213 | >>> get_digit(123, 2) |
| | 214 | 2 |
| | 215 | |
| | 216 | >>> get_digit(123, 3) |
| | 217 | 1 |
| | 218 | |
| | 219 | >>> get_digit(123, 4) |
| | 220 | 0 |
| | 221 | |
| | 222 | >>> get_digit(123, 0) |
| | 223 | 123 |
| | 224 | |
| | 225 | >>> get_digit('xyz', 0) |
| | 226 | 'xyz' |
| | 227 | |
| | 228 | # real testing of date() is in dateformat.py |
| | 229 | >>> date(datetime.datetime(2005, 12, 29), "d F Y") |
| | 230 | '29 December 2005' |
| | 231 | |
| | 232 | # real testing of time() is done in dateformat.py |
| | 233 | >>> time(datetime.time(13), "h") |
| | 234 | '01' |
| | 235 | |
| | 236 | # real testing is done in timesince.py, where we can provide our own 'now' |
| | 237 | >>> timesince(datetime.datetime.now() - datetime.timedelta(1)) |
| | 238 | '1 day' |
| | 239 | |
| | 240 | >>> default("val", "default") |
| | 241 | 'val' |
| | 242 | |
| | 243 | >>> default(None, "default") |
| | 244 | 'default' |
| | 245 | |
| | 246 | >>> default('', "default") |
| | 247 | 'default' |
| | 248 | |
| | 249 | >>> default_if_none("val", "default") |
| | 250 | 'val' |
| | 251 | |
| | 252 | >>> default_if_none(None, "default") |
| | 253 | 'default' |
| | 254 | |
| | 255 | >>> default_if_none('', "default") |
| | 256 | '' |
| | 257 | |
| | 258 | >>> divisibleby(4, 2) |
| | 259 | True |
| | 260 | |
| | 261 | >>> divisibleby(4, 3) |
| | 262 | False |
| | 263 | |
| | 264 | >>> yesno(True) |
| | 265 | 'yes' |
| | 266 | |
| | 267 | >>> yesno(False) |
| | 268 | 'no' |
| | 269 | |
| | 270 | >>> yesno(None) |
| | 271 | 'maybe' |
| | 272 | |
| | 273 | >>> yesno(True, 'certainly,get out of town,perhaps') |
| | 274 | 'certainly' |
| | 275 | |
| | 276 | >>> yesno(False, 'certainly,get out of town,perhaps') |
| | 277 | 'get out of town' |
| | 278 | |
| | 279 | >>> yesno(None, 'certainly,get out of town,perhaps') |
| | 280 | 'perhaps' |
| | 281 | |
| | 282 | >>> yesno(None, 'certainly,get out of town') |
| | 283 | 'get out of town' |
| | 284 | |
| | 285 | >>> filesizeformat(1023) |
| | 286 | '1023 bytes' |
| | 287 | |
| | 288 | >>> filesizeformat(1024) |
| | 289 | '1.0 KB' |
| | 290 | |
| | 291 | >>> filesizeformat(10*1024) |
| | 292 | '10.0 KB' |
| | 293 | |
| | 294 | >>> filesizeformat(1024*1024-1) |
| | 295 | '1024.0 KB' |
| | 296 | |
| | 297 | >>> filesizeformat(1024*1024) |
| | 298 | '1.0 MB' |
| | 299 | |
| | 300 | >>> filesizeformat(1024*1024*50) |
| | 301 | '50.0 MB' |
| | 302 | |
| | 303 | >>> filesizeformat(1024*1024*1024-1) |
| | 304 | '1024.0 MB' |
| | 305 | |
| | 306 | >>> filesizeformat(1024*1024*1024) |
| | 307 | '1.0 GB' |
| | 308 | |
| | 309 | >>> pluralize(1) |
| | 310 | '' |
| | 311 | |
| | 312 | >>> pluralize(0) |
| | 313 | 's' |
| | 314 | |
| | 315 | >>> pluralize(2) |
| | 316 | 's' |
| | 317 | |
| | 318 | >>> phone2numeric('0800 flowers') |
| | 319 | '0800 3569377' |
| | 320 | |
| | 321 | |
| | 322 | |