def __repr__(self):
		"""return string representation of entry
		
		:note: 2006-08-11:eliminate final comma, handle months-> macro and journal macros
		"""
		stringrep = '@%s{%s,\n' % (self.entry_type.upper() , self.citekey)
		try:
			mlen = max( len(key_str) for key_str in self._fields )  # for pretty format
		except ValueError: #no fields (not a true entry)
			mlen = 0
			bibfile_logger.warn("Entry apparently has no fields.")
		field_list = []
		for key in self._fields:
			addbraces = True
                        addquotes = False
			spacer = ' '*(mlen - len(key) )
			val = self[key]
			#handle crossref
			if key == 'crossref':
				try: val = val['citekey'] #might be an entry
				except TypeError: pass    #->must be a string
			elif key == 'journal':
				if val.isalpha() and val.islower(): #:TODO: allow punctuation!!
					addbraces = False  #i.e., assume it is a macro
			elif key == 'month':
				# always use month macros if possible
				if val.lower() in monthslower_en + monthmacros_en:
					val = val[:3].lower()
					addbraces = False
			elif key in ("year","number","volume","chapter"):
				try:
					addbraces = not int(val)
				except:
					pass
                        if '@' in val:  # need to protect '@'
                                addquotes = True
                        if addquotes:
                                val = '"' + val + '"'
			elif addbraces:
				val = "{" + val + "}"
			field_list.append("  %-*s = %s" % (mlen, key, val))
		stringrep += ",\n".join(field_list)
		stringrep += '\n}\n'
		return stringrep
dataset/ETHPy150Open matthew-brett/bibstuff/bibstuff/bibfile.py/BibEntry.__repr__/original