prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>test_different_outputs.py<|end_file_name|><|fim▁begin|>import unittest from polycircles import polycircles from nose.tools import assert_equal, assert_almost_equal class TestDifferentOutputs(unittest.TestCase): """Tests the various output methods: KML style, WKT, lat-lon and lon-lat.""" def setUp(self): self.latitude = 32.074322 self.longitude = 34.792081 self.radius_meters = 100 self.number_of_vertices = 36 self.polycircle = \ polycircles.Polycircle(latitude=self.latitude, longitude=self.longitude, radius=self.radius_meters, number_of_vertices=self.number_of_vertices) def test_lat_lon_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lat_lon(): assert_almost_equal(vertex[0], self.latitude, places=2) assert_almost_equal(vertex[1], self.longitude, places=2) def test_lon_lat_output(self): <|fim_middle|> def test_vertices_equals_lat_lon(self): """Asserts that the "vertices" property is identical to the return value of to_lat_lon().""" assert_equal(self.polycircle.vertices, self.polycircle.to_lat_lon()) def test_kml_equals_lon_lat(self): """Asserts that the return value of to_kml() property is identical to the return value of to_lon_lat().""" assert_equal(self.polycircle.to_kml(), self.polycircle.to_lon_lat()) if __name__ == '__main__': unittest.main()<|fim▁end|>
"""Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lon_lat(): assert_almost_equal(vertex[0], self.longitude, places=2) assert_almost_equal(vertex[1], self.latitude, places=2)
<|file_name|>test_different_outputs.py<|end_file_name|><|fim▁begin|>import unittest from polycircles import polycircles from nose.tools import assert_equal, assert_almost_equal class TestDifferentOutputs(unittest.TestCase): """Tests the various output methods: KML style, WKT, lat-lon and lon-lat.""" def setUp(self): self.latitude = 32.074322 self.longitude = 34.792081 self.radius_meters = 100 self.number_of_vertices = 36 self.polycircle = \ polycircles.Polycircle(latitude=self.latitude, longitude=self.longitude, radius=self.radius_meters, number_of_vertices=self.number_of_vertices) def test_lat_lon_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lat_lon(): assert_almost_equal(vertex[0], self.latitude, places=2) assert_almost_equal(vertex[1], self.longitude, places=2) def test_lon_lat_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lon_lat(): assert_almost_equal(vertex[0], self.longitude, places=2) assert_almost_equal(vertex[1], self.latitude, places=2) def test_vertices_equals_lat_lon(self): <|fim_middle|> def test_kml_equals_lon_lat(self): """Asserts that the return value of to_kml() property is identical to the return value of to_lon_lat().""" assert_equal(self.polycircle.to_kml(), self.polycircle.to_lon_lat()) if __name__ == '__main__': unittest.main()<|fim▁end|>
"""Asserts that the "vertices" property is identical to the return value of to_lat_lon().""" assert_equal(self.polycircle.vertices, self.polycircle.to_lat_lon())
<|file_name|>test_different_outputs.py<|end_file_name|><|fim▁begin|>import unittest from polycircles import polycircles from nose.tools import assert_equal, assert_almost_equal class TestDifferentOutputs(unittest.TestCase): """Tests the various output methods: KML style, WKT, lat-lon and lon-lat.""" def setUp(self): self.latitude = 32.074322 self.longitude = 34.792081 self.radius_meters = 100 self.number_of_vertices = 36 self.polycircle = \ polycircles.Polycircle(latitude=self.latitude, longitude=self.longitude, radius=self.radius_meters, number_of_vertices=self.number_of_vertices) def test_lat_lon_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lat_lon(): assert_almost_equal(vertex[0], self.latitude, places=2) assert_almost_equal(vertex[1], self.longitude, places=2) def test_lon_lat_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lon_lat(): assert_almost_equal(vertex[0], self.longitude, places=2) assert_almost_equal(vertex[1], self.latitude, places=2) def test_vertices_equals_lat_lon(self): """Asserts that the "vertices" property is identical to the return value of to_lat_lon().""" assert_equal(self.polycircle.vertices, self.polycircle.to_lat_lon()) def test_kml_equals_lon_lat(self): <|fim_middle|> if __name__ == '__main__': unittest.main()<|fim▁end|>
"""Asserts that the return value of to_kml() property is identical to the return value of to_lon_lat().""" assert_equal(self.polycircle.to_kml(), self.polycircle.to_lon_lat())
<|file_name|>test_different_outputs.py<|end_file_name|><|fim▁begin|>import unittest from polycircles import polycircles from nose.tools import assert_equal, assert_almost_equal class TestDifferentOutputs(unittest.TestCase): """Tests the various output methods: KML style, WKT, lat-lon and lon-lat.""" def setUp(self): self.latitude = 32.074322 self.longitude = 34.792081 self.radius_meters = 100 self.number_of_vertices = 36 self.polycircle = \ polycircles.Polycircle(latitude=self.latitude, longitude=self.longitude, radius=self.radius_meters, number_of_vertices=self.number_of_vertices) def test_lat_lon_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lat_lon(): assert_almost_equal(vertex[0], self.latitude, places=2) assert_almost_equal(vertex[1], self.longitude, places=2) def test_lon_lat_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lon_lat(): assert_almost_equal(vertex[0], self.longitude, places=2) assert_almost_equal(vertex[1], self.latitude, places=2) def test_vertices_equals_lat_lon(self): """Asserts that the "vertices" property is identical to the return value of to_lat_lon().""" assert_equal(self.polycircle.vertices, self.polycircle.to_lat_lon()) def test_kml_equals_lon_lat(self): """Asserts that the return value of to_kml() property is identical to the return value of to_lon_lat().""" assert_equal(self.polycircle.to_kml(), self.polycircle.to_lon_lat()) if __name__ == '__main__': <|fim_middle|> <|fim▁end|>
unittest.main()
<|file_name|>test_different_outputs.py<|end_file_name|><|fim▁begin|>import unittest from polycircles import polycircles from nose.tools import assert_equal, assert_almost_equal class TestDifferentOutputs(unittest.TestCase): """Tests the various output methods: KML style, WKT, lat-lon and lon-lat.""" def <|fim_middle|>(self): self.latitude = 32.074322 self.longitude = 34.792081 self.radius_meters = 100 self.number_of_vertices = 36 self.polycircle = \ polycircles.Polycircle(latitude=self.latitude, longitude=self.longitude, radius=self.radius_meters, number_of_vertices=self.number_of_vertices) def test_lat_lon_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lat_lon(): assert_almost_equal(vertex[0], self.latitude, places=2) assert_almost_equal(vertex[1], self.longitude, places=2) def test_lon_lat_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lon_lat(): assert_almost_equal(vertex[0], self.longitude, places=2) assert_almost_equal(vertex[1], self.latitude, places=2) def test_vertices_equals_lat_lon(self): """Asserts that the "vertices" property is identical to the return value of to_lat_lon().""" assert_equal(self.polycircle.vertices, self.polycircle.to_lat_lon()) def test_kml_equals_lon_lat(self): """Asserts that the return value of to_kml() property is identical to the return value of to_lon_lat().""" assert_equal(self.polycircle.to_kml(), self.polycircle.to_lon_lat()) if __name__ == '__main__': unittest.main()<|fim▁end|>
setUp
<|file_name|>test_different_outputs.py<|end_file_name|><|fim▁begin|>import unittest from polycircles import polycircles from nose.tools import assert_equal, assert_almost_equal class TestDifferentOutputs(unittest.TestCase): """Tests the various output methods: KML style, WKT, lat-lon and lon-lat.""" def setUp(self): self.latitude = 32.074322 self.longitude = 34.792081 self.radius_meters = 100 self.number_of_vertices = 36 self.polycircle = \ polycircles.Polycircle(latitude=self.latitude, longitude=self.longitude, radius=self.radius_meters, number_of_vertices=self.number_of_vertices) def <|fim_middle|>(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lat_lon(): assert_almost_equal(vertex[0], self.latitude, places=2) assert_almost_equal(vertex[1], self.longitude, places=2) def test_lon_lat_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lon_lat(): assert_almost_equal(vertex[0], self.longitude, places=2) assert_almost_equal(vertex[1], self.latitude, places=2) def test_vertices_equals_lat_lon(self): """Asserts that the "vertices" property is identical to the return value of to_lat_lon().""" assert_equal(self.polycircle.vertices, self.polycircle.to_lat_lon()) def test_kml_equals_lon_lat(self): """Asserts that the return value of to_kml() property is identical to the return value of to_lon_lat().""" assert_equal(self.polycircle.to_kml(), self.polycircle.to_lon_lat()) if __name__ == '__main__': unittest.main()<|fim▁end|>
test_lat_lon_output
<|file_name|>test_different_outputs.py<|end_file_name|><|fim▁begin|>import unittest from polycircles import polycircles from nose.tools import assert_equal, assert_almost_equal class TestDifferentOutputs(unittest.TestCase): """Tests the various output methods: KML style, WKT, lat-lon and lon-lat.""" def setUp(self): self.latitude = 32.074322 self.longitude = 34.792081 self.radius_meters = 100 self.number_of_vertices = 36 self.polycircle = \ polycircles.Polycircle(latitude=self.latitude, longitude=self.longitude, radius=self.radius_meters, number_of_vertices=self.number_of_vertices) def test_lat_lon_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lat_lon(): assert_almost_equal(vertex[0], self.latitude, places=2) assert_almost_equal(vertex[1], self.longitude, places=2) def <|fim_middle|>(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lon_lat(): assert_almost_equal(vertex[0], self.longitude, places=2) assert_almost_equal(vertex[1], self.latitude, places=2) def test_vertices_equals_lat_lon(self): """Asserts that the "vertices" property is identical to the return value of to_lat_lon().""" assert_equal(self.polycircle.vertices, self.polycircle.to_lat_lon()) def test_kml_equals_lon_lat(self): """Asserts that the return value of to_kml() property is identical to the return value of to_lon_lat().""" assert_equal(self.polycircle.to_kml(), self.polycircle.to_lon_lat()) if __name__ == '__main__': unittest.main()<|fim▁end|>
test_lon_lat_output
<|file_name|>test_different_outputs.py<|end_file_name|><|fim▁begin|>import unittest from polycircles import polycircles from nose.tools import assert_equal, assert_almost_equal class TestDifferentOutputs(unittest.TestCase): """Tests the various output methods: KML style, WKT, lat-lon and lon-lat.""" def setUp(self): self.latitude = 32.074322 self.longitude = 34.792081 self.radius_meters = 100 self.number_of_vertices = 36 self.polycircle = \ polycircles.Polycircle(latitude=self.latitude, longitude=self.longitude, radius=self.radius_meters, number_of_vertices=self.number_of_vertices) def test_lat_lon_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lat_lon(): assert_almost_equal(vertex[0], self.latitude, places=2) assert_almost_equal(vertex[1], self.longitude, places=2) def test_lon_lat_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lon_lat(): assert_almost_equal(vertex[0], self.longitude, places=2) assert_almost_equal(vertex[1], self.latitude, places=2) def <|fim_middle|>(self): """Asserts that the "vertices" property is identical to the return value of to_lat_lon().""" assert_equal(self.polycircle.vertices, self.polycircle.to_lat_lon()) def test_kml_equals_lon_lat(self): """Asserts that the return value of to_kml() property is identical to the return value of to_lon_lat().""" assert_equal(self.polycircle.to_kml(), self.polycircle.to_lon_lat()) if __name__ == '__main__': unittest.main()<|fim▁end|>
test_vertices_equals_lat_lon
<|file_name|>test_different_outputs.py<|end_file_name|><|fim▁begin|>import unittest from polycircles import polycircles from nose.tools import assert_equal, assert_almost_equal class TestDifferentOutputs(unittest.TestCase): """Tests the various output methods: KML style, WKT, lat-lon and lon-lat.""" def setUp(self): self.latitude = 32.074322 self.longitude = 34.792081 self.radius_meters = 100 self.number_of_vertices = 36 self.polycircle = \ polycircles.Polycircle(latitude=self.latitude, longitude=self.longitude, radius=self.radius_meters, number_of_vertices=self.number_of_vertices) def test_lat_lon_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lat_lon(): assert_almost_equal(vertex[0], self.latitude, places=2) assert_almost_equal(vertex[1], self.longitude, places=2) def test_lon_lat_output(self): """Asserts that the vertices in the lat-lon output are in the right order (lat before long).""" for vertex in self.polycircle.to_lon_lat(): assert_almost_equal(vertex[0], self.longitude, places=2) assert_almost_equal(vertex[1], self.latitude, places=2) def test_vertices_equals_lat_lon(self): """Asserts that the "vertices" property is identical to the return value of to_lat_lon().""" assert_equal(self.polycircle.vertices, self.polycircle.to_lat_lon()) def <|fim_middle|>(self): """Asserts that the return value of to_kml() property is identical to the return value of to_lon_lat().""" assert_equal(self.polycircle.to_kml(), self.polycircle.to_lon_lat()) if __name__ == '__main__': unittest.main()<|fim▁end|>
test_kml_equals_lon_lat
<|file_name|>test_documentbylineviewlet.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from imio.history.config import HISTORY_COMMENT_NOT_VIEWABLE from imio.history.interfaces import IImioHistory from imio.history.testing import IntegrationTestCase from plone import api from plone.memoize.instance import Memojito from Products.Five.browser import BrowserView from zope.component import getAdapter from zope.component import getMultiAdapter from zope.viewlet.interfaces import IViewletManager class TestDocumentByLineViewlet(IntegrationTestCase): def setUp(self): super(TestDocumentByLineViewlet, self).setUp() # get the viewlet doc = api.content.create(type='Document', id='doc', container=self.portal) view = BrowserView(doc, self.portal.REQUEST) manager = getMultiAdapter( (doc, self.portal.REQUEST, view), IViewletManager, 'plone.belowcontenttitle') manager.update() self.viewlet = manager.get(u'imio.history.documentbyline') def test_show_history(self): """Test the show_history method. The history is shown in every case except if 'ajax_load' is found in the REQUEST.""" self.assertTrue(self.viewlet.show_history()) # show_history is False if displayed in a popup, aka 'ajax_load' in the REQUEST self.portal.REQUEST.set('ajax_load', True) self.assertFalse(self.viewlet.show_history()) def test_highlight_history_link(self): """Test the highlight_history_link method. History link will be highlighted if last event had a comment and if that comment is not an ignorable comment."""<|fim▁hole|> self.assertFalse(history[-1]['comments']) self.assertFalse(self.viewlet.highlight_history_link()) # now 'publish' the doc and add a comment, last event has a comment self.wft.doActionFor(self.portal.doc, 'publish', comment='my publish comment') # clean memoize getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertTrue(self.viewlet.highlight_history_link()) self.assertFalse(history[-1]['comments'] in adapter.ignorableHistoryComments()) # now test that the 'you can not access this comment' is an ignored message self.wft.doActionFor(self.portal.doc, 'retract', comment=HISTORY_COMMENT_NOT_VIEWABLE) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history[-1]['comments'] in adapter.ignorableHistoryComments()) # test that it works if no history # it is the case if we changed used workflow self.wft.setChainForPortalTypes(('Document', ), ('intranet_workflow',)) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history == [])<|fim▁end|>
adapter = getAdapter(self.portal.doc, IImioHistory, 'workflow') # not highlighted because '' is an ignored comment history = adapter.getHistory()
<|file_name|>test_documentbylineviewlet.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from imio.history.config import HISTORY_COMMENT_NOT_VIEWABLE from imio.history.interfaces import IImioHistory from imio.history.testing import IntegrationTestCase from plone import api from plone.memoize.instance import Memojito from Products.Five.browser import BrowserView from zope.component import getAdapter from zope.component import getMultiAdapter from zope.viewlet.interfaces import IViewletManager class TestDocumentByLineViewlet(IntegrationTestCase): <|fim_middle|> <|fim▁end|>
def setUp(self): super(TestDocumentByLineViewlet, self).setUp() # get the viewlet doc = api.content.create(type='Document', id='doc', container=self.portal) view = BrowserView(doc, self.portal.REQUEST) manager = getMultiAdapter( (doc, self.portal.REQUEST, view), IViewletManager, 'plone.belowcontenttitle') manager.update() self.viewlet = manager.get(u'imio.history.documentbyline') def test_show_history(self): """Test the show_history method. The history is shown in every case except if 'ajax_load' is found in the REQUEST.""" self.assertTrue(self.viewlet.show_history()) # show_history is False if displayed in a popup, aka 'ajax_load' in the REQUEST self.portal.REQUEST.set('ajax_load', True) self.assertFalse(self.viewlet.show_history()) def test_highlight_history_link(self): """Test the highlight_history_link method. History link will be highlighted if last event had a comment and if that comment is not an ignorable comment.""" adapter = getAdapter(self.portal.doc, IImioHistory, 'workflow') # not highlighted because '' is an ignored comment history = adapter.getHistory() self.assertFalse(history[-1]['comments']) self.assertFalse(self.viewlet.highlight_history_link()) # now 'publish' the doc and add a comment, last event has a comment self.wft.doActionFor(self.portal.doc, 'publish', comment='my publish comment') # clean memoize getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertTrue(self.viewlet.highlight_history_link()) self.assertFalse(history[-1]['comments'] in adapter.ignorableHistoryComments()) # now test that the 'you can not access this comment' is an ignored message self.wft.doActionFor(self.portal.doc, 'retract', comment=HISTORY_COMMENT_NOT_VIEWABLE) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history[-1]['comments'] in adapter.ignorableHistoryComments()) # test that it works if no history # it is the case if we changed used workflow self.wft.setChainForPortalTypes(('Document', ), ('intranet_workflow',)) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history == [])
<|file_name|>test_documentbylineviewlet.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from imio.history.config import HISTORY_COMMENT_NOT_VIEWABLE from imio.history.interfaces import IImioHistory from imio.history.testing import IntegrationTestCase from plone import api from plone.memoize.instance import Memojito from Products.Five.browser import BrowserView from zope.component import getAdapter from zope.component import getMultiAdapter from zope.viewlet.interfaces import IViewletManager class TestDocumentByLineViewlet(IntegrationTestCase): def setUp(self): <|fim_middle|> def test_show_history(self): """Test the show_history method. The history is shown in every case except if 'ajax_load' is found in the REQUEST.""" self.assertTrue(self.viewlet.show_history()) # show_history is False if displayed in a popup, aka 'ajax_load' in the REQUEST self.portal.REQUEST.set('ajax_load', True) self.assertFalse(self.viewlet.show_history()) def test_highlight_history_link(self): """Test the highlight_history_link method. History link will be highlighted if last event had a comment and if that comment is not an ignorable comment.""" adapter = getAdapter(self.portal.doc, IImioHistory, 'workflow') # not highlighted because '' is an ignored comment history = adapter.getHistory() self.assertFalse(history[-1]['comments']) self.assertFalse(self.viewlet.highlight_history_link()) # now 'publish' the doc and add a comment, last event has a comment self.wft.doActionFor(self.portal.doc, 'publish', comment='my publish comment') # clean memoize getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertTrue(self.viewlet.highlight_history_link()) self.assertFalse(history[-1]['comments'] in adapter.ignorableHistoryComments()) # now test that the 'you can not access this comment' is an ignored message self.wft.doActionFor(self.portal.doc, 'retract', comment=HISTORY_COMMENT_NOT_VIEWABLE) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history[-1]['comments'] in adapter.ignorableHistoryComments()) # test that it works if no history # it is the case if we changed used workflow self.wft.setChainForPortalTypes(('Document', ), ('intranet_workflow',)) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history == []) <|fim▁end|>
super(TestDocumentByLineViewlet, self).setUp() # get the viewlet doc = api.content.create(type='Document', id='doc', container=self.portal) view = BrowserView(doc, self.portal.REQUEST) manager = getMultiAdapter( (doc, self.portal.REQUEST, view), IViewletManager, 'plone.belowcontenttitle') manager.update() self.viewlet = manager.get(u'imio.history.documentbyline')
<|file_name|>test_documentbylineviewlet.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from imio.history.config import HISTORY_COMMENT_NOT_VIEWABLE from imio.history.interfaces import IImioHistory from imio.history.testing import IntegrationTestCase from plone import api from plone.memoize.instance import Memojito from Products.Five.browser import BrowserView from zope.component import getAdapter from zope.component import getMultiAdapter from zope.viewlet.interfaces import IViewletManager class TestDocumentByLineViewlet(IntegrationTestCase): def setUp(self): super(TestDocumentByLineViewlet, self).setUp() # get the viewlet doc = api.content.create(type='Document', id='doc', container=self.portal) view = BrowserView(doc, self.portal.REQUEST) manager = getMultiAdapter( (doc, self.portal.REQUEST, view), IViewletManager, 'plone.belowcontenttitle') manager.update() self.viewlet = manager.get(u'imio.history.documentbyline') def test_show_history(self): <|fim_middle|> def test_highlight_history_link(self): """Test the highlight_history_link method. History link will be highlighted if last event had a comment and if that comment is not an ignorable comment.""" adapter = getAdapter(self.portal.doc, IImioHistory, 'workflow') # not highlighted because '' is an ignored comment history = adapter.getHistory() self.assertFalse(history[-1]['comments']) self.assertFalse(self.viewlet.highlight_history_link()) # now 'publish' the doc and add a comment, last event has a comment self.wft.doActionFor(self.portal.doc, 'publish', comment='my publish comment') # clean memoize getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertTrue(self.viewlet.highlight_history_link()) self.assertFalse(history[-1]['comments'] in adapter.ignorableHistoryComments()) # now test that the 'you can not access this comment' is an ignored message self.wft.doActionFor(self.portal.doc, 'retract', comment=HISTORY_COMMENT_NOT_VIEWABLE) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history[-1]['comments'] in adapter.ignorableHistoryComments()) # test that it works if no history # it is the case if we changed used workflow self.wft.setChainForPortalTypes(('Document', ), ('intranet_workflow',)) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history == []) <|fim▁end|>
"""Test the show_history method. The history is shown in every case except if 'ajax_load' is found in the REQUEST.""" self.assertTrue(self.viewlet.show_history()) # show_history is False if displayed in a popup, aka 'ajax_load' in the REQUEST self.portal.REQUEST.set('ajax_load', True) self.assertFalse(self.viewlet.show_history())
<|file_name|>test_documentbylineviewlet.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from imio.history.config import HISTORY_COMMENT_NOT_VIEWABLE from imio.history.interfaces import IImioHistory from imio.history.testing import IntegrationTestCase from plone import api from plone.memoize.instance import Memojito from Products.Five.browser import BrowserView from zope.component import getAdapter from zope.component import getMultiAdapter from zope.viewlet.interfaces import IViewletManager class TestDocumentByLineViewlet(IntegrationTestCase): def setUp(self): super(TestDocumentByLineViewlet, self).setUp() # get the viewlet doc = api.content.create(type='Document', id='doc', container=self.portal) view = BrowserView(doc, self.portal.REQUEST) manager = getMultiAdapter( (doc, self.portal.REQUEST, view), IViewletManager, 'plone.belowcontenttitle') manager.update() self.viewlet = manager.get(u'imio.history.documentbyline') def test_show_history(self): """Test the show_history method. The history is shown in every case except if 'ajax_load' is found in the REQUEST.""" self.assertTrue(self.viewlet.show_history()) # show_history is False if displayed in a popup, aka 'ajax_load' in the REQUEST self.portal.REQUEST.set('ajax_load', True) self.assertFalse(self.viewlet.show_history()) def test_highlight_history_link(self): <|fim_middle|> <|fim▁end|>
"""Test the highlight_history_link method. History link will be highlighted if last event had a comment and if that comment is not an ignorable comment.""" adapter = getAdapter(self.portal.doc, IImioHistory, 'workflow') # not highlighted because '' is an ignored comment history = adapter.getHistory() self.assertFalse(history[-1]['comments']) self.assertFalse(self.viewlet.highlight_history_link()) # now 'publish' the doc and add a comment, last event has a comment self.wft.doActionFor(self.portal.doc, 'publish', comment='my publish comment') # clean memoize getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertTrue(self.viewlet.highlight_history_link()) self.assertFalse(history[-1]['comments'] in adapter.ignorableHistoryComments()) # now test that the 'you can not access this comment' is an ignored message self.wft.doActionFor(self.portal.doc, 'retract', comment=HISTORY_COMMENT_NOT_VIEWABLE) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history[-1]['comments'] in adapter.ignorableHistoryComments()) # test that it works if no history # it is the case if we changed used workflow self.wft.setChainForPortalTypes(('Document', ), ('intranet_workflow',)) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history == [])
<|file_name|>test_documentbylineviewlet.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from imio.history.config import HISTORY_COMMENT_NOT_VIEWABLE from imio.history.interfaces import IImioHistory from imio.history.testing import IntegrationTestCase from plone import api from plone.memoize.instance import Memojito from Products.Five.browser import BrowserView from zope.component import getAdapter from zope.component import getMultiAdapter from zope.viewlet.interfaces import IViewletManager class TestDocumentByLineViewlet(IntegrationTestCase): def <|fim_middle|>(self): super(TestDocumentByLineViewlet, self).setUp() # get the viewlet doc = api.content.create(type='Document', id='doc', container=self.portal) view = BrowserView(doc, self.portal.REQUEST) manager = getMultiAdapter( (doc, self.portal.REQUEST, view), IViewletManager, 'plone.belowcontenttitle') manager.update() self.viewlet = manager.get(u'imio.history.documentbyline') def test_show_history(self): """Test the show_history method. The history is shown in every case except if 'ajax_load' is found in the REQUEST.""" self.assertTrue(self.viewlet.show_history()) # show_history is False if displayed in a popup, aka 'ajax_load' in the REQUEST self.portal.REQUEST.set('ajax_load', True) self.assertFalse(self.viewlet.show_history()) def test_highlight_history_link(self): """Test the highlight_history_link method. History link will be highlighted if last event had a comment and if that comment is not an ignorable comment.""" adapter = getAdapter(self.portal.doc, IImioHistory, 'workflow') # not highlighted because '' is an ignored comment history = adapter.getHistory() self.assertFalse(history[-1]['comments']) self.assertFalse(self.viewlet.highlight_history_link()) # now 'publish' the doc and add a comment, last event has a comment self.wft.doActionFor(self.portal.doc, 'publish', comment='my publish comment') # clean memoize getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertTrue(self.viewlet.highlight_history_link()) self.assertFalse(history[-1]['comments'] in adapter.ignorableHistoryComments()) # now test that the 'you can not access this comment' is an ignored message self.wft.doActionFor(self.portal.doc, 'retract', comment=HISTORY_COMMENT_NOT_VIEWABLE) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history[-1]['comments'] in adapter.ignorableHistoryComments()) # test that it works if no history # it is the case if we changed used workflow self.wft.setChainForPortalTypes(('Document', ), ('intranet_workflow',)) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history == []) <|fim▁end|>
setUp
<|file_name|>test_documentbylineviewlet.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from imio.history.config import HISTORY_COMMENT_NOT_VIEWABLE from imio.history.interfaces import IImioHistory from imio.history.testing import IntegrationTestCase from plone import api from plone.memoize.instance import Memojito from Products.Five.browser import BrowserView from zope.component import getAdapter from zope.component import getMultiAdapter from zope.viewlet.interfaces import IViewletManager class TestDocumentByLineViewlet(IntegrationTestCase): def setUp(self): super(TestDocumentByLineViewlet, self).setUp() # get the viewlet doc = api.content.create(type='Document', id='doc', container=self.portal) view = BrowserView(doc, self.portal.REQUEST) manager = getMultiAdapter( (doc, self.portal.REQUEST, view), IViewletManager, 'plone.belowcontenttitle') manager.update() self.viewlet = manager.get(u'imio.history.documentbyline') def <|fim_middle|>(self): """Test the show_history method. The history is shown in every case except if 'ajax_load' is found in the REQUEST.""" self.assertTrue(self.viewlet.show_history()) # show_history is False if displayed in a popup, aka 'ajax_load' in the REQUEST self.portal.REQUEST.set('ajax_load', True) self.assertFalse(self.viewlet.show_history()) def test_highlight_history_link(self): """Test the highlight_history_link method. History link will be highlighted if last event had a comment and if that comment is not an ignorable comment.""" adapter = getAdapter(self.portal.doc, IImioHistory, 'workflow') # not highlighted because '' is an ignored comment history = adapter.getHistory() self.assertFalse(history[-1]['comments']) self.assertFalse(self.viewlet.highlight_history_link()) # now 'publish' the doc and add a comment, last event has a comment self.wft.doActionFor(self.portal.doc, 'publish', comment='my publish comment') # clean memoize getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertTrue(self.viewlet.highlight_history_link()) self.assertFalse(history[-1]['comments'] in adapter.ignorableHistoryComments()) # now test that the 'you can not access this comment' is an ignored message self.wft.doActionFor(self.portal.doc, 'retract', comment=HISTORY_COMMENT_NOT_VIEWABLE) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history[-1]['comments'] in adapter.ignorableHistoryComments()) # test that it works if no history # it is the case if we changed used workflow self.wft.setChainForPortalTypes(('Document', ), ('intranet_workflow',)) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history == []) <|fim▁end|>
test_show_history
<|file_name|>test_documentbylineviewlet.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from imio.history.config import HISTORY_COMMENT_NOT_VIEWABLE from imio.history.interfaces import IImioHistory from imio.history.testing import IntegrationTestCase from plone import api from plone.memoize.instance import Memojito from Products.Five.browser import BrowserView from zope.component import getAdapter from zope.component import getMultiAdapter from zope.viewlet.interfaces import IViewletManager class TestDocumentByLineViewlet(IntegrationTestCase): def setUp(self): super(TestDocumentByLineViewlet, self).setUp() # get the viewlet doc = api.content.create(type='Document', id='doc', container=self.portal) view = BrowserView(doc, self.portal.REQUEST) manager = getMultiAdapter( (doc, self.portal.REQUEST, view), IViewletManager, 'plone.belowcontenttitle') manager.update() self.viewlet = manager.get(u'imio.history.documentbyline') def test_show_history(self): """Test the show_history method. The history is shown in every case except if 'ajax_load' is found in the REQUEST.""" self.assertTrue(self.viewlet.show_history()) # show_history is False if displayed in a popup, aka 'ajax_load' in the REQUEST self.portal.REQUEST.set('ajax_load', True) self.assertFalse(self.viewlet.show_history()) def <|fim_middle|>(self): """Test the highlight_history_link method. History link will be highlighted if last event had a comment and if that comment is not an ignorable comment.""" adapter = getAdapter(self.portal.doc, IImioHistory, 'workflow') # not highlighted because '' is an ignored comment history = adapter.getHistory() self.assertFalse(history[-1]['comments']) self.assertFalse(self.viewlet.highlight_history_link()) # now 'publish' the doc and add a comment, last event has a comment self.wft.doActionFor(self.portal.doc, 'publish', comment='my publish comment') # clean memoize getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertTrue(self.viewlet.highlight_history_link()) self.assertFalse(history[-1]['comments'] in adapter.ignorableHistoryComments()) # now test that the 'you can not access this comment' is an ignored message self.wft.doActionFor(self.portal.doc, 'retract', comment=HISTORY_COMMENT_NOT_VIEWABLE) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history[-1]['comments'] in adapter.ignorableHistoryComments()) # test that it works if no history # it is the case if we changed used workflow self.wft.setChainForPortalTypes(('Document', ), ('intranet_workflow',)) getattr(adapter, Memojito.propname).clear() history = adapter.getHistory() self.assertFalse(self.viewlet.highlight_history_link()) self.assertTrue(history == []) <|fim▁end|>
test_highlight_history_link
<|file_name|>res_users.py<|end_file_name|><|fim▁begin|># -*- encoding: utf-8 -*- # # OpenERP, Open Source Management Solution # This module copyright (C) 2014 Savoir-faire Linux # (<http://www.savoirfairelinux.com>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # import logging from openerp.osv import osv, fields _logger = logging.getLogger(__name__) class res_users(osv.osv): _inherit = "res.users" _columns = { 'xis_user_external_id': fields.integer('XIS external user',<|fim▁hole|><|fim▁end|>
required=True), }
<|file_name|>res_users.py<|end_file_name|><|fim▁begin|># -*- encoding: utf-8 -*- # # OpenERP, Open Source Management Solution # This module copyright (C) 2014 Savoir-faire Linux # (<http://www.savoirfairelinux.com>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # import logging from openerp.osv import osv, fields _logger = logging.getLogger(__name__) class res_users(osv.osv): <|fim_middle|> <|fim▁end|>
_inherit = "res.users" _columns = { 'xis_user_external_id': fields.integer('XIS external user', required=True), }
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key.<|fim▁hole|> This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url()<|fim▁end|>
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): <|fim_middle|> <|fim▁end|>
''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url()
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): <|fim_middle|> def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v)
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): <|fim_middle|> def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
for f in self.FIELDS: yield getattr(self, f, '')
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): <|fim_middle|> def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
return len(iter(self))
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): <|fim_middle|> def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
return getattr(self, field, None)
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): <|fim_middle|> def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
setattr(self, field, value)
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): <|fim_middle|> @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
delattr(self, field)
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): <|fim_middle|> @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
'''the scheme, split by plus signs''' return self.scheme.split('+')
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): <|fim_middle|> @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
'''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): <|fim_middle|> @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
'''the path attribute split by /''' return filter(None, self.path.split('/'))
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): <|fim_middle|> @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
'''the hostname, but I like host better''' return self.hostname
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): <|fim_middle|> def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
'''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): <|fim_middle|> def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value)
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): <|fim_middle|> def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
'''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, ))
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): <|fim_middle|> def __str__(self): return self.get_url() <|fim▁end|>
return DSN(self.get_url())
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): <|fim_middle|> <|fim▁end|>
return self.get_url()
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: <|fim_middle|> self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0]
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: <|fim_middle|> else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
options[k] = kv
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: <|fim_middle|> self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
options[k] = kv[0]
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: <|fim_middle|> if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
s += self.username prefix = '@'
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: <|fim_middle|> s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
s += ":{}".format(self.password) prefix = '@'
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: <|fim_middle|> return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
hostloc = '{}:{}'.format(hostloc, self.port)
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): <|fim_middle|> def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
setattr(self, key, value)
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def <|fim_middle|>(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
__init__
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def <|fim_middle|>(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
__iter__
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def <|fim_middle|>(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
__len__
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def <|fim_middle|>(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
__getitem__
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def <|fim_middle|>(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
__setitem__
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def <|fim_middle|>(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
__delitem__
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def <|fim_middle|>(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
schemes
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def <|fim_middle|>(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
netloc
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def <|fim_middle|>(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
paths
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def <|fim_middle|>(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
host
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def <|fim_middle|>(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
hostloc
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def <|fim_middle|>(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
set_default
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def <|fim_middle|>(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
get_url
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def <|fim_middle|>(self): return DSN(self.get_url()) def __str__(self): return self.get_url() <|fim▁end|>
copy
<|file_name|>dsntool.py<|end_file_name|><|fim▁begin|>import collections import re import urlparse class DSN(collections.MutableMapping): ''' Hold the results of a parsed dsn. This is very similar to urlparse.ParseResult tuple. http://docs.python.org/2/library/urlparse.html#results-of-urlparse-and-urlsplit It exposes the following attributes: scheme schemes -- if your scheme has +'s in it, then this will contain a list of schemes split by + path paths -- the path segment split by /, so "/foo/bar" would be ["foo", "bar"] host -- same as hostname (I just like host better) hostname hostloc -- host:port username password netloc query -- a dict of the query string query_str -- the raw query string port fragment ''' DSN_REGEXP = re.compile(r'^\S+://\S+') FIELDS = ('scheme', 'netloc', 'path', 'params', 'query', 'fragment') def __init__(self, dsn, **defaults): ''' Parse a dsn to parts similar to urlparse. This is a nuts function that can serve as a good basis to parsing a custom dsn :param dsn: the dsn to parse :type dsn: str :param defaults: any values you want to have defaults for if they aren't in the dsn :type defaults: dict ''' assert self.DSN_REGEXP.match(dsn), \ "{} is invalid, only full dsn urls (scheme://host...) allowed".format(dsn) first_colon = dsn.find(':') scheme = dsn[0:first_colon] dsn_url = dsn[first_colon+1:] url = urlparse.urlparse(dsn_url) options = {} if url.query: for k, kv in urlparse.parse_qs(url.query, True, True).iteritems(): if len(kv) > 1: options[k] = kv else: options[k] = kv[0] self.scheme = scheme self.hostname = url.hostname self.path = url.path self.params = url.params self.query = options self.fragment = url.fragment self.username = url.username self.password = url.password self.port = url.port self.query_str = url.query for k, v in defaults.iteritems(): self.set_default(k, v) def __iter__(self): for f in self.FIELDS: yield getattr(self, f, '') def __len__(self): return len(iter(self)) def __getitem__(self, field): return getattr(self, field, None) def __setitem__(self, field, value): setattr(self, field, value) def __delitem__(self, field): delattr(self, field) @property def schemes(self): '''the scheme, split by plus signs''' return self.scheme.split('+') @property def netloc(self): '''return username:password@hostname:port''' s = '' prefix = '' if self.username: s += self.username prefix = '@' if self.password: s += ":{}".format(self.password) prefix = '@' s += "{}{}".format(prefix, self.hostloc) return s @property def paths(self): '''the path attribute split by /''' return filter(None, self.path.split('/')) @property def host(self): '''the hostname, but I like host better''' return self.hostname @property def hostloc(self): '''return host:port''' hostloc = self.hostname if self.port: hostloc = '{}:{}'.format(hostloc, self.port) return hostloc def set_default(self, key, value): ''' Set a default value for key. This is different than dict's setdefault because it will set default either if the key doesn't exist, or if the value at the key evaluates to False, so an empty string or a None will value will be updated. :param key: the item to update :type key: str :param value: the items new value if key has a current value that evaluates to False ''' if not getattr(self, key, None): setattr(self, key, value) def get_url(self): '''return the dsn back into url form''' return urlparse.urlunparse(( self.scheme, self.netloc, self.path, self.params, self.query_str, self.fragment, )) def copy(self): return DSN(self.get_url()) def <|fim_middle|>(self): return self.get_url() <|fim▁end|>
__str__
<|file_name|>0001_initial.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Generated by Django 1.9.6 on 2016-06-06 02:47 from __future__ import unicode_literals import django.core.validators from django.db import migrations, models import django.db.models.deletion class Migration(migrations.Migration): initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='Car', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('car_model', models.CharField(max_length=20)), ('color', models.CharField(max_length=20)), ('year', models.SmallIntegerField(help_text='Use year as YYYY.', validators=[django.core.validators.RegexValidator('^[0-9]{4}$', 'Year in invalid format!', 'invalid')])), ('mileage', models.IntegerField(default=0, help_text='Or your car is brand new or it have some mileage traveled', validators=[django.core.validators.MinValueValidator(0)])), ], ), migrations.CreateModel( name='OilChange', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('date', models.DateTimeField(verbose_name='date changed')), ('mileage', models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(0)])), ('car', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='car.Car')), ], ), migrations.CreateModel( name='Refuel', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('date', models.DateTimeField(verbose_name='date refueled')), ('liters', models.DecimalField(decimal_places=3, max_digits=7)), ('fuel_price', models.DecimalField(decimal_places=2, max_digits=4)), ('mileage', models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(0)])), ('fuel_type', models.CharField(choices=[('Regular gas', 'Regular gas'), ('Premium gas', 'Premium gas'), ('Alcohol', 'Alcohol'), ('Diesel', 'Diesel')], default='Regular gas', max_length=20)), ('car', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='car.Car')), ],<|fim▁hole|> ]<|fim▁end|>
),
<|file_name|>0001_initial.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Generated by Django 1.9.6 on 2016-06-06 02:47 from __future__ import unicode_literals import django.core.validators from django.db import migrations, models import django.db.models.deletion class Migration(migrations.Migration): <|fim_middle|> <|fim▁end|>
initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='Car', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('car_model', models.CharField(max_length=20)), ('color', models.CharField(max_length=20)), ('year', models.SmallIntegerField(help_text='Use year as YYYY.', validators=[django.core.validators.RegexValidator('^[0-9]{4}$', 'Year in invalid format!', 'invalid')])), ('mileage', models.IntegerField(default=0, help_text='Or your car is brand new or it have some mileage traveled', validators=[django.core.validators.MinValueValidator(0)])), ], ), migrations.CreateModel( name='OilChange', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('date', models.DateTimeField(verbose_name='date changed')), ('mileage', models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(0)])), ('car', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='car.Car')), ], ), migrations.CreateModel( name='Refuel', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('date', models.DateTimeField(verbose_name='date refueled')), ('liters', models.DecimalField(decimal_places=3, max_digits=7)), ('fuel_price', models.DecimalField(decimal_places=2, max_digits=4)), ('mileage', models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(0)])), ('fuel_type', models.CharField(choices=[('Regular gas', 'Regular gas'), ('Premium gas', 'Premium gas'), ('Alcohol', 'Alcohol'), ('Diesel', 'Diesel')], default='Regular gas', max_length=20)), ('car', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='car.Car')), ], ), ]
<|file_name|>Nikon_DX.py<|end_file_name|><|fim▁begin|>import bpy<|fim▁hole|>camera = bpy.context.edit_movieclip.tracking.camera camera.sensor_width = 23.6 camera.units = 'MILLIMETERS' camera.pixel_aspect = 1 camera.k1 = 0.0 camera.k2 = 0.0 camera.k3 = 0.0<|fim▁end|>
<|file_name|>realview-switcheroo-atomic.py<|end_file_name|><|fim▁begin|># Copyright (c) 2012 ARM Limited # All rights reserved. # # The license below extends only to copyright in the software and shall # not be construed as granting a license to any other intellectual # property including but not limited to intellectual property relating # to a hardware implementation of the functionality of the software # licensed hereunder. You may use the software subject to the license # terms below provided that you ensure that this notice is replicated # unmodified and in its entirety in all distributions of the software, # modified or unmodified, in source code or in binary form. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer; # redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution; # neither the name of the copyright holders nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR<|fim▁hole|># A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Authors: Andreas Sandberg from m5.objects import * from arm_generic import * import switcheroo root = LinuxArmFSSwitcheroo( mem_class=DDR3_1600_x64, cpu_classes=(AtomicSimpleCPU, AtomicSimpleCPU) ).create_root() # Setup a custom test method that uses the switcheroo tester that # switches between CPU models. run_test = switcheroo.run_test<|fim▁end|>
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+"<|fim▁hole|>def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0]))<|fim▁end|>
token.lexer.lineno += len(token.value)
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): <|fim_middle|> t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
r"[0-9]+" token.value = int(token.value) return token
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): <|fim_middle|> def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
r",\sFirst\sof\s(his|her)\sName" return token
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): <|fim_middle|> def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
r"I\spromise" return token
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): <|fim_middle|> def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
r"Mayhaps" return token
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): <|fim_middle|> def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
r"Hodor" return token
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): <|fim_middle|> def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
r"And\snow\shis\swatch\sis\sended" return token
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): <|fim_middle|> t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
r"[a-zA-Z][_a-zA-Z0-9]*" return token
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): <|fim_middle|> def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
r"\n+" token.lexer.lineno += len(token.value)
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): <|fim_middle|> def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
r"//(.*)\n" token.lexer.lineno += 1
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): <|fim_middle|> <|fim▁end|>
raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0]))
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def <|fim_middle|>(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_NUMBER
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def <|fim_middle|>(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_VAR_DEFINITION
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def <|fim_middle|>(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_IF
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def <|fim_middle|>(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_ELSE
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def <|fim_middle|>(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_PRINT
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def <|fim_middle|>(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_END
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def <|fim_middle|>(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_ID
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def <|fim_middle|>(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_NEWLINE
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def <|fim_middle|>(token): r"//(.*)\n" token.lexer.lineno += 1 def t_error(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_IGNORE_COMMENTS
<|file_name|>lexer_rules.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- tokens = [ 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'EQUAL', 'DOUBLE_EQUAL', 'NUMBER', 'COMMA', 'VAR_DEFINITION', 'IF', 'ELSE', 'END', 'ID', 'PRINT' ] t_LPAREN = r"\(" t_RPAREN = r"\)" t_LBRACE = r"\{" t_RBRACE = r"\}" t_EQUAL = r"\=" t_DOUBLE_EQUAL = r"\=\=" def t_NUMBER(token): r"[0-9]+" token.value = int(token.value) return token t_COMMA = r"," def t_VAR_DEFINITION(token): r",\sFirst\sof\s(his|her)\sName" return token def t_IF(token): r"I\spromise" return token def t_ELSE(token): r"Mayhaps" return token def t_PRINT(token): r"Hodor" return token def t_END(token): r"And\snow\shis\swatch\sis\sended" return token def t_ID(token): r"[a-zA-Z][_a-zA-Z0-9]*" return token t_ignore = " \t" def t_NEWLINE(token): r"\n+" token.lexer.lineno += len(token.value) def t_IGNORE_COMMENTS(token): r"//(.*)\n" token.lexer.lineno += 1 def <|fim_middle|>(token): raise Exception("Sintax error: Unknown token on line {0}. \"{1}\"".format(token.lineno, token.value.partition("\n")[0])) <|fim▁end|>
t_error
<|file_name|>basic.py<|end_file_name|><|fim▁begin|>a = a # e 4 a = 1 # 0 int l = [a] # 0 [int] d = {a:l} # 0 {int:[int]} s = "abc" c = ord(s[2].lower()[0]) # 0 int # 4 (str) -> int l2 = [range(i) for i in d] # 0 [[int]] y = [(a,b) for a,b in {1:'2'}.iteritems()] # 0 [(int,str)] b = 1 # 0 int if 0: b = '' # 4 str<|fim▁hole|>if r: # 3 int r = str(r) # 4 str # 12 int r # 0 <int|str> l = range(5) # 0 [int] l2 = l[2:3] # 0 [int] x = l2[1] # 0 int k = 1() # 0 <unknown> # e 4 del k k # e 0 l = [] # 0 [int] x = 1 # 0 int while x: # 6 int l = [] # 4 [int] l.append(1) # 0 [int] # 2 (int) -> None l = [1, 2] # 0 [int] l2 = [x for x in l] # 0 [<int|str>] l2.append('') # 0 [<int|str>] s = str() # 0 str s2 = str(s) # 0 str s3 = repr() # e 5 # 0 str s4 = repr(s) # 0 str x = 1 if [] else '' # 0 <int|str> l = [1] # 0 [<int|str>] l2 = [''] # 0 [str] l[:] = l2 # 0 [<int|str>] b = 1 < 2 < 3 # 0 bool l = sorted(range(5), key=lambda x:-x) # 0 [int] d = {} # 0 {<bool|int>:<int|str>} d1 = {1:''} # 0 {int:str} d.update(d1) d[True] = 1 d # 0 {<bool|int>:<int|str>} l = [] # 0 [int] l1 = [] # 0 [<unknown>] l.extend(l1) l.append(2) l = [] # 0 [<[str]|int>] l1 = [[]] # 0 [[str]] l.extend(l1) l[0].append('') # e 0 l.append(1) l = [] # 0 [[<int|str>]] l2 = [1] # 0 [int] l3 = [''] # 0 [str] l.append(l2) l.append(l3) for i, s in enumerate("aoeu"): # 4 int # 7 str pass x = 1 # 0 int y = x + 1.0 # 0 float y << 1 # e 0 l = [1, 1.0] # 0 [float] 1.0 in [1] # e 0 x = `1` # 0 str def f(): x = `1` # 4 str d = dict(a=1) # 0 {str:int} l = list() # 0 [<unknown>] i = int(1) # 0 int i = int(1.2) # 0 int i = abs(1) # 0 int i = abs(1.0) # 0 float d = dict() # 0 {int:int} d[1] = 2 d2 = dict(d) # 0 {<int|str>:<int|str>} d2[''] = '' d3 = dict([(1,2)]) # 0 {int:int} d4 = dict(a=1) # 0 {str:int}<|fim▁end|>
else: b = str(b) # 4 str # 12 int r = 0 # 0 int
<|file_name|>basic.py<|end_file_name|><|fim▁begin|>a = a # e 4 a = 1 # 0 int l = [a] # 0 [int] d = {a:l} # 0 {int:[int]} s = "abc" c = ord(s[2].lower()[0]) # 0 int # 4 (str) -> int l2 = [range(i) for i in d] # 0 [[int]] y = [(a,b) for a,b in {1:'2'}.iteritems()] # 0 [(int,str)] b = 1 # 0 int if 0: b = '' # 4 str else: b = str(b) # 4 str # 12 int r = 0 # 0 int if r: # 3 int r = str(r) # 4 str # 12 int r # 0 <int|str> l = range(5) # 0 [int] l2 = l[2:3] # 0 [int] x = l2[1] # 0 int k = 1() # 0 <unknown> # e 4 del k k # e 0 l = [] # 0 [int] x = 1 # 0 int while x: # 6 int l = [] # 4 [int] l.append(1) # 0 [int] # 2 (int) -> None l = [1, 2] # 0 [int] l2 = [x for x in l] # 0 [<int|str>] l2.append('') # 0 [<int|str>] s = str() # 0 str s2 = str(s) # 0 str s3 = repr() # e 5 # 0 str s4 = repr(s) # 0 str x = 1 if [] else '' # 0 <int|str> l = [1] # 0 [<int|str>] l2 = [''] # 0 [str] l[:] = l2 # 0 [<int|str>] b = 1 < 2 < 3 # 0 bool l = sorted(range(5), key=lambda x:-x) # 0 [int] d = {} # 0 {<bool|int>:<int|str>} d1 = {1:''} # 0 {int:str} d.update(d1) d[True] = 1 d # 0 {<bool|int>:<int|str>} l = [] # 0 [int] l1 = [] # 0 [<unknown>] l.extend(l1) l.append(2) l = [] # 0 [<[str]|int>] l1 = [[]] # 0 [[str]] l.extend(l1) l[0].append('') # e 0 l.append(1) l = [] # 0 [[<int|str>]] l2 = [1] # 0 [int] l3 = [''] # 0 [str] l.append(l2) l.append(l3) for i, s in enumerate("aoeu"): # 4 int # 7 str pass x = 1 # 0 int y = x + 1.0 # 0 float y << 1 # e 0 l = [1, 1.0] # 0 [float] 1.0 in [1] # e 0 x = `1` # 0 str def f(): <|fim_middle|> d = dict(a=1) # 0 {str:int} l = list() # 0 [<unknown>] i = int(1) # 0 int i = int(1.2) # 0 int i = abs(1) # 0 int i = abs(1.0) # 0 float d = dict() # 0 {int:int} d[1] = 2 d2 = dict(d) # 0 {<int|str>:<int|str>} d2[''] = '' d3 = dict([(1,2)]) # 0 {int:int} d4 = dict(a=1) # 0 {str:int} <|fim▁end|>
x = `1` # 4 str
<|file_name|>basic.py<|end_file_name|><|fim▁begin|>a = a # e 4 a = 1 # 0 int l = [a] # 0 [int] d = {a:l} # 0 {int:[int]} s = "abc" c = ord(s[2].lower()[0]) # 0 int # 4 (str) -> int l2 = [range(i) for i in d] # 0 [[int]] y = [(a,b) for a,b in {1:'2'}.iteritems()] # 0 [(int,str)] b = 1 # 0 int if 0: <|fim_middle|> else: b = str(b) # 4 str # 12 int r = 0 # 0 int if r: # 3 int r = str(r) # 4 str # 12 int r # 0 <int|str> l = range(5) # 0 [int] l2 = l[2:3] # 0 [int] x = l2[1] # 0 int k = 1() # 0 <unknown> # e 4 del k k # e 0 l = [] # 0 [int] x = 1 # 0 int while x: # 6 int l = [] # 4 [int] l.append(1) # 0 [int] # 2 (int) -> None l = [1, 2] # 0 [int] l2 = [x for x in l] # 0 [<int|str>] l2.append('') # 0 [<int|str>] s = str() # 0 str s2 = str(s) # 0 str s3 = repr() # e 5 # 0 str s4 = repr(s) # 0 str x = 1 if [] else '' # 0 <int|str> l = [1] # 0 [<int|str>] l2 = [''] # 0 [str] l[:] = l2 # 0 [<int|str>] b = 1 < 2 < 3 # 0 bool l = sorted(range(5), key=lambda x:-x) # 0 [int] d = {} # 0 {<bool|int>:<int|str>} d1 = {1:''} # 0 {int:str} d.update(d1) d[True] = 1 d # 0 {<bool|int>:<int|str>} l = [] # 0 [int] l1 = [] # 0 [<unknown>] l.extend(l1) l.append(2) l = [] # 0 [<[str]|int>] l1 = [[]] # 0 [[str]] l.extend(l1) l[0].append('') # e 0 l.append(1) l = [] # 0 [[<int|str>]] l2 = [1] # 0 [int] l3 = [''] # 0 [str] l.append(l2) l.append(l3) for i, s in enumerate("aoeu"): # 4 int # 7 str pass x = 1 # 0 int y = x + 1.0 # 0 float y << 1 # e 0 l = [1, 1.0] # 0 [float] 1.0 in [1] # e 0 x = `1` # 0 str def f(): x = `1` # 4 str d = dict(a=1) # 0 {str:int} l = list() # 0 [<unknown>] i = int(1) # 0 int i = int(1.2) # 0 int i = abs(1) # 0 int i = abs(1.0) # 0 float d = dict() # 0 {int:int} d[1] = 2 d2 = dict(d) # 0 {<int|str>:<int|str>} d2[''] = '' d3 = dict([(1,2)]) # 0 {int:int} d4 = dict(a=1) # 0 {str:int} <|fim▁end|>
b = '' # 4 str
<|file_name|>basic.py<|end_file_name|><|fim▁begin|>a = a # e 4 a = 1 # 0 int l = [a] # 0 [int] d = {a:l} # 0 {int:[int]} s = "abc" c = ord(s[2].lower()[0]) # 0 int # 4 (str) -> int l2 = [range(i) for i in d] # 0 [[int]] y = [(a,b) for a,b in {1:'2'}.iteritems()] # 0 [(int,str)] b = 1 # 0 int if 0: b = '' # 4 str else: <|fim_middle|> r = 0 # 0 int if r: # 3 int r = str(r) # 4 str # 12 int r # 0 <int|str> l = range(5) # 0 [int] l2 = l[2:3] # 0 [int] x = l2[1] # 0 int k = 1() # 0 <unknown> # e 4 del k k # e 0 l = [] # 0 [int] x = 1 # 0 int while x: # 6 int l = [] # 4 [int] l.append(1) # 0 [int] # 2 (int) -> None l = [1, 2] # 0 [int] l2 = [x for x in l] # 0 [<int|str>] l2.append('') # 0 [<int|str>] s = str() # 0 str s2 = str(s) # 0 str s3 = repr() # e 5 # 0 str s4 = repr(s) # 0 str x = 1 if [] else '' # 0 <int|str> l = [1] # 0 [<int|str>] l2 = [''] # 0 [str] l[:] = l2 # 0 [<int|str>] b = 1 < 2 < 3 # 0 bool l = sorted(range(5), key=lambda x:-x) # 0 [int] d = {} # 0 {<bool|int>:<int|str>} d1 = {1:''} # 0 {int:str} d.update(d1) d[True] = 1 d # 0 {<bool|int>:<int|str>} l = [] # 0 [int] l1 = [] # 0 [<unknown>] l.extend(l1) l.append(2) l = [] # 0 [<[str]|int>] l1 = [[]] # 0 [[str]] l.extend(l1) l[0].append('') # e 0 l.append(1) l = [] # 0 [[<int|str>]] l2 = [1] # 0 [int] l3 = [''] # 0 [str] l.append(l2) l.append(l3) for i, s in enumerate("aoeu"): # 4 int # 7 str pass x = 1 # 0 int y = x + 1.0 # 0 float y << 1 # e 0 l = [1, 1.0] # 0 [float] 1.0 in [1] # e 0 x = `1` # 0 str def f(): x = `1` # 4 str d = dict(a=1) # 0 {str:int} l = list() # 0 [<unknown>] i = int(1) # 0 int i = int(1.2) # 0 int i = abs(1) # 0 int i = abs(1.0) # 0 float d = dict() # 0 {int:int} d[1] = 2 d2 = dict(d) # 0 {<int|str>:<int|str>} d2[''] = '' d3 = dict([(1,2)]) # 0 {int:int} d4 = dict(a=1) # 0 {str:int} <|fim▁end|>
b = str(b) # 4 str # 12 int
<|file_name|>basic.py<|end_file_name|><|fim▁begin|>a = a # e 4 a = 1 # 0 int l = [a] # 0 [int] d = {a:l} # 0 {int:[int]} s = "abc" c = ord(s[2].lower()[0]) # 0 int # 4 (str) -> int l2 = [range(i) for i in d] # 0 [[int]] y = [(a,b) for a,b in {1:'2'}.iteritems()] # 0 [(int,str)] b = 1 # 0 int if 0: b = '' # 4 str else: b = str(b) # 4 str # 12 int r = 0 # 0 int if r: # 3 int <|fim_middle|> r # 0 <int|str> l = range(5) # 0 [int] l2 = l[2:3] # 0 [int] x = l2[1] # 0 int k = 1() # 0 <unknown> # e 4 del k k # e 0 l = [] # 0 [int] x = 1 # 0 int while x: # 6 int l = [] # 4 [int] l.append(1) # 0 [int] # 2 (int) -> None l = [1, 2] # 0 [int] l2 = [x for x in l] # 0 [<int|str>] l2.append('') # 0 [<int|str>] s = str() # 0 str s2 = str(s) # 0 str s3 = repr() # e 5 # 0 str s4 = repr(s) # 0 str x = 1 if [] else '' # 0 <int|str> l = [1] # 0 [<int|str>] l2 = [''] # 0 [str] l[:] = l2 # 0 [<int|str>] b = 1 < 2 < 3 # 0 bool l = sorted(range(5), key=lambda x:-x) # 0 [int] d = {} # 0 {<bool|int>:<int|str>} d1 = {1:''} # 0 {int:str} d.update(d1) d[True] = 1 d # 0 {<bool|int>:<int|str>} l = [] # 0 [int] l1 = [] # 0 [<unknown>] l.extend(l1) l.append(2) l = [] # 0 [<[str]|int>] l1 = [[]] # 0 [[str]] l.extend(l1) l[0].append('') # e 0 l.append(1) l = [] # 0 [[<int|str>]] l2 = [1] # 0 [int] l3 = [''] # 0 [str] l.append(l2) l.append(l3) for i, s in enumerate("aoeu"): # 4 int # 7 str pass x = 1 # 0 int y = x + 1.0 # 0 float y << 1 # e 0 l = [1, 1.0] # 0 [float] 1.0 in [1] # e 0 x = `1` # 0 str def f(): x = `1` # 4 str d = dict(a=1) # 0 {str:int} l = list() # 0 [<unknown>] i = int(1) # 0 int i = int(1.2) # 0 int i = abs(1) # 0 int i = abs(1.0) # 0 float d = dict() # 0 {int:int} d[1] = 2 d2 = dict(d) # 0 {<int|str>:<int|str>} d2[''] = '' d3 = dict([(1,2)]) # 0 {int:int} d4 = dict(a=1) # 0 {str:int} <|fim▁end|>
r = str(r) # 4 str # 12 int
<|file_name|>basic.py<|end_file_name|><|fim▁begin|>a = a # e 4 a = 1 # 0 int l = [a] # 0 [int] d = {a:l} # 0 {int:[int]} s = "abc" c = ord(s[2].lower()[0]) # 0 int # 4 (str) -> int l2 = [range(i) for i in d] # 0 [[int]] y = [(a,b) for a,b in {1:'2'}.iteritems()] # 0 [(int,str)] b = 1 # 0 int if 0: b = '' # 4 str else: b = str(b) # 4 str # 12 int r = 0 # 0 int if r: # 3 int r = str(r) # 4 str # 12 int r # 0 <int|str> l = range(5) # 0 [int] l2 = l[2:3] # 0 [int] x = l2[1] # 0 int k = 1() # 0 <unknown> # e 4 del k k # e 0 l = [] # 0 [int] x = 1 # 0 int while x: # 6 int l = [] # 4 [int] l.append(1) # 0 [int] # 2 (int) -> None l = [1, 2] # 0 [int] l2 = [x for x in l] # 0 [<int|str>] l2.append('') # 0 [<int|str>] s = str() # 0 str s2 = str(s) # 0 str s3 = repr() # e 5 # 0 str s4 = repr(s) # 0 str x = 1 if [] else '' # 0 <int|str> l = [1] # 0 [<int|str>] l2 = [''] # 0 [str] l[:] = l2 # 0 [<int|str>] b = 1 < 2 < 3 # 0 bool l = sorted(range(5), key=lambda x:-x) # 0 [int] d = {} # 0 {<bool|int>:<int|str>} d1 = {1:''} # 0 {int:str} d.update(d1) d[True] = 1 d # 0 {<bool|int>:<int|str>} l = [] # 0 [int] l1 = [] # 0 [<unknown>] l.extend(l1) l.append(2) l = [] # 0 [<[str]|int>] l1 = [[]] # 0 [[str]] l.extend(l1) l[0].append('') # e 0 l.append(1) l = [] # 0 [[<int|str>]] l2 = [1] # 0 [int] l3 = [''] # 0 [str] l.append(l2) l.append(l3) for i, s in enumerate("aoeu"): # 4 int # 7 str pass x = 1 # 0 int y = x + 1.0 # 0 float y << 1 # e 0 l = [1, 1.0] # 0 [float] 1.0 in [1] # e 0 x = `1` # 0 str def <|fim_middle|>(): x = `1` # 4 str d = dict(a=1) # 0 {str:int} l = list() # 0 [<unknown>] i = int(1) # 0 int i = int(1.2) # 0 int i = abs(1) # 0 int i = abs(1.0) # 0 float d = dict() # 0 {int:int} d[1] = 2 d2 = dict(d) # 0 {<int|str>:<int|str>} d2[''] = '' d3 = dict([(1,2)]) # 0 {int:int} d4 = dict(a=1) # 0 {str:int} <|fim▁end|>
f
<|file_name|>here-now.py<|end_file_name|><|fim▁begin|>## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework ## Copyright (c) 2010 Stephen Blum ## http://www.pubnub.com/<|fim▁hole|>from pubnub import PubnubTornado as Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) channel = 'hello_world' # Asynchronous usage def callback(message): print(message) pubnub.here_now(channel, callback=callback, error=callback) pubnub.start()<|fim▁end|>
import sys
<|file_name|>here-now.py<|end_file_name|><|fim▁begin|>## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework ## Copyright (c) 2010 Stephen Blum ## http://www.pubnub.com/ import sys from pubnub import PubnubTornado as Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) channel = 'hello_world' # Asynchronous usage def callback(message): <|fim_middle|> pubnub.here_now(channel, callback=callback, error=callback) pubnub.start() <|fim▁end|>
print(message)
<|file_name|>here-now.py<|end_file_name|><|fim▁begin|>## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework ## Copyright (c) 2010 Stephen Blum ## http://www.pubnub.com/ import sys from pubnub import PubnubTornado as Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) channel = 'hello_world' # Asynchronous usage def <|fim_middle|>(message): print(message) pubnub.here_now(channel, callback=callback, error=callback) pubnub.start() <|fim▁end|>
callback
<|file_name|>MercurialHasRevisionRule.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2014 Will Thames <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<|fim▁hole|>from typing import TYPE_CHECKING, Any, Dict, Union from ansiblelint.rules import AnsibleLintRule if TYPE_CHECKING: from typing import Optional from ansiblelint.file_utils import Lintable class MercurialHasRevisionRule(AnsibleLintRule): id = 'hg-latest' shortdesc = 'Mercurial checkouts must contain explicit revision' description = ( 'All version control checkouts must point to ' 'an explicit commit or tag, not just ``latest``' ) severity = 'MEDIUM' tags = ['idempotency'] version_added = 'historic' def matchtask( self, task: Dict[str, Any], file: 'Optional[Lintable]' = None ) -> Union[bool, str]: return bool( task['action']['__ansible_module__'] == 'hg' and task['action'].get('revision', 'default') == 'default' )<|fim▁end|>
# THE SOFTWARE.
<|file_name|>MercurialHasRevisionRule.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2014 Will Thames <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from typing import TYPE_CHECKING, Any, Dict, Union from ansiblelint.rules import AnsibleLintRule if TYPE_CHECKING: from typing import Optional from ansiblelint.file_utils import Lintable class MercurialHasRevisionRule(AnsibleLintRule): <|fim_middle|> <|fim▁end|>
id = 'hg-latest' shortdesc = 'Mercurial checkouts must contain explicit revision' description = ( 'All version control checkouts must point to ' 'an explicit commit or tag, not just ``latest``' ) severity = 'MEDIUM' tags = ['idempotency'] version_added = 'historic' def matchtask( self, task: Dict[str, Any], file: 'Optional[Lintable]' = None ) -> Union[bool, str]: return bool( task['action']['__ansible_module__'] == 'hg' and task['action'].get('revision', 'default') == 'default' )
<|file_name|>MercurialHasRevisionRule.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2014 Will Thames <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from typing import TYPE_CHECKING, Any, Dict, Union from ansiblelint.rules import AnsibleLintRule if TYPE_CHECKING: from typing import Optional from ansiblelint.file_utils import Lintable class MercurialHasRevisionRule(AnsibleLintRule): id = 'hg-latest' shortdesc = 'Mercurial checkouts must contain explicit revision' description = ( 'All version control checkouts must point to ' 'an explicit commit or tag, not just ``latest``' ) severity = 'MEDIUM' tags = ['idempotency'] version_added = 'historic' def matchtask( self, task: Dict[str, Any], file: 'Optional[Lintable]' = None ) -> Union[bool, str]: <|fim_middle|> <|fim▁end|>
return bool( task['action']['__ansible_module__'] == 'hg' and task['action'].get('revision', 'default') == 'default' )
<|file_name|>MercurialHasRevisionRule.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2014 Will Thames <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from typing import TYPE_CHECKING, Any, Dict, Union from ansiblelint.rules import AnsibleLintRule if TYPE_CHECKING: <|fim_middle|> class MercurialHasRevisionRule(AnsibleLintRule): id = 'hg-latest' shortdesc = 'Mercurial checkouts must contain explicit revision' description = ( 'All version control checkouts must point to ' 'an explicit commit or tag, not just ``latest``' ) severity = 'MEDIUM' tags = ['idempotency'] version_added = 'historic' def matchtask( self, task: Dict[str, Any], file: 'Optional[Lintable]' = None ) -> Union[bool, str]: return bool( task['action']['__ansible_module__'] == 'hg' and task['action'].get('revision', 'default') == 'default' ) <|fim▁end|>
from typing import Optional from ansiblelint.file_utils import Lintable
<|file_name|>MercurialHasRevisionRule.py<|end_file_name|><|fim▁begin|># Copyright (c) 2013-2014 Will Thames <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from typing import TYPE_CHECKING, Any, Dict, Union from ansiblelint.rules import AnsibleLintRule if TYPE_CHECKING: from typing import Optional from ansiblelint.file_utils import Lintable class MercurialHasRevisionRule(AnsibleLintRule): id = 'hg-latest' shortdesc = 'Mercurial checkouts must contain explicit revision' description = ( 'All version control checkouts must point to ' 'an explicit commit or tag, not just ``latest``' ) severity = 'MEDIUM' tags = ['idempotency'] version_added = 'historic' def <|fim_middle|>( self, task: Dict[str, Any], file: 'Optional[Lintable]' = None ) -> Union[bool, str]: return bool( task['action']['__ansible_module__'] == 'hg' and task['action'].get('revision', 'default') == 'default' ) <|fim▁end|>
matchtask
<|file_name|>F57.py<|end_file_name|><|fim▁begin|>import fechbase class Records(fechbase.RecordsBase): def __init__(self): fechbase.RecordsBase.__init__(self) self.fields = [ {'name': 'FORM TYPE', 'number': '1'}, {'name': 'FILER FEC CMTE ID', 'number': '2'}, {'name': 'ENTITY TYPE', 'number': '3'}, {'name': 'NAME (Payee)', 'number': '4'}, {'name': 'STREET 1', 'number': '5'}, {'name': 'STREET 2', 'number': '6'}, {'name': 'CITY', 'number': '7'}, {'name': 'STATE', 'number': '8'}, {'name': 'ZIP', 'number': '9'}, {'name': 'TRANSDESC', 'number': '10'}, {'name': 'Of Expenditure', 'number': '11-'}, {'name': 'AMOUNT', 'number': '12'}, {'name': 'SUPPORT/OPPOSE', 'number': '13'}, {'name': 'S/O FEC CAN ID NUMBER', 'number': '14'}, {'name': 'S/O CAN/NAME', 'number': '15'}, {'name': 'S/O CAN/OFFICE', 'number': '16'}, {'name': 'S/O CAN/STATE', 'number': '17'}, {'name': 'S/O CAN/DIST', 'number': '18'}, {'name': 'FEC COMMITTEE ID NUMBER', 'number': '19'}, {'name': 'Unused field', 'number': '20'}, {'name': 'Unused field', 'number': '21'}, {'name': 'Unused field', 'number': '22'}, {'name': 'Unused field', 'number': '23'}, {'name': 'Unused field', 'number': '24'}, {'name': 'CONDUIT NAME', 'number': '25'}, {'name': 'CONDUIT STREET 1', 'number': '26'}, {'name': 'CONDUIT STREET 2', 'number': '27'}, {'name': 'CONDUIT CITY', 'number': '28'}, {'name': 'CONDUIT STATE', 'number': '29'},<|fim▁hole|> {'name': 'AMENDED CD', 'number': '31'}, {'name': 'TRAN ID', 'number': '32'}, ] self.fields_names = self.hash_names(self.fields)<|fim▁end|>
{'name': 'CONDUIT ZIP', 'number': '30'},
<|file_name|>F57.py<|end_file_name|><|fim▁begin|>import fechbase class Records(fechbase.RecordsBase): <|fim_middle|> <|fim▁end|>
def __init__(self): fechbase.RecordsBase.__init__(self) self.fields = [ {'name': 'FORM TYPE', 'number': '1'}, {'name': 'FILER FEC CMTE ID', 'number': '2'}, {'name': 'ENTITY TYPE', 'number': '3'}, {'name': 'NAME (Payee)', 'number': '4'}, {'name': 'STREET 1', 'number': '5'}, {'name': 'STREET 2', 'number': '6'}, {'name': 'CITY', 'number': '7'}, {'name': 'STATE', 'number': '8'}, {'name': 'ZIP', 'number': '9'}, {'name': 'TRANSDESC', 'number': '10'}, {'name': 'Of Expenditure', 'number': '11-'}, {'name': 'AMOUNT', 'number': '12'}, {'name': 'SUPPORT/OPPOSE', 'number': '13'}, {'name': 'S/O FEC CAN ID NUMBER', 'number': '14'}, {'name': 'S/O CAN/NAME', 'number': '15'}, {'name': 'S/O CAN/OFFICE', 'number': '16'}, {'name': 'S/O CAN/STATE', 'number': '17'}, {'name': 'S/O CAN/DIST', 'number': '18'}, {'name': 'FEC COMMITTEE ID NUMBER', 'number': '19'}, {'name': 'Unused field', 'number': '20'}, {'name': 'Unused field', 'number': '21'}, {'name': 'Unused field', 'number': '22'}, {'name': 'Unused field', 'number': '23'}, {'name': 'Unused field', 'number': '24'}, {'name': 'CONDUIT NAME', 'number': '25'}, {'name': 'CONDUIT STREET 1', 'number': '26'}, {'name': 'CONDUIT STREET 2', 'number': '27'}, {'name': 'CONDUIT CITY', 'number': '28'}, {'name': 'CONDUIT STATE', 'number': '29'}, {'name': 'CONDUIT ZIP', 'number': '30'}, {'name': 'AMENDED CD', 'number': '31'}, {'name': 'TRAN ID', 'number': '32'}, ] self.fields_names = self.hash_names(self.fields)
<|file_name|>F57.py<|end_file_name|><|fim▁begin|>import fechbase class Records(fechbase.RecordsBase): def __init__(self): <|fim_middle|> <|fim▁end|>
fechbase.RecordsBase.__init__(self) self.fields = [ {'name': 'FORM TYPE', 'number': '1'}, {'name': 'FILER FEC CMTE ID', 'number': '2'}, {'name': 'ENTITY TYPE', 'number': '3'}, {'name': 'NAME (Payee)', 'number': '4'}, {'name': 'STREET 1', 'number': '5'}, {'name': 'STREET 2', 'number': '6'}, {'name': 'CITY', 'number': '7'}, {'name': 'STATE', 'number': '8'}, {'name': 'ZIP', 'number': '9'}, {'name': 'TRANSDESC', 'number': '10'}, {'name': 'Of Expenditure', 'number': '11-'}, {'name': 'AMOUNT', 'number': '12'}, {'name': 'SUPPORT/OPPOSE', 'number': '13'}, {'name': 'S/O FEC CAN ID NUMBER', 'number': '14'}, {'name': 'S/O CAN/NAME', 'number': '15'}, {'name': 'S/O CAN/OFFICE', 'number': '16'}, {'name': 'S/O CAN/STATE', 'number': '17'}, {'name': 'S/O CAN/DIST', 'number': '18'}, {'name': 'FEC COMMITTEE ID NUMBER', 'number': '19'}, {'name': 'Unused field', 'number': '20'}, {'name': 'Unused field', 'number': '21'}, {'name': 'Unused field', 'number': '22'}, {'name': 'Unused field', 'number': '23'}, {'name': 'Unused field', 'number': '24'}, {'name': 'CONDUIT NAME', 'number': '25'}, {'name': 'CONDUIT STREET 1', 'number': '26'}, {'name': 'CONDUIT STREET 2', 'number': '27'}, {'name': 'CONDUIT CITY', 'number': '28'}, {'name': 'CONDUIT STATE', 'number': '29'}, {'name': 'CONDUIT ZIP', 'number': '30'}, {'name': 'AMENDED CD', 'number': '31'}, {'name': 'TRAN ID', 'number': '32'}, ] self.fields_names = self.hash_names(self.fields)