<commit_before># PyFileMaker - Integrating FileMaker and Python
# (c) 2014-2016 <NAME>, <EMAIL>
# (c) 2006-2008 <NAME>, <EMAIL>
# (c) 2002-2006 <NAME>, <EMAIL>
#
# http://code.google.com/p/pyfilemaker/
# http://www.yellowduck.be/filemaker/

# Import the main modules
import sys
import re
import string
import urllib
import urlparse
import requests
import collections
import datetime

# Import the FM modules
import FMResultset
from FMError import *

uu = urllib.urlencode

class FMServer:
	"""The main class for communicating with FileMaker Server"""

	def __init__(self, url='http://login:password@localhost/fmi/xml/fmresultset.xml', db='', layout='', debug=False):
		"""Class constructor"""

		self._url = url
		parsed = urlparse.urlparse(self._url)

		self._protocol = parsed.scheme   or 'http'
		self._login    = parsed.username or 'pyfilemaker'
		self._password = parsed.password or ''
		self._host     = parsed.hostname or 'localhost'
		self._port     = parsed.port     or (443 if self._protocol == 'https' else 80)
		self._address  = parsed.path     or '/fmi/xml/fmresultset.xml'

		self._file_address = 'fmi/xml/cnt/data.%(extension)s'
		self._extra_script = None

		self._maxRecords = 0
		self._skipRecords = 0

		self._db = db
		self._layout = layout
		self._lop = 'and'

		self._dbParams = []
		self._sortParams = []

		self._debug = debug
		if '--debug' in sys.argv and not debug:
			self._debug = True

	@staticmethod
	def toJSON(fm_data, to_lower=False):
		if str(type(fm_data)) == "<type 'instance'>":
			ml = []
			for obj in fm_data:
				ml.append(FMServer.toJSON(obj))
			return ml
		elif str(type(fm_data)) == "<class 'PyFileMaker.FMData.FMData'>":
			d = {}
			for field in fm_data:
				orig_f = field
				if to_lower:
					field = field.lower()
				d[field] = FMServer.toJSON(fm_data[orig_f])
			return d
		elif type(fm_data) == list:
			l = []
			for item in fm_data:
				l.append(FMServer.toJSON(item))
			return l
		elif isinstance(fm_data, datetime.datetime):
			return fm_data.strftime('%d/%m/%Y %H:%M')
		elif isinstance(fm_data, datetime.date):
			return fm_data.strftime('%d/%m/%Y')
		elif isinstance(fm_data, datetime.time):
			return fm_data.strftime('%H:%M')
		else:
			return fm_data

	def setDb(self, db):
		"""Select the database to use. You don't need to specify the file
		extension. PyFileMaker will do this automatically."""

		self._db = db<commit_msg>patched datetime.time instance type so that it returns seconds if available<commit_after># PyFileMaker - Integrating FileMaker and Python
# (c) 2014-2016 <NAME>, <EMAIL>
# (c) 2006-2008 <NAME>, <EMAIL>
# (c) 2002-2006 <NAME>, <EMAIL>
#
# http://code.google.com/p/pyfilemaker/
# http://www.yellowduck.be/filemaker/

# Import the main modules
import sys
import re
import string
import urllib
import urlparse
import requests
import collections
import datetime

# Import the FM modules
import FMResultset
from FMError import *

uu = urllib.urlencode

class FMServer:
	"""The main class for communicating with FileMaker Server"""

	def __init__(self, url='http://login:password@localhost/fmi/xml/fmresultset.xml', db='', layout='', debug=False):
		"""Class constructor"""

		self._url = url
		parsed = urlparse.urlparse(self._url)

		self._protocol = parsed.scheme   or 'http'
		self._login    = parsed.username or 'pyfilemaker'
		self._password = parsed.password or ''
		self._host     = parsed.hostname or 'localhost'
		self._port     = parsed.port     or (443 if self._protocol == 'https' else 80)
		self._address  = parsed.path     or '/fmi/xml/fmresultset.xml'

		self._file_address = 'fmi/xml/cnt/data.%(extension)s'
		self._extra_script = None

		self._maxRecords = 0
		self._skipRecords = 0

		self._db = db
		self._layout = layout
		self._lop = 'and'

		self._dbParams = []
		self._sortParams = []

		self._debug = debug
		if '--debug' in sys.argv and not debug:
			self._debug = True

	@staticmethod
	def toJSON(fm_data, to_lower=False):
		if str(type(fm_data)) == "<type 'instance'>":
			ml = []
			for obj in fm_data:
				ml.append(FMServer.toJSON(obj))
			return ml
		elif str(type(fm_data)) == "<class 'PyFileMaker.FMData.FMData'>":
			d = {}
			for field in fm_data:
				orig_f = field
				if to_lower:
					field = field.lower()
				d[field] = FMServer.toJSON(fm_data[orig_f])
			return d
		elif type(fm_data) == list:
			l = []
			for item in fm_data:
				l.append(FMServer.toJSON(item))
			return l
		elif isinstance(fm_data, datetime.datetime):
			return fm_data.strftime('%d/%m/%Y %H:%M')
		elif isinstance(fm_data, datetime.date):
			return fm_data.strftime('%d/%m/%Y')
		elif isinstance(fm_data, datetime.time):
			if fm_data.second != 0:
				return fm_data.strftime('%H:%M:%S')
			else:
				return fm_data.strftime('%H:%M')
		else:
			return fm_data

	def setDb(self, db):
		"""Select the database to use. You don't need to specify the file
		extension. PyFileMaker will do this automatically."""

		self._db = db
{'fraction_non_alphanumeric': 0.13447085110704854, 'fraction_numerical': 0.012797074954296161, 'mean_word_length': 3.6365348399246704, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4190734', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1695, 'n_words': 447}