Skip to content

Commit

Permalink
Added a key_name utility function to use with to_dict() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Worrell committed Mar 2, 2015
1 parent 1c83e54 commit 2bf9616
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion stix/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ def attr_name(name):
Example:
>>> attr_name("id")
'id_'
>>> attr_name("title")
>>> attr_name("Title")
'title
"""
name = name.lower()

if name.startswith("_"):
name = name[1:]

Expand All @@ -122,6 +124,19 @@ def attr_name(name):
return name


def key_name(name):
"""Converts the input attribute name `name` into a key to be
used in `to_dict()` return dictionaries.
"""
name = attr_name(name)

if name.endswith("_"):
return name[:-1]

return name


def is_sequence(item):
"""Returns ``True`` if `value` is a sequence type (e.g., ``list``, or
``tuple``). String types will return ``False``.
Expand Down

0 comments on commit 2bf9616

Please sign in to comment.