Skip to content

Commit

Permalink
Merge branch 'burhan-string-methods' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
joke2k committed Sep 23, 2015
2 parents 1d48d5b + 6ebc1c2 commit f986a3e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 20 additions & 4 deletions environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ def get_value(self, var, cast=None, default=NOTSET, parse_default=False):
:returns: Value from environment or default (if set)
"""

logger.debug("get '{0}' casted as '{1}' with default '{2}'".format(var, cast, default))
logger.debug("get '{0}' casted as '{1}' with default '{2}'".format(
var, cast, default
))

if var in self.scheme:
var_info = self.scheme[var]
Expand Down Expand Up @@ -290,7 +292,10 @@ def parse_value(cls, value, cast):
value_cast = cast.get('value', str)
value_cast_by_key = cast.get('cast', dict())
value = dict(map(
lambda kv: (key_cast(kv[0]), cls.parse_value(kv[1], value_cast_by_key.get(kv[0], value_cast))),
lambda kv: (
key_cast(kv[0]),
cls.parse_value(kv[1], value_cast_by_key.get(kv[0], value_cast))
),
[val.split('=') for val in value.split(';') if val]
))
elif cast is dict:
Expand Down Expand Up @@ -675,7 +680,8 @@ def __sub__(self, other):
return self.path('../' * other)
elif isinstance(other, string_types):
return Path(self.__root__.rstrip(other))
raise TypeError("unsupported operand type(s) for -: '{0}' and '{1}'".format(self, type(other)))
raise TypeError(
"unsupported operand type(s) for -: '{0}' and '{1}'".format(self, type(other)))

def __invert__(self):
return self.path('..')
Expand All @@ -695,11 +701,21 @@ def __str__(self):
def __unicode__(self):
return self.__str__()

def __getitem__(self, *args, **kwargs):
return self.__str__().__getitem__(*args, **kwargs)

def rfind(self, *args, **kwargs):
return self.__str__().rfind(*args, **kwargs)

def find(self, *args, **kwargs):
return self.__str__().find(*args, **kwargs)

@staticmethod
def _absolute_join(base, *paths, **kwargs):
absolute_path = os.path.abspath(os.path.join(base, *paths))
if kwargs.get('required', False) and not os.path.exists(absolute_path):
raise ImproperlyConfigured("Create required path: {0}".format(absolute_path))
raise ImproperlyConfigured(
"Create required path: {0}".format(absolute_path))
return absolute_path


Expand Down
4 changes: 4 additions & 0 deletions environ/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ def test_comparison(self):
self.assertTrue(Path('/home') == Path('/home'))
self.assertTrue(Path('/home') != Path('/home/dev'))

self.assertEqual(Path('/home/foo/').rfind('/'), str(Path('/home/foo')).rfind('/'))
self.assertEqual(Path('/home/foo/').find('/home'), str(Path('/home/foo/')).find('/home'))
self.assertEqual(Path('/home/foo/')[1], str(Path('/home/foo/'))[1])

self.assertEqual(~Path('/home'), Path('/'))
self.assertEqual(Path('/') + 'home', Path('/home'))
self.assertEqual(Path('/') + '/home/public', Path('/home/public'))
Expand Down

0 comments on commit f986a3e

Please sign in to comment.