def _detect_timezone_etc_localtime():
matches = []
if os.path.exists("/etc/localtime"):
localtime = pytz.tzfile.build_tzinfo("/etc/localtime",
file("/etc/localtime"))
# See if we can find a "Human Name" for this..
for tzname in pytz.all_timezones:
tz = _tzinfome(tzname)
if dir(tz) != dir(localtime):
continue
for attrib in dir(tz):
# Ignore functions and specials
if callable(getattr(tz, attrib)) or attrib.startswith("__"):
continue
# This will always be different
if attrib == "zone" or attrib == "_tzinfos":
continue
if getattr(tz, attrib) != getattr(localtime, attrib):
break
# We get here iff break didn't happen, i.e. no meaningful attributes
# differ between tz and localtime
else:
matches.append(tzname)
#if len(matches) == 1:
# return _tzinfome(matches[0])
#else:
# # Warn the person about this!
# warning = "Could not get a human name for your timezone: "
# if len(matches) > 1:
# warning += ("We detected multiple matches for your /etc/localtime. "
# "(Matches where %s)" % matches)
# else:
# warning += "We detected no matches for your /etc/localtime."
# warnings.warn(warning)
#
# return localtime
if len(matches) > 0:
return _tzinfome(matches[0])
评论列表
文章目录