function
stringlengths
11
56k
repo_name
stringlengths
5
60
features
list
def test_one(self, f, foo): self._test(f, foo)
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_patch_multiple_create(self): patcher = patch.multiple(Foo, blam='blam') self.assertRaises(AttributeError, patcher.start) patcher = patch.multiple(Foo, blam='blam', create=True) patcher.start() try: self.assertEqual(Foo.blam, 'blam') finally: patcher.stop() self.assertFalse(hasattr(Foo, 'blam'))
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_patch_multiple_new_callable(self): class Thing(object): pass patcher = patch.multiple( Foo, f=DEFAULT, g=DEFAULT, new_callable=Thing ) result = patcher.start() try: self.assertIs(Foo.f, result['f']) self.assertIs(Foo.g, result['g']) self.assertIsInstance(Foo.f, Thing) self.assertIsInstance(Foo.g, Thing) self.assertIsNot(Foo.f, Foo.g) finally: patcher.stop()
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def thing1(): pass
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def thing2(): pass
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def thing3(): pass
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_new_callable_failure(self): original_f = Foo.f original_g = Foo.g original_foo = Foo.foo def crasher(): raise NameError('crasher') @patch.object(Foo, 'g', 1) @patch.object(Foo, 'foo', new_callable=crasher) @patch.object(Foo, 'f', 1) def thing1(): pass @patch.object(Foo, 'foo', new_callable=crasher) @patch.object(Foo, 'g', 1) @patch.object(Foo, 'f', 1) def thing2(): pass @patch.object(Foo, 'g', 1) @patch.object(Foo, 'f', 1) @patch.object(Foo, 'foo', new_callable=crasher) def thing3(): pass for func in thing1, thing2, thing3: self.assertRaises(NameError, func) self.assertEqual(Foo.f, original_f) self.assertEqual(Foo.g, original_g) self.assertEqual(Foo.foo, original_foo)
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def func(): pass
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_patch_multiple_new_callable_failure(self): original_f = Foo.f original_g = Foo.g original_foo = Foo.foo def crasher(): raise NameError('crasher') patcher = patch.object(Foo, 'f', 1) patcher.attribute_name = 'f' good = patch.object(Foo, 'g', 1) good.attribute_name = 'g' bad = patch.object(Foo, 'foo', new_callable=crasher) bad.attribute_name = 'foo' for additionals in [good, bad], [bad, good]: patcher.additional_patchers = additionals @patcher def func(): pass self.assertRaises(NameError, func) self.assertEqual(Foo.f, original_f) self.assertEqual(Foo.g, original_g) self.assertEqual(Foo.foo, original_foo)
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test(): self.assertEqual(foo.fish, 'nearly gone')
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_patch_test_prefix(self): class Foo(object): thing = 'original' def foo_one(self): return self.thing def foo_two(self): return self.thing def test_one(self): return self.thing def test_two(self): return self.thing Foo = patch.object(Foo, 'thing', 'changed')(Foo) foo = Foo() self.assertEqual(foo.foo_one(), 'changed') self.assertEqual(foo.foo_two(), 'changed') self.assertEqual(foo.test_one(), 'original') self.assertEqual(foo.test_two(), 'original')
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_patch_dict_test_prefix(self): class Foo(object): def bar_one(self): return dict(the_dict) def bar_two(self): return dict(the_dict) def test_one(self): return dict(the_dict) def test_two(self): return dict(the_dict) the_dict = {'key': 'original'} Foo = patch.dict(the_dict, key='changed')(Foo) foo =Foo() self.assertEqual(foo.bar_one(), {'key': 'changed'}) self.assertEqual(foo.bar_two(), {'key': 'changed'}) self.assertEqual(foo.test_one(), {'key': 'original'}) self.assertEqual(foo.test_two(), {'key': 'original'})
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_patch_nested_autospec_repr(self): with patch('unittest.test.testmock.support', autospec=True) as m: self.assertIn(" name='support.SomeClass.wibble()'", repr(m.SomeClass.wibble())) self.assertIn(" name='support.SomeClass().wibble()'", repr(m.SomeClass().wibble()))
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_patch_imports_lazily(self): p1 = patch('squizz.squozz') self.assertRaises(ImportError, p1.start) with uncache('squizz'): squizz = Mock() sys.modules['squizz'] = squizz squizz.squozz = 6 p1 = patch('squizz.squozz') squizz.squozz = 3 p1.start() p1.stop() self.assertEqual(squizz.squozz, 3)
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def __exit__(self, etype=None, val=None, tb=None): _patch.__exit__(self, etype, val, tb) holder.exc_info = etype, val, tb
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def with_custom_patch(target): getter, attribute = _get_target(target) return custom_patch( getter, attribute, DEFAULT, None, False, None, None, None, {} )
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test(mock): raise RuntimeError
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_create_and_specs(self): for kwarg in ('spec', 'spec_set', 'autospec'): p = patch('%s.doesnotexist' % __name__, create=True, **{kwarg: True}) self.assertRaises(TypeError, p.start) self.assertRaises(NameError, lambda: doesnotexist) # check that spec with create is innocuous if the original exists p = patch(MODNAME, create=True, **{kwarg: True}) p.start() p.stop()
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_specs_false_instead_of_none(self): p = patch(MODNAME, spec=False, spec_set=False, autospec=False) mock = p.start() try: # no spec should have been set, so attribute access should not fail mock.does_not_exist mock.does_not_exist = 3 finally: p.stop()
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_spec_set_true(self): for kwarg in ('spec', 'autospec'): p = patch(MODNAME, spec_set=True, **{kwarg: True}) m = p.start() try: self.assertRaises(AttributeError, setattr, m, 'doesnotexist', 'something') self.assertRaises(AttributeError, getattr, m, 'doesnotexist') finally: p.stop()
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_not_callable_spec_as_list(self): spec = ('foo', 'bar') p = patch(MODNAME, spec=spec) m = p.start() try: self.assertFalse(callable(m)) finally: p.stop()
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def patched(mock_path): patch.stopall() self.assertIs(os.path, mock_path) self.assertIs(os.unlink, unlink) self.assertIs(os.chdir, chdir)
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def test_stopall_lifo(self): stopped = [] class thing(object): one = two = three = None def get_patch(attribute): class mypatch(_patch): def stop(self): stopped.append(attribute) return super(mypatch, self).stop() return mypatch(lambda: thing, attribute, None, None, False, None, None, None, {}) [get_patch(val).start() for val in ("one", "two", "three")] patch.stopall() self.assertEqual(stopped, ["three", "two", "one"])
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def foo(x=0): """TEST""" return x
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def foo(*a, x=0): return x
FFMG/myoddweb.piger
[ 16, 2, 16, 2, 1456065110 ]
def __init__(self, name, dependency): self.name = name self.id = 1 self.dependency = dependency self.plan_version = "v0.10" self.success = False self.start_date = datetime.datetime.now().strftime("%I:%M%p %d-%B-%Y") self.resources = [] self.constraint = [] self.beliefs = Beliefs(self) self.desires = Desires(self) self.intentions = Intentions(self)
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def __str__(self): res = "---== Plan ==---- \n" res += "name : " + self.name + "\n" res += "version : " + self.plan_version + "\n" for i in self.beliefs.list(): res += "belief : " + i + "\n" for i in self.desires.list(): res += "desire : " + i + "\n" for i in self.intentions.list(): res += "intention : " + i + "\n"
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def get_name(self): return self.name
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def generate_plan(self): """ Main logic in class which generates a plan """ print("generating plan... TODO")
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def load_plan(self, fname): """ read the list of thoughts from a text file """ with open(fname, "r") as f: for line in f: if line != '': tpe, txt = self.parse_plan_from_string(line) #print('tpe= "' + tpe + '"', txt) if tpe == 'name': self.name = txt elif tpe == 'version': self.plan_version = txt elif tpe == 'belief': self.beliefs.add(txt) elif tpe == 'desire': self.desires.add(txt) elif tpe == 'intention': self.intentions.add(txt)
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def save_plan(self, fname):
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def parse_plan_from_string(self, line): tpe = '' txt = '' if line != '': if line[0:1] != '#': parts = line.split(":") tpe = parts[0].strip() txt = parts[1].strip() return tpe, txt
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def add_resource(self, name, tpe): """ add a resource available for the plan. These are text strings of real world objects mapped to an ontology key or programs from the toolbox section (can also be external programs) """ self.resources.append([name, tpe])
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def add_constraint(self, name, tpe, val): """ adds a constraint for the plan """ self.constraint.append([name, tpe, val])
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def __init__(self, thought_type): #print("Thoughts - init: thought_type = " + thought_type + "\n") self._thoughts = [] self._type = thought_type
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def __str__(self): res = ' -- Thoughts --\n' for i in self._thoughts: res += i + '\n' return res
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def add(self, name): self._thoughts.append(name)
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def list(self, print_console=False): lst = [] for i, thought in enumerate(self._thoughts): if print_console is True: print(self._type + str(i) + ' = ' + thought) lst.append(thought) return lst
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def __init__(self, parent_plan): self.parent_plan = parent_plan super(Beliefs, self).__init__('belief')
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def __init__(self, parent_plan): self.parent_plan = parent_plan super(Desires, self).__init__('desire')
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def __init__(self, parent_plan): self.parent_plan = parent_plan super(Intentions, self).__init__('intention')
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def TEST(): myplan = Plan_BDI('new plan', '') myplan.beliefs.add('belief0') myplan.beliefs.add('belief1') myplan.beliefs.add('belief2') myplan.desires.add('desire0') myplan.desires.add('desire1') myplan.intentions.add('intention0') myplan.beliefs.list() myplan.desires.list() myplan.intentions.list() #myplan.save_plan("test_plan.txt") #myplan.load_plan("test_plan.txt") print(str(myplan))
acutesoftware/AIKIF
[ 54, 13, 54, 10, 1378213987 ]
def __init__(self, parent=None, id=wx.ID_ANY, project=None, localRoot="", *args, **kwargs): wx.Dialog.__init__(self, parent, id, *args, **kwargs) panel = wx.Panel(self, wx.ID_ANY, style=wx.TAB_TRAVERSAL) # when a project is successfully created these will be populated if hasattr(parent, 'filename'): self.filename = parent.filename else: self.filename = None self.project = project # type: pavlovia.PavloviaProject self.projInfo = None self.parent = parent if project: # edit existing project self.isNew = False if project.localRoot and not localRoot: localRoot = project.localRoot else: self.isNew = True # create the controls nameLabel = wx.StaticText(panel, -1, _translate("Name:")) self.nameBox = wx.TextCtrl(panel, -1, size=(400, -1)) # Path can contain only letters, digits, '_', '-' and '.'. # Cannot start with '-', end in '.git' or end in '.atom'] pavSession = pavlovia.getCurrentSession() try: username = pavSession.user.username except AttributeError as e: raise pavlovia.NoUserError("{}: Tried to create project with no user logged in.".format(e)) gpChoices = [username] gpChoices.extend(pavSession.listUserGroups()) groupLabel = wx.StaticText(panel, -1, _translate("Group/owner:")) self.groupBox = wx.Choice(panel, -1, size=(400, -1), choices=gpChoices) descrLabel = wx.StaticText(panel, -1, _translate("Description:")) self.descrBox = wx.TextCtrl(panel, -1, size=(400, 200), style=wx.TE_MULTILINE | wx.SUNKEN_BORDER) localLabel = wx.StaticText(panel, -1, _translate("Local folder:")) self.localBox = wx.TextCtrl(panel, -1, size=(400, -1), value=localRoot) self.btnLocalBrowse = wx.Button(panel, wx.ID_ANY, _translate("Browse...")) self.btnLocalBrowse.Bind(wx.EVT_BUTTON, self.onBrowseLocal) localPathSizer = wx.BoxSizer(wx.HORIZONTAL) localPathSizer.Add(self.localBox) localPathSizer.Add(self.btnLocalBrowse) tagsLabel = wx.StaticText(panel, -1, _translate("Tags (comma separated):")) self.tagsBox = wx.TextCtrl(panel, -1, size=(400, 100), value="PsychoPy, Builder, Coder", style=wx.TE_MULTILINE | wx.SUNKEN_BORDER) publicLabel = wx.StaticText(panel, -1, _translate("Public:")) self.publicBox = wx.CheckBox(panel, -1) # buttons if self.isNew: buttonMsg = _translate("Create project on Pavlovia") else: buttonMsg = _translate("Submit changes to Pavlovia") updateBtn = wx.Button(panel, -1, buttonMsg) updateBtn.Bind(wx.EVT_BUTTON, self.submitChanges) cancelBtn = wx.Button(panel, -1, _translate("Cancel")) cancelBtn.Bind(wx.EVT_BUTTON, self.onCancel) btnSizer = wx.BoxSizer(wx.HORIZONTAL) if sys.platform == "win32": btns = [updateBtn, cancelBtn] else: btns = [cancelBtn, updateBtn] btnSizer.AddMany(btns) # do layout fieldsSizer = wx.FlexGridSizer(cols=2, rows=6, vgap=5, hgap=5) fieldsSizer.AddMany([(nameLabel, 0, wx.ALIGN_RIGHT), self.nameBox, (groupLabel, 0, wx.ALIGN_RIGHT), self.groupBox, (localLabel, 0, wx.ALIGN_RIGHT), localPathSizer, (descrLabel, 0, wx.ALIGN_RIGHT), self.descrBox, (tagsLabel, 0, wx.ALIGN_RIGHT), self.tagsBox, (publicLabel, 0, wx.ALIGN_RIGHT), self.publicBox]) border = wx.BoxSizer(wx.VERTICAL) border.Add(fieldsSizer, 0, wx.ALL, 5) border.Add(btnSizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5) panel.SetSizerAndFit(border) self.Fit()
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def submitChanges(self, evt=None): session = pavlovia.getCurrentSession() if not session.user: user = logInPavlovia(parent=self.parent) if not session.user: return # get current values name = self.nameBox.GetValue() namespace = self.groupBox.GetStringSelection() descr = self.descrBox.GetValue() visibility = self.publicBox.GetValue() # tags need splitting and then tagsList = self.tagsBox.GetValue().split(',') tags = [thisTag.strip() for thisTag in tagsList] localRoot = self.localBox.GetValue() if not localRoot: localRoot = setLocalPath(self.parent, project=None, path="") # then create/update if self.isNew: project = session.createProject(name=name, description=descr, tags=tags, visibility=visibility, localRoot=localRoot, namespace=namespace) self.project = project self.project._newRemote = True else: # we're changing metadata of an existing project. Don't sync self.project.pavlovia.name = name self.project.pavlovia.description = descr self.project.tags = tags self.project.visibility = visibility self.project.localRoot = localRoot self.project.save() # pushes changed metadata to gitlab self.project._newRemote = False self.EndModal(wx.ID_OK) pavlovia.knownProjects.save() self.project.getRepo(forceRefresh=True) self.parent.project = self.project
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def __init__(self, parent, iconCache, value=False): wx.Button.__init__(self, parent, label=_translate("Star")) # Setup icons self.icons = { True: iconCache.getBitmap(name="starred", size=16), False: iconCache.getBitmap(name="unstarred", size=16), } self.SetBitmapDisabled(self.icons[False]) # Always appear empty when disabled # Set start value self.value = value
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def value(self): return self._value
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def value(self, value): # Store value self._value = bool(value) # Change icon self.SetBitmap(self.icons[self._value]) self.SetBitmapCurrent(self.icons[self._value]) self.SetBitmapFocus(self.icons[self._value])
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def __init__(self, parent, project=None, size=(650, 550), style=wx.NO_BORDER): wx.Panel.__init__(self, parent, -1, size=size, style=style) self.SetBackgroundColour("white") iconCache = parent.app.iconCache # Setup sizer self.contentBox = wx.BoxSizer() self.SetSizer(self.contentBox) self.sizer = wx.BoxSizer(wx.VERTICAL) self.contentBox.Add(self.sizer, proportion=1, border=12, flag=wx.ALL | wx.EXPAND) # Head sizer self.headSizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.headSizer, border=0, flag=wx.EXPAND) # Icon self.icon = utils.ImageCtrl(self, bitmap=wx.Bitmap(), size=(128, 128)) self.icon.SetBackgroundColour("#f2f2f2") self.icon.Bind(wx.EVT_FILEPICKER_CHANGED, self.updateProject) self.headSizer.Add(self.icon, border=6, flag=wx.ALL) self.icon.SetToolTip(_translate( "An image to represent this project, this helps it stand out when browsing on Pavlovia." )) # Title sizer self.titleSizer = wx.BoxSizer(wx.VERTICAL) self.headSizer.Add(self.titleSizer, proportion=1, flag=wx.EXPAND) # Title self.title = wx.TextCtrl(self, size=(-1, 30 if sys.platform == 'darwin' else -1), value="") self.title.Bind(wx.EVT_KILL_FOCUS, self.updateProject) self.title.SetFont( wx.Font(24, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD) ) self.titleSizer.Add(self.title, border=6, flag=wx.ALL | wx.EXPAND) self.title.SetToolTip(_translate( "Title of the project. Unlike the project name, this isn't used as a filename anywhere; so you can " "add spaces, apostrophes and emojis to your heart's content! 🦕✨" )) # Author self.author = wx.StaticText(self, size=(-1, -1), label="by ---") self.titleSizer.Add(self.author, border=6, flag=wx.LEFT | wx.RIGHT) # Pavlovia link self.link = wxhl.HyperLinkCtrl(self, -1, label="https://pavlovia.org/", URL="https://pavlovia.org/", ) self.link.SetBackgroundColour("white") self.titleSizer.Add(self.link, border=6, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM) self.link.SetToolTip(_translate( "Click to view the project in Pavlovia." )) # Button sizer self.btnSizer = wx.BoxSizer(wx.HORIZONTAL) self.titleSizer.Add(self.btnSizer, flag=wx.EXPAND) # Star button self.starLbl = wx.StaticText(self, label="-") self.btnSizer.Add(self.starLbl, border=6, flag=wx.LEFT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL) self.starBtn = self.StarBtn(self, iconCache=iconCache) self.starBtn.Bind(wx.EVT_BUTTON, self.star) self.btnSizer.Add(self.starBtn, border=6, flag=wx.ALL | wx.EXPAND) self.starBtn.SetToolTip(_translate( "'Star' this project to get back to it easily. Projects you've starred will appear first in your searches " "and projects with more stars in total will appear higher in everyone's searches." )) # Fork button self.forkLbl = wx.StaticText(self, label="-") self.btnSizer.Add(self.forkLbl, border=6, flag=wx.LEFT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL) self.forkBtn = wx.Button(self, label=_translate("Fork")) self.forkBtn.SetBitmap(iconCache.getBitmap(name="fork", size=16)) self.forkBtn.Bind(wx.EVT_BUTTON, self.fork) self.btnSizer.Add(self.forkBtn, border=6, flag=wx.ALL | wx.EXPAND) self.forkBtn.SetToolTip(_translate( "Create a copy of this project on your own Pavlovia account so that you can make changes without affecting " "the original project." )) # Create button self.createBtn = wx.Button(self, label=_translate("Create")) self.createBtn.SetBitmap(iconCache.getBitmap(name="plus", size=16)) self.createBtn.Bind(wx.EVT_BUTTON, self.create) self.btnSizer.Add(self.createBtn, border=6, flag=wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL) self.createBtn.SetToolTip(_translate( "Create a Pavlovia project for the current experiment." )) # Sync button self.syncBtn = wx.Button(self, label=_translate("Sync")) self.syncBtn.SetBitmap(iconCache.getBitmap(name="view-refresh", size=16)) self.syncBtn.Bind(wx.EVT_BUTTON, self.sync) self.btnSizer.Add(self.syncBtn, border=6, flag=wx.ALL | wx.EXPAND) self.syncBtn.SetToolTip(_translate( "Synchronise this project's local files with their online counterparts. This will 'pull' changes from " "Pavlovia and 'push' changes from your local files." )) # Get button self.downloadBtn = wx.Button(self, label=_translate("Download")) self.downloadBtn.SetBitmap(iconCache.getBitmap(name="download", size=16)) self.downloadBtn.Bind(wx.EVT_BUTTON, self.sync) self.btnSizer.Add(self.downloadBtn, border=6, flag=wx.ALL | wx.EXPAND) self.downloadBtn.SetToolTip(_translate( "'Clone' this project, creating local copies of all its files and tracking any changes you make so that " "they can be applied when you next 'sync' the project." )) # Sync label self.syncLbl = wx.StaticText(self, size=(-1, -1), label="---") self.btnSizer.Add(self.syncLbl, border=6, flag=wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL) self.syncLbl.SetToolTip(_translate( "Last synced at..." )) self.btnSizer.AddStretchSpacer(1) # Sep self.sizer.Add(wx.StaticLine(self, -1), border=6, flag=wx.EXPAND | wx.ALL) # Local root self.rootSizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.rootSizer, flag=wx.EXPAND) self.localRootLabel = wx.StaticText(self, label="Local root:") self.rootSizer.Add(self.localRootLabel, border=6, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL) self.localRoot = utils.FileCtrl(self, dlgtype="dir") self.localRoot.Bind(wx.EVT_FILEPICKER_CHANGED, self.updateProject) self.rootSizer.Add(self.localRoot, proportion=1, border=6, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM) self.localRoot.SetToolTip(_translate( "Folder in which local files are stored for this project. Changes to files in this folder will be tracked " "and applied to the project when you 'sync', so make sure the only files in this folder are relevant!" )) # Sep self.sizer.Add(wx.StaticLine(self, -1), border=6, flag=wx.EXPAND | wx.ALL) # Description self.description = wx.TextCtrl(self, size=(-1, -1), value="", style=wx.TE_MULTILINE) self.description.Bind(wx.EVT_KILL_FOCUS, self.updateProject) self.sizer.Add(self.description, proportion=1, border=6, flag=wx.ALL | wx.EXPAND) self.description.SetToolTip(_translate( "Description of the project to be shown on Pavlovia. Note: This is different than a README file!" )) # Sep self.sizer.Add(wx.StaticLine(self, -1), border=6, flag=wx.EXPAND | wx.ALL) # Visibility self.visSizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.visSizer, flag=wx.EXPAND) self.visLbl = wx.StaticText(self, label=_translate("Visibility:")) self.visSizer.Add(self.visLbl, border=6, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL) self.visibility = wx.Choice(self, choices=["Private", "Public"]) self.visibility.Bind(wx.EVT_CHOICE, self.updateProject) self.visSizer.Add(self.visibility, proportion=1, border=6, flag=wx.EXPAND | wx.ALL) self.visibility.SetToolTip(_translate( "Visibility of the current project; whether its visible only to its creator (Private) or to any user " "(Public)." )) # Status self.statusSizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.statusSizer, flag=wx.EXPAND) self.statusLbl = wx.StaticText(self, label=_translate("Status:")) self.statusSizer.Add(self.statusLbl, border=6, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL) self.status = wx.Choice(self, choices=["Running", "Piloting", "Inactive"]) self.status.Bind(wx.EVT_CHOICE, self.updateProject) self.statusSizer.Add(self.status, proportion=1, border=6, flag=wx.EXPAND | wx.ALL) self.status.SetToolTip(_translate( "Project status; whether it can be run to collect data (Running), run by its creator without saving " "data (Piloting) or cannot be run (Inactive)." )) # Tags self.tagSizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.tagSizer, flag=wx.EXPAND) self.tagLbl = wx.StaticText(self, label=_translate("Keywords:")) self.tagSizer.Add(self.tagLbl, border=6, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL) self.tags = utils.ButtonArray(self, orient=wx.HORIZONTAL, items=[], itemAlias=_translate("tag")) self.tags.Bind(wx.EVT_LIST_INSERT_ITEM, self.updateProject) self.tags.Bind(wx.EVT_LIST_DELETE_ITEM, self.updateProject) self.tagSizer.Add(self.tags, proportion=1, border=6, flag=wx.EXPAND | wx.ALL) self.tags.SetToolTip(_translate( "Keywords associated with this project, helping others to find it. For example, if your experiment is " "useful to psychophysicists, you may want to add the keyword 'psychophysics'." )) # Populate if project is not None: project.refresh() self.project = project
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def project(self): return self._project
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def project(self, project): self._project = project # Populate fields if project is None: # Icon self.icon.SetBitmap(wx.Bitmap()) self.icon.SetBackgroundColour("#f2f2f2") self.icon.Disable() # Title self.title.SetValue("") self.title.Disable() # Author self.author.SetLabel("by --- on ---") self.author.Disable() # Link self.link.SetLabel("---/---") self.link.SetURL("https://pavlovia.org/") self.link.Disable() # Star button self.starBtn.Disable() self.starBtn.value = False # Star label self.starLbl.SetLabel("-") self.starLbl.Disable() # Fork button self.forkBtn.Disable() # Fork label self.forkLbl.SetLabel("-") self.forkLbl.Disable() # Create button self.createBtn.Show() self.createBtn.Enable(bool(self.session.user)) # Sync button self.syncBtn.Hide() # Get button self.downloadBtn.Hide() # Sync label self.syncLbl.SetLabel("---") self.syncLbl.Disable() # Local root self.localRootLabel.Disable() wx.TextCtrl.SetValue(self.localRoot, "") # use base method to avoid callback self.localRoot.Disable() # Description self.description.SetValue("") self.description.Disable() # Visibility self.visibility.SetSelection(wx.NOT_FOUND) self.visibility.Disable() # Status self.status.SetSelection(wx.NOT_FOUND) self.status.Disable() # Tags self.tags.clear() self.tags.Disable() else: # Refresh project to make sure it has info if not hasattr(project, "_info"): project.refresh() # Icon if 'avatarUrl' in project.info: try: content = requests.get(project['avatar_url']).content icon = wx.Bitmap(wx.Image(io.BytesIO(content))) except requests.exceptions.MissingSchema: icon = wx.Bitmap() else: icon = wx.Bitmap() self.icon.SetBitmap(icon) self.icon.SetBackgroundColour("#f2f2f2") self.icon.Enable(project.editable) # Title self.title.SetValue(project['name']) self.title.Enable(project.editable) # Author self.author.SetLabel(f"by {project['path_with_namespace'].split('/')[0]} on {project['created_at']:%d %B %Y}") self.author.Enable() # Link self.link.SetLabel(project['path_with_namespace']) self.link.SetURL("https://pavlovia.org/" + project['path_with_namespace']) self.link.Enable() # Star button self.starBtn.value = project.starred self.starBtn.Enable(bool(project.session.user)) # Star label self.starLbl.SetLabel(str(project['star_count'])) self.starLbl.Enable() # Fork button self.forkBtn.Enable(bool(project.session.user) and not project.owned) # Fork label self.forkLbl.SetLabel(str(project['forks_count'])) self.forkLbl.Enable() # Create button self.createBtn.Hide() # Sync button self.syncBtn.Show(bool(project.localRoot) or (not project.editable)) self.syncBtn.Enable(project.editable) # Get button self.downloadBtn.Show(not bool(project.localRoot) and project.editable) self.downloadBtn.Enable(project.editable) # Sync label self.syncLbl.SetLabel(f"{project['last_activity_at']:%d %B %Y, %I:%M%p}") self.syncLbl.Show(bool(project.localRoot) or (not project.editable)) self.syncLbl.Enable(project.editable) # Local root wx.TextCtrl.SetValue(self.localRoot, project.localRoot or "") # use base method to avoid callback self.localRootLabel.Enable(project.editable) self.localRoot.Enable(project.editable) # Description self.description.SetValue(project['description']) self.description.Enable(project.editable) # Visibility self.visibility.SetStringSelection(project['visibility']) self.visibility.Enable(project.editable) # Status self.status.SetStringSelection(str(project['status2']).title()) self.status.Enable(project.editable) # Tags self.tags.items = project['keywords'] self.tags.Enable(project.editable) # Layout self.Layout()
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def session(self): # Cache session if not cached if not hasattr(self, "_session"): self._session = pavlovia.getCurrentSession() # Return cached session return self._session
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def sync(self, evt=None): # If not synced locally, choose a folder if not self.localRoot.GetValue(): self.localRoot.browse() # If cancelled, return if not self.localRoot.GetValue(): return self.project.localRoot = self.localRoot.GetValue() # Enable ctrl now that there is a local root self.localRoot.Enable() self.localRootLabel.Enable() # Show sync dlg (does sync) dlg = sync.SyncDialog(self, self.project) dlg.sync() functions.showCommitDialog(self, self.project, initMsg="", infoStream=dlg.status) # Update project self.project.refresh() # Update last sync date & show self.syncLbl.SetLabel(f"{self.project['last_activity_at']:%d %B %Y, %I:%M%p}") self.syncLbl.Show() self.syncLbl.Enable() # Switch buttons to show Sync rather than Download/Create self.createBtn.Hide() self.downloadBtn.Hide() self.syncBtn.Show() self.syncBtn.Enable()
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def star(self, evt=None): # Toggle button self.starBtn.toggle() # Star/unstar project self.updateProject(evt) # todo: Refresh stars count
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def __init__(self, app, parent=None, style=None, pos=wx.DefaultPosition, project=None): if style is None: style = (wx.DEFAULT_DIALOG_STYLE | wx.CENTER | wx.TAB_TRAVERSAL | wx.RESIZE_BORDER) if project: title = project['name'] else: title = _translate("Project info") self.frameType = 'ProjectInfo' wx.Dialog.__init__(self, parent, -1, title=title, style=style, size=(700, 500), pos=pos) self.app = app self.project = project self.parent = parent self.detailsPanel = DetailsPanel(parent=self, project=self.project) self.mainSizer = wx.BoxSizer(wx.VERTICAL) self.mainSizer.Add(self.detailsPanel, proportion=1, border=12, flag=wx.EXPAND | wx.ALL) self.SetSizerAndFit(self.mainSizer) if self.parent: self.CenterOnParent() self.Layout()
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def __init__(self, project, *args, **kwargs): wx.Dialog.__init__(self, *args, **kwargs) existingName = project.name session = pavlovia.getCurrentSession() groups = [session.user['username']] groups.extend(session.listUserGroups()) msg = wx.StaticText(self, label="Where shall we fork to?") groupLbl = wx.StaticText(self, label="Group:") self.groupField = wx.Choice(self, choices=groups) nameLbl = wx.StaticText(self, label="Project name:") self.nameField = wx.TextCtrl(self, value=project.name) fieldsSizer = wx.FlexGridSizer(cols=2, rows=2, vgap=5, hgap=5) fieldsSizer.AddMany([groupLbl, self.groupField, nameLbl, self.nameField]) buttonSizer = wx.BoxSizer(wx.HORIZONTAL) buttonSizer.Add(wx.Button(self, id=wx.ID_OK, label="OK")) buttonSizer.Add(wx.Button(self, id=wx.ID_CANCEL, label="Cancel")) mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(msg, 1, wx.ALL, 5) mainSizer.Add(fieldsSizer, 1, wx.ALL, 5) mainSizer.Add(buttonSizer, 1, wx.ALL | wx.ALIGN_RIGHT, 5) self.SetSizerAndFit(mainSizer) self.Layout()
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def __init__(self, project, parent, *args, **kwargs): wx.Dialog.__init__(self, parent, *args, **kwargs) self.parent = parent self.project = project existingName = project.name msgText = _translate("points to a remote that doesn't exist (deleted?).") msgText += (" "+_translate("What shall we do?")) msg = wx.StaticText(self, label="{} {}".format(existingName, msgText)) choices = [_translate("(Re)create a project"), "{} ({})".format(_translate("Point to an different location"), _translate("not yet supported")), _translate("Forget the local git repository (deletes history keeps files)")] self.radioCtrl = wx.RadioBox(self, label='RadioBox', choices=choices, majorDimension=1) self.radioCtrl.EnableItem(1, False) self.radioCtrl.EnableItem(2, False) mainSizer = wx.BoxSizer(wx.VERTICAL) buttonSizer = wx.BoxSizer(wx.HORIZONTAL) buttonSizer.Add(wx.Button(self, id=wx.ID_OK, label=_translate("OK")), 1, wx.ALL, 5) buttonSizer.Add(wx.Button(self, id=wx.ID_CANCEL, label=_translate("Cancel")), 1, wx.ALL, 5) mainSizer.Add(msg, 1, wx.ALL, 5) mainSizer.Add(self.radioCtrl, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5) mainSizer.Add(buttonSizer, 1, wx.ALL | wx.ALIGN_RIGHT, 1) self.SetSizer(mainSizer) self.Layout()
psychopy/psychopy
[ 1370, 772, 1370, 229, 1283360404 ]
def get_ordering(self, request, queryset): if self.model_admin.sortable_is_enabled(): return [self.model_admin.sortable, '-' + self.model._meta.pk.name] return super(SortableChangeList, self).get_ordering(request, queryset)
82Flex/DCRM
[ 226, 97, 226, 5, 1485696947 ]
def __init__(self, *args, **kwargs): super(SortableTabularInlineBase, self).__init__(*args, **kwargs) self.ordering = (self.sortable,) self.fields = self.fields or [] if self.fields and self.sortable not in self.fields: self.fields = list(self.fields) + [self.sortable]
82Flex/DCRM
[ 226, 97, 226, 5, 1485696947 ]
def __init__(self, *args, **kwargs): super(SortableStackedInlineBase, self).__init__(*args, **kwargs) self.ordering = (self.sortable,)
82Flex/DCRM
[ 226, 97, 226, 5, 1485696947 ]
def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name == self.sortable: kwargs['widget'] = deepcopy(SortableListForm.Meta.widgets['order']) kwargs['widget'].attrs['class'] += ' suit-sortable-stacked' kwargs['widget'].attrs['rowclass'] = ' suit-sortable-stacked-row' return super(SortableStackedInlineBase, self).formfield_for_dbfield(db_field, **kwargs)
82Flex/DCRM
[ 226, 97, 226, 5, 1485696947 ]
def __init__(self, *args, **kwargs): super(SortableModelAdmin, self).__init__(*args, **kwargs) # Keep originals for restore self._original_ordering = copy(self.ordering) self._original_list_display = copy(self.list_display) self._original_list_editable = copy(self.list_editable) self._original_exclude = copy(self.exclude) self._original_list_per_page = self.list_per_page self.enable_sortable()
82Flex/DCRM
[ 226, 97, 226, 5, 1485696947 ]
def get_changelist_form(self, request, **kwargs): form = super(SortableModelAdmin, self).get_changelist_form(request, **kwargs) self.merge_form_meta(form) return form
82Flex/DCRM
[ 226, 97, 226, 5, 1485696947 ]
def enable_sortable(self): self.list_per_page = 500 self.ordering = (self.sortable,) if self.list_display and self.sortable not in self.list_display: self.list_display = list(self.list_display) + [self.sortable] self.list_editable = self.list_editable or [] if self.sortable not in self.list_editable: self.list_editable = list(self.list_editable) + [self.sortable] self.exclude = self.exclude or [] if self.sortable not in self.exclude: self.exclude = list(self.exclude) + [self.sortable]
82Flex/DCRM
[ 226, 97, 226, 5, 1485696947 ]
def sortable_is_enabled(self): return self.list_display and self.sortable in self.list_display
82Flex/DCRM
[ 226, 97, 226, 5, 1485696947 ]
def __init__(self): super(ConsultarLoteRpsEnvio, self).__init__() self.versao = TagDecimal(nome=u'ConsultarLoteRpsEnvio', propriedade=u'versao', namespace=NAMESPACE_NFSE, valor=u'1.00', raiz=u'/') self.Prestador = IdentificacaoPrestador() self.Protocolo = TagCaracter(nome=u'Protocolo', tamanho=[ 1, 50], raiz=u'/') self.caminho_esquema = os.path.join(DIRNAME, u'schema/') self.arquivo_esquema = u'nfse.xsd'
thiagopena/PySIGNFe
[ 43, 35, 43, 4, 1480611950 ]
def get_xml(self): xml = XMLNFe.get_xml(self) xml += ABERTURA xml += u'<ConsultarLoteRpsEnvio xmlns="'+ NAMESPACE_NFSE + '">' xml += self.Prestador.xml.replace(ABERTURA, u'') xml += self.Protocolo.xml
thiagopena/PySIGNFe
[ 43, 35, 43, 4, 1480611950 ]
def set_xml(self, arquivo): if self._le_xml(arquivo): self.Prestador.xml = arquivo self.Protocolo.xml = arquivo
thiagopena/PySIGNFe
[ 43, 35, 43, 4, 1480611950 ]
def __init__(self): super(ConsultarLoteRpsResposta, self).__init__() self.CompNfse = [] self.ListaMensagemRetorno = ListaMensagemRetorno()
thiagopena/PySIGNFe
[ 43, 35, 43, 4, 1480611950 ]
def get_xml(self): xml = XMLNFe.get_xml(self) xml += ABERTURA xml += u'<ConsultarLoteRpsResposta xmlns="'+ NAMESPACE_NFSE + '">' if len(self.ListaMensagemRetorno.MensagemRetorno) != 0: xml += self.ListaMensagemRetorno.xml.replace(ABERTURA, u'') else: xml += u'<ListaNfse>' for c in self.CompNfse: xml += tira_abertura(c.xml) xml += u'</ListaNfse>'
thiagopena/PySIGNFe
[ 43, 35, 43, 4, 1480611950 ]
def set_xml(self, arquivo): if self._le_xml(arquivo): self.CompNfse = self.le_grupo('[nfse]//ConsultarLoteRpsResposta/CompNfse', CompNfse) self.ListaMensagemRetorno.xml = arquivo
thiagopena/PySIGNFe
[ 43, 35, 43, 4, 1480611950 ]
def __init__(self, id, page): self.id = id self.page = page
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def get_href(self): return self.page.attr("_href")
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def __init__(self, id, title, url, data=None): self.id = id self.title = jQuery.trim(title) self.url = url self.data = data
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def __init__(self): self.id = 0 self.titles = {} self.active_item = None
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def is_open(self, title): if self.titles and title in self.titles and self.titles[title]: return True else: return False
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def register(self, title): self.titles[title] = "$$$"
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def _on_show_tab(self, e): nonlocal menu_item window.ACTIVE_PAGE = Page(_id, jQuery("#" + _id), menu_item) menu = get_menu() menu_item = menu.titles[jQuery.trim(e.target.text)] self.active_item = menu_item if window.PUSH_STATE: history_push_state(menu_item.title, menu_item.url) process_resize(document.getElementById(menu_item.id))
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def _on_button_click(self, event): get_menu().remove_page(jQuery(this).attr("id").replace("button_", ""))
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def _local_fun(index, element): eval(this.innerHTML)
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def remove_page(self, id): def _local_fun(index, value): if value and value.id == id: self.titles[index] = None jQuery.each(self.titles, _local_fun) remove_element(sprintf("#li_%s", id)) remove_element(sprintf("#%s", id)) last_a = jQuery("#tabs2 a:last") if last_a.length > 0: last_a.tab("show") else: window.ACTIVE_PAGE = None if window.PUSH_STATE: history_push_state("", window.BASE_PATH) if jQuery("#body_desktop").find(".content").length == 0: window.init_start_wiki_page() jQuery("#body_desktop").show()
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def on_menu_href(self, elem, data_or_html, title, title_alt=None, url=None): if window.APPLICATION_TEMPLATE == "modern": if self.is_open(title): self.activate(title) else: self.register(title) if url: href = url else: href = jQuery(elem).attr("href") href2 = correct_href(href) jQuery("#body_desktop").hide() # self.new_page(title, data_or_html.innerHTML, href2, title_alt) self.new_page(title, data_or_html, href2, title_alt) jQuery(".auto-hide").trigger("click") return False else: mount_html(document.querySelector("#body_desktop"), data_or_html, None) jQuery(".auto-hide").trigger("click") return False
Splawik/pytigon
[ 6, 1, 6, 2, 1419597762 ]
def __init__(self, fname=None): if not fname: fname = '/usr/share/dict/words' with open(fname) as f: self.repository = [x.rstrip('\n') for x in f.readlines()]
amitsaha/learning
[ 4, 4, 4, 20, 1413605035 ]
def find_close_matches(r, w, count=3): return difflib.get_close_matches(w, r.repository, count)
amitsaha/learning
[ 4, 4, 4, 20, 1413605035 ]
def create_update_Conv2d(c_in, c_out, k_size): kernel_scale = 1.0 / 3.0 if isinstance(k_size, list) or isinstance(k_size, tuple): bias_scale = c_out / (3.0 * c_in * k_size[0] * k_size[1]) else: bias_scale = c_out / (3.0 * c_in * k_size * k_size) return tf.keras.layers.Conv2D( filters=c_out, kernel_size=k_size, kernel_initializer=tf.keras.initializers.VarianceScaling( distribution='uniform', scale=kernel_scale, mode='fan_in'), bias_initializer=tf.keras.initializers.VarianceScaling( distribution='uniform', scale=bias_scale, mode='fan_in'))
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def __init__(self, hidden_dim=128, input_dim=192 + 128, **kwargs): super(ConvGRU, self).__init__(**kwargs) self.convz = create_update_Conv2d( c_in=hidden_dim + input_dim, c_out=hidden_dim, k_size=3) self.convr = create_update_Conv2d( c_in=hidden_dim + input_dim, c_out=hidden_dim, k_size=3) self.convq = create_update_Conv2d( c_in=hidden_dim + input_dim, c_out=hidden_dim, k_size=3)
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def __init__(self, hidden_dim=128, input_dim=192 + 128): super(SepConvGRU, self).__init__() self.convz1 = create_update_Conv2d( c_in=hidden_dim + input_dim, c_out=hidden_dim, k_size=(1, 5)) self.convr1 = create_update_Conv2d( c_in=hidden_dim + input_dim, c_out=hidden_dim, k_size=(1, 5)) self.convq1 = create_update_Conv2d( c_in=hidden_dim + input_dim, c_out=hidden_dim, k_size=(1, 5)) self.convz2 = create_update_Conv2d( c_in=hidden_dim + input_dim, c_out=hidden_dim, k_size=(5, 1)) self.convr2 = create_update_Conv2d( c_in=hidden_dim + input_dim, c_out=hidden_dim, k_size=(5, 1)) self.convq2 = create_update_Conv2d( c_in=hidden_dim + input_dim, c_out=hidden_dim, k_size=(5, 1))
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def __init__(self, hidden_dim=256, input_dim=128, **kwargs): super(FlowHead, self).__init__(**kwargs) self.conv1 = create_update_Conv2d( c_in=input_dim, c_out=hidden_dim, k_size=3) self.conv2 = create_update_Conv2d(c_in=hidden_dim, c_out=2, k_size=3)
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def __init__(self, args, **kwargs): super(BasicMotionEncoder, self).__init__(**kwargs) cor_planes = args.corr_levels * (2 * args.corr_radius + 1)**2 self.convc1 = create_update_Conv2d(c_in=cor_planes, c_out=256, k_size=1) self.convc2 = create_update_Conv2d(c_in=256, c_out=192, k_size=3) self.convf1 = create_update_Conv2d(c_in=2, c_out=128, k_size=7) self.convf2 = create_update_Conv2d(c_in=128, c_out=64, k_size=3) self.conv = create_update_Conv2d(c_in=64 + 192, c_out=128 - 2, k_size=3)
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def __init__(self, args, **kwargs): super(SmallMotionEncoder, self).__init__(**kwargs) cor_planes = args.corr_levels * (2 * args.corr_radius + 1)**2 self.convc1 = create_update_Conv2d(c_in=cor_planes, c_out=96, k_size=1) self.convf1 = create_update_Conv2d(c_in=96, c_out=64, k_size=7) self.convf2 = create_update_Conv2d(c_in=64, c_out=32, k_size=3) self.conv = create_update_Conv2d(c_in=32, c_out=80, k_size=3)
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def __init__(self, args, hidden_dim=128, **kwargs): super(BasicUpdateBlock, self).__init__(**kwargs) self.args = args self.encoder = BasicMotionEncoder(args) self.gru = SepConvGRU(hidden_dim=hidden_dim, input_dim=128 + hidden_dim) self.flow_head = FlowHead(hidden_dim=256, input_dim=hidden_dim) if args.convex_upsampling: self.mask = tf.keras.Sequential( [create_update_Conv2d(c_in=128, c_out=256, k_size=3), tf.keras.layers.ReLU(), create_update_Conv2d(c_in=256, c_out=64 * 9, k_size=1) ])
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def __init__(self, args, hidden_dim=96, **kwargs): super(SmallUpdateBlock, self).__init__(**kwargs) self.encoder = SmallMotionEncoder(args) self.gru = ConvGRU(hidden_dim=hidden_dim, input_dim=82 + 64) self.flow_head = FlowHead(hidden_dim=128, input_dim=hidden_dim)
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def sample_update_folder(): # Create a client client = resourcemanager_v3.FoldersClient() # Initialize request argument(s) folder = resourcemanager_v3.Folder() folder.parent = "parent_value" request = resourcemanager_v3.UpdateFolderRequest( folder=folder, ) # Make the request operation = client.update_folder(request=request) print("Waiting for operation to complete...") response = operation.result() # Handle the response print(response)
googleapis/python-resource-manager
[ 22, 19, 22, 9, 1575936598 ]
def setUp(self): self.fd, self.path = tempfile.mkstemp()
rbuffat/pyidf
[ 20, 7, 20, 2, 1417292720 ]
def domaindownload():# this function downloads domain and website links from multible blacklisted website databases. if os.path.isfile("list/list1.txt")==True: print "Malicious website database from https://spyeyetracker.abuse.ch exists!\n" print "Continuing with the next list." else: print "Fetching list from: https://spyeyetracker.abuse.ch" command1="wget https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist -O list/list1.txt" os.system(command1)
Masood-M/yalih
[ 66, 10, 66, 1, 1392605442 ]
def duplicateremover(): mylist=list() fopen2=open("list/malwebsites.txt","r") for line in fopen2: line=line.strip() if line.startswith("127.0.0.1"): line=line[10:] pass if line.startswith("#"): continue if line.find('#') == 1: continue
Masood-M/yalih
[ 66, 10, 66, 1, 1392605442 ]
def whitespace_split_with_indices( text: str) -> Tuple[List[str], List[int], List[int]]: """Whitespace splits a text into unigrams and returns indices mapping.""" if not isinstance(text, str): raise ValueError("The input text is not of unicode format.") unigrams = [] unigram_to_char_map = [] char_to_unigram_map = [] prev_is_separator = True for i, c in enumerate(text): if c in _WHITESPACE_DELIMITER: prev_is_separator = True else: if prev_is_separator: unigrams.append(c) unigram_to_char_map.append(i) else: unigrams[-1] += c prev_is_separator = False char_to_unigram_map.append(len(unigrams) - 1) return unigrams, unigram_to_char_map, char_to_unigram_map
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def get_wordpiece_tokenized_text( text: str, tokenizer: tokenization.FullTokenizer) -> TokenizedText: """Gets WordPiece TokenizedText for a text with indices mapping.""" unigrams, _, chars_to_unigrams = whitespace_split_with_indices(text) tokens, unigrams_to_tokens, tokens_to_unigrams = ( wordpiece_tokenize_with_indices(unigrams, tokenizer)) token_ids = tokenizer.convert_tokens_to_ids(tokens) tokenized_text = TokenizedText() tokenized_text.text = text tokenized_text.tokens = tokens tokenized_text.token_ids = token_ids tokenized_text.unigrams = unigrams tokenized_text.chars_to_unigrams = chars_to_unigrams tokenized_text.unigrams_to_tokens = unigrams_to_tokens tokenized_text.tokens_to_unigrams = tokens_to_unigrams return tokenized_text
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def get_sentencepiece_tokenized_text( text: str, tokenizer: tokenization.FullTokenizer) -> TokenizedText: """Gets SentencePiece TokenizedText for a text with indices mapping.""" tokens = [six.ensure_text(tk, "utf-8") for tk in tokenizer.tokenize(text)] token_ids = tokenizer.convert_tokens_to_ids(tokens) chars_to_tokens = [] for i, token in enumerate(tokens): num_chars = len(token) if i == 0: num_chars -= 1 chars_to_tokens.extend([i] * num_chars) token_ids = tokenizer.convert_tokens_to_ids(tokens) tokenized_text = TokenizedText() tokenized_text.text = sentencepiece_detokenize(tokens) tokenized_text.tokens = tokens tokenized_text.token_ids = token_ids tokenized_text.chars_to_tokens = chars_to_tokens return tokenized_text
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def _improve_answer_span( doc_tokens: Sequence[str], unimproved_span: Tuple[int, int], orig_answer_text: str, tokenizer: tokenization.FullTokenizer,
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]
def _convert_answer_spans(answer_unigram_spans: Sequence[Tuple[int, int]], unigram_to_token_map: Sequence[int], num_tokens: int) -> List[Tuple[int, int]]: """Converts answer unigram spans to token spans.""" answer_token_spans = [] for unigram_begin, unigram_end in answer_unigram_spans: token_begin = unigram_to_token_map[unigram_begin] if unigram_end + 1 < len(unigram_to_token_map): token_end = unigram_to_token_map[unigram_end + 1] - 1 else: token_end = num_tokens - 1 answer_token_spans.append((token_begin, token_end)) return answer_token_spans
google-research/google-research
[ 27788, 6881, 27788, 944, 1538678568 ]