Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. from django.utils import simplejson
  2.  
  3. class DatetimeJSONEncoder(simplejson.JSONEncoder):
  4.  
  5.     class DateInt(int):
  6.         '''
            ÐÐ°ÑÐ»ÐµÐ´ÑƒÐµÐ¼ÑÑ Ð¾Ñ‚ int, Ð¿Ð¾Ñ‚ому Ñ‡Ñ‚о Ñ‚огда Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ðµ Ð±ÑƒÐ´ÐµÑ‚ Ð±ÐµÐ· "".
            Ð’ Ð´Ñ€ÑƒÐ³Ð¸Ñ… ÑÐ»ÑƒÑ‡Ð°ÑÑ… Ð¿Ð¾Ð»ÑƒÑ‡Ð¸Ð¼: "new Date(100500)" Ð¸ Ð¿Ñ€Ð¸ eval Ð±ÑƒÐ´ÐµÑ‚ Ð¿Ñ€Ð¾ÑÑ‚о
            ÑÑ‚рока.
            '''
  7.         def __str__(self):
  8.             return 'new Date(%s)' % (self*1000)
  9.  
  10.     def default(self, o):
  11.         from django.utils import datetime_safe
  12.         from datetime import datetime
  13.         import time
  14.  
  15.         if isinstance(o, datetime):
  16.             d = datetime_safe.new_datetime(o)
  17.             return self.DateInt(int(time.mktime(d.timetuple())))
  18.         else:
  19.             return super(DatetimeJSONEncoder, self).default(o)
  20.  
  21. #example
  22. from datetime import datetime
  23. from django.utils import simplejson
  24.  
  25. data = dict(date=datetime.now())
  26. json = simplejson.dumps(data, cls=DjangoJSONEncoder)




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2012