Files
deb-python-pecan/pecan/util.py
Jonathan LaCour bed5cbfa14 After a full-scale scan with pep8.py and pyflakes, identified and
resolved most of our PEP8 compliance issues.
2012-03-11 09:52:25 -07:00

46 lines
979 B
Python

import sys
import os
def iscontroller(obj):
return getattr(obj, 'exposed', False)
def _cfg(f):
if not hasattr(f, '_pecan'):
f._pecan = {}
return f._pecan
def compat_splitext(path):
"""
This method emulates the behavior os.path.splitext introduced in python 2.6
"""
basename = os.path.basename(path)
index = basename.rfind('.')
if index > 0:
root = basename[:index]
if root.count('.') != index:
return (
os.path.join(os.path.dirname(path), root),
basename[index:]
)
return (path, '')
# use the builtin splitext unless we're python 2.5
if sys.version_info >= (2, 6):
from os.path import splitext
else: # pragma no cover
splitext = compat_splitext # noqa
if sys.version_info >= (2, 6, 5):
def encode_if_needed(s):
return s
else:
def encode_if_needed(s): # noqa
return s.encode('utf-8')