# Path: floyd/util/unicode.py
# def force_unicode(text, encoding='utf-8'):
#   """
#   
#   @TODO encoding support
#   """
#   if text == None:
#     return u''
# 
#   try:
#     text = unicode(text, 'utf-8')
#   except UnicodeDecodeError:
#     text = unicode(text, 'latin1')
#   except TypeError:
#     text = unicode(text)
#   return text
# 
# def force_utf8(text):
#   return str(force_unicode(text).encode('utf8'))
# 
# Path: floyd/util/dates.py
# MONTHS = {
#     1:_('January'), 2:_('February'), 3:_('March'), 4:_('April'), 5:_('May'), 6:_('June'),
#     7:_('July'), 8:_('August'), 9:_('September'), 10:_('October'), 11:_('November'),
#     12:_('December')
# }
# 
# MONTHS_3 = {
#     1:_('jan'), 2:_('feb'), 3:_('mar'), 4:_('apr'), 5:_('may'), 6:_('jun'),
#     7:_('jul'), 8:_('aug'), 9:_('sep'), 10:_('oct'), 11:_('nov'), 12:_('dec')
# }
# 
# MONTHS_AP = { # month names in Associated Press style
#     1:_('Jan.'), 2:_('Feb.'), 3:_('March'), 4:_('April'), 5:_('May'), 6:_('June'), 7:_('July'),
#     8:_('Aug.'), 9:_('Sept.'), 10:_('Oct.'), 11:_('Nov.'), 12:_('Dec.')
# }
# 
# WEEKDAYS = {
#     0:_('Monday'), 1:_('Tuesday'), 2:_('Wednesday'), 3:_('Thursday'), 4:_('Friday'),
#     5:_('Saturday'), 6:_('Sunday')
# }
# 
# WEEKDAYS_ABBR = {
#     0:_('Mon'), 1:_('Tue'), 2:_('Wed'), 3:_('Thu'), 4:_('Fri'),
#     5:_('Sat'), 6:_('Sun')
# }
# 
# Path: floyd/util/translation.py
# def ugettext(str, format=unicode):
#   return force_unicode(str)


import re
import time
import calendar
import time
from datetime import tzinfo, timedelta
from floyd.util.unicode import force_unicode, force_utf8
from floyd.util.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
from floyd.util.translation import ugettext as _
  from email.utils import formatdate
  from rfc822 import formatdate as HTTPDate


try:
  def HTTPDate(timeval=None):
    return formatdate(timeval, usegmt=True)
except ImportError:

class LocalTimezone(tzinfo):
    "Proxy timezone information from time module."
    def __init__(self, dt):
        tzinfo.__init__(self)
        self._tzname = self.tzname(dt)

    def __repr__(self):
        return smart_str(self._tzname)

    def utcoffset(self, dt):
        if self._isdst(dt):
            return timedelta(seconds=-time.altzone)
        else:
            return timedelta(seconds=-time.timezone)

    def dst(self, dt):
        if self._isdst(dt):
            return timedelta(seconds=-time.altzone) - timedelta(seconds=-time.timezone)
        else:
            return timedelta(0)

    def tzname(self, dt):
        try:

# Path: floyd/util/unicode.py
# def force_unicode(text, encoding='utf-8'):
#   """
#   
#   @TODO encoding support
#   """
#   if text == None:
#     return u''
# 
#   try:
#     text = unicode(text, 'utf-8')
#   except UnicodeDecodeError:
#     text = unicode(text, 'latin1')
#   except TypeError:
#     text = unicode(text)
#   return text
# 
# def force_utf8(text):
#   return str(force_unicode(text).encode('utf8'))
# 
# Path: floyd/util/dates.py
# MONTHS = {
#     1:_('January'), 2:_('February'), 3:_('March'), 4:_('April'), 5:_('May'), 6:_('June'),
#     7:_('July'), 8:_('August'), 9:_('September'), 10:_('October'), 11:_('November'),
#     12:_('December')
# }
# 
# MONTHS_3 = {
#     1:_('jan'), 2:_('feb'), 3:_('mar'), 4:_('apr'), 5:_('may'), 6:_('jun'),
#     7:_('jul'), 8:_('aug'), 9:_('sep'), 10:_('oct'), 11:_('nov'), 12:_('dec')
# }
# 
# MONTHS_AP = { # month names in Associated Press style
#     1:_('Jan.'), 2:_('Feb.'), 3:_('March'), 4:_('April'), 5:_('May'), 6:_('June'), 7:_('July'),
#     8:_('Aug.'), 9:_('Sept.'), 10:_('Oct.'), 11:_('Nov.'), 12:_('Dec.')
# }
# 
# WEEKDAYS = {
#     0:_('Monday'), 1:_('Tuesday'), 2:_('Wednesday'), 3:_('Thursday'), 4:_('Friday'),
#     5:_('Saturday'), 6:_('Sunday')
# }
# 
# WEEKDAYS_ABBR = {
#     0:_('Mon'), 1:_('Tue'), 2:_('Wed'), 3:_('Thu'), 4:_('Fri'),
#     5:_('Sat'), 6:_('Sun')
# }
# 
# Path: floyd/util/translation.py
# def ugettext(str, format=unicode):
#   return force_unicode(str)


# Path: floyd/util/dateformat.py
import re
import time
import calendar
import time
from datetime import tzinfo, timedelta
from floyd.util.unicode import force_unicode, force_utf8
from floyd.util.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
from floyd.util.translation import ugettext as _
  from email.utils import formatdate
  from rfc822 import formatdate as HTTPDate



try:
  def HTTPDate(timeval=None):
    return formatdate(timeval, usegmt=True)
except ImportError:

class LocalTimezone(tzinfo):
    "Proxy timezone information from time module."
    def __init__(self, dt):
        tzinfo.__init__(self)
        self._tzname = self.tzname(dt)

    def __repr__(self):
        return smart_str(self._tzname)

    def utcoffset(self, dt):
        if self._isdst(dt):
            return timedelta(seconds=-time.altzone)
        else:
            return timedelta(seconds=-time.timezone)

    def dst(self, dt):
        if self._isdst(dt):
            return timedelta(seconds=-time.altzone) - timedelta(seconds=-time.timezone)
        else:
            return timedelta(0)

    def tzname(self, dt):
        try:

            return force_unicode(time.tzname[self._isdst(dt)], 'utf-8')