#NEWLINE# def format_date( date = None , format = 'medium' , locale = LC_TIME ) : #NEWLINE# #INDENT# 'Return a date formatted according to the given pattern.\n    \n    >>> d = date(2007, 04, 01)\n    >>> format_date(d, locale=\'en_US\')\n    u\'Apr 1, 2007\'\n    >>> format_date(d, format=\'full\', locale=\'de_DE\')\n    u\'Sonntag, 1. April 2007\'\n    \n    If you don\'t want to use the locale default formats, you can specify a\n    custom date pattern:\n    \n    >>> format_date(d, "EEE, MMM d, \'\'yy", locale=\'en\')\n    u"Sun, Apr 1, \'07"\n    \n    :param date: the ``date`` or ``datetime`` object; if `None`, the current\n                 date is used\n    :param format: one of "full", "long", "medium", or "short", or a custom\n                   date/time pattern\n    :param locale: a `Locale` object or a locale identifier\n    :rtype: `unicode`\n    \n    :note: If the pattern contains time fields, an `AttributeError` will be\n           raised when trying to apply the formatting. This is also true if\n           the value of ``date`` parameter is actually a ``datetime`` object,\n           as this function automatically converts that to a ``date``.\n    ' #NEWLINE# if ( date is None ) : #NEWLINE# #INDENT# date = date_ . today ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( date , datetime ) : #NEWLINE# #INDENT# date = date . date ( ) #NEWLINE# #UNINDENT# #UNINDENT# locale = Locale . parse ( locale ) #NEWLINE# if ( format in ( 'full' , 'long' , 'medium' , 'short' ) ) : #NEWLINE# #INDENT# format = get_date_format ( format , locale = locale ) #NEWLINE# #UNINDENT# pattern = parse_pattern ( format ) #NEWLINE# return pattern . apply ( date , locale )