summaryrefslogtreecommitdiff
path: root/tablib/helpers.py
blob: 31b4558415f2ebed612dc570f9cda8e3ad380044 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding: utf-8 -*-

""" Tablib - General Helpers.
"""

import sys


class Struct(object):
	"""Your attributes are belong to us."""
	
	def __init__(self, **entries): 
		self.__dict__.update(entries)
		
	def __getitem__(self, key):
		return getattr(self, key, None)

	def dictionary(self):
		"""Returns dictionary representation of object."""
		return self.__dict__


def piped():
	"""Returns piped input via stdin, else False."""
	with sys.stdin as stdin:
		# TTY is only way to detect if stdin contains data
		return stdin.read() if not stdin.isatty() else None