function
stringlengths
11
56k
repo_name
stringlengths
5
60
features
list
def test_login_with_wrong_domain(self): project = Domain.get_or_create_with_name('api-test-fail', is_active=True) self.addCleanup(project.delete) self.assertAuthenticationFail(LoginAndDomainAuthentication(), self._get_request_with_api_key(domain=project.name...
dimagi/commcare-hq
[ 465, 201, 465, 202, 1247158807 ]
def test_auth_type_basic_no_domain(self): self.assertAuthenticationFail(LoginAndDomainAuthentication(), self._get_request_with_basic_auth())
dimagi/commcare-hq
[ 465, 201, 465, 202, 1247158807 ]
def setUpClass(cls): super().setUpClass() cls.role_with_permission = UserRole.create( cls.domain, 'edit-data', permissions=Permissions(edit_data=True) ) cls.role_without_permission = UserRole.create( cls.domain, 'no-edit-data', permissions=Permissions(edit_data=Fa...
dimagi/commcare-hq
[ 465, 201, 465, 202, 1247158807 ]
def test_login_no_auth_with_domain(self): self.assertAuthenticationFail(self.require_edit_data, self._get_request(domain=self.domain))
dimagi/commcare-hq
[ 465, 201, 465, 202, 1247158807 ]
def test_login_with_domain_no_permissions(self): self.assertAuthenticationFail(self.require_edit_data, self._get_request_with_api_key(domain=self.domain))
dimagi/commcare-hq
[ 465, 201, 465, 202, 1247158807 ]
def test_domain_admin_with_explicit_roles(self): api_key_with_explicit_permissions, _ = HQApiKey.objects.get_or_create( user=WebUser.get_django_user(self.domain_admin), name='explicit_with_permission', role_id=self.role_with_permission.get_id, ) api_key_withou...
dimagi/commcare-hq
[ 465, 201, 465, 202, 1247158807 ]
def test_login_with_explicit_permission_and_roles(self): api_key_with_explicit_permissions, _ = HQApiKey.objects.get_or_create( user=WebUser.get_django_user(self.user_with_permission), name='explicit_with_permission', role_id=self.role_with_permission.get_id, ) ...
dimagi/commcare-hq
[ 465, 201, 465, 202, 1247158807 ]
def test_login_with_wrong_permission(self): api_key_without_permissions, _ = HQApiKey.objects.get_or_create( user=WebUser.get_django_user(self.user_without_permission) ) self.assertAuthenticationFail(self.require_edit_data, self._get_request( ...
dimagi/commcare-hq
[ 465, 201, 465, 202, 1247158807 ]
def test_explicit_role_wrong_domain(self): project = Domain.get_or_create_with_name('api-test-fail-2', is_active=True) self.addCleanup(project.delete) user = WebUser.create(self.domain, 'multi_domain_admin', '***', None, None, is_admin=True) user.add_domain_membership(project.name, is_ad...
dimagi/commcare-hq
[ 465, 201, 465, 202, 1247158807 ]
def forwards(self, orm):
drawquest/drawquest-web
[ 19, 6, 19, 2, 1447125196 ]
def backwards(self, orm): # Renaming column for 'Comment.parent_content' to match new field type. db.rename_column('canvas_comment', 'parent_content_id', 'parent_content') # Changing field 'Comment.parent_content' db.alter_column('canvas_comment', 'parent_content', self.gf('django.db.mo...
drawquest/drawquest-web
[ 19, 6, 19, 2, 1447125196 ]
def read_kl(filename): with open(filename, 'r') as f: inp = f.read() inlist = inp.split('\n') inlist = [ x for x in inlist if x != ''] inlist = [ x for x in inlist if x[0] != '#'] inlist = [x.split(' ') for x in inlist] #print inlist x_in = np.array([ float(x[0]) for x in inlist]) ...
DocBO/mubosym
[ 14, 8, 14, 1, 1441211238 ]
def __init__(self, filename, tst = False): self.vx, self.vy = read_kl(filename) self.f_interp = interp1d(self.vx, self.vy, kind = 'linear', bounds_error=False) # Test: if tst: x_dense = np.linspace(-1., 15., 200) y_dense = [] for xx in x_dense: ...
DocBO/mubosym
[ 14, 8, 14, 1, 1441211238 ]
def strip_caret_codes(text): """Strip out any caret codes from a string. :param str text: The text to strip the codes from :returns str: The clean text """ text = text.replace('^^', '\x00') for token, foo in ANSI_CODES.items(): text = text.replace(token, '') return text.replace('\x...
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def word_wrap(text, columns=80, indent=4, padding=2): """Given a block of text, break it into a list of lines wrapped to length. :param str text: The text to wrap :param int columns: The number of columns to wrap the text to :param int indent: The number of spaces to indent additionally lines to :p...
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def __init__(self): self.local_option = UNKNOWN # Local state of an option self.remote_option = UNKNOWN # Remote state of an option self.reply_pending = False # Are we expecting a reply?
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def __init__(self, sock, addr_tup): """Create a new client connection. :param socket.socket sock: The socket of the new connection :param tuple addr_tup: A tuple of (address, port number) """ self.protocol = 'telnet' self.active = True # Turns False when the connection...
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def get_command(self): """Get a line of text that was received from the client. The client's cmd_ready attribute will be true if lines are available. :returns str: The found command or None """ cmd = None count = len(self.command_list) if count > 0: ...
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def send_cc(self, text): """Send text with caret codes converted to ANSI codes. :param str text: The text to send :returns None: """ self.send(colorize(text, self.use_ansi))
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def deactivate(self): """Set the client to disconnect on the next server poll.""" self.active = False
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def idle(self): """Return the client's idle time. Idle time is the number of seconds that have elapsed since the client last sent us some input. :returns float: The idle time, in seconds """ return time.time() - self.last_input_time
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def request_do_sga(self): """Request client to Suppress Go-Ahead. See RFC 858. """ self._iac_do(SGA) self._note_reply_pending(SGA, True)
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def request_wont_echo(self): """Tell the client that we would like to stop echoing their text. See RFC 857. """ self._iac_wont(ECHO) self._note_reply_pending(ECHO, True) self.telnet_echo = False
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def password_mode_off(self): """Tell client we are done echoing (we lied) and show typing again.""" self._iac_wont(ECHO) self._note_reply_pending(ECHO, True)
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def request_terminal_type(self): """Request the terminal type from the client. See RFC 779. """ self._iac_do(TTYPE) self._note_reply_pending(TTYPE, True)
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def socket_send(self): """Send data to the client socket. Called by TelnetServer when there is data ready to send. """ if len(self.send_buffer): try: # Convert to ANSI before sending. sent = self.sock.send(bytes(self.send_buffer, "cp1252")) ...
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def _recv_byte(self, byte): """Process receiving a single byte. Non-printable filtering currently disabled because it did not play well with extended character sets. :param str byte: The byte to buffer :returns None: """ # Filter out non-printing characters. ...
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def _iac_sniffer(self, byte): """Check incoming data for Telnet IAC sequences. Passes the data, if any, with the IAC commands stripped to _recv_byte(). :param str byte: The byte to check :returns None: """ # Are we not currently in an IAC sequence coming from t...
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def _three_byte_cmd(self, option): """Handle incoming Telnet commands that are three bytes long. :param str option: The received option byte :returns None: """ cmd = self.telnet_got_cmd logging.debug("Got three byte cmd {}:{}" .format(_COMMAND_NAME...
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def _check_local_option(self, option): """Test the status of local negotiated Telnet options.""" if option not in self.telnet_opt_dict: self.telnet_opt_dict[option] = TelnetOption() return self.telnet_opt_dict[option].local_option
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def _check_remote_option(self, option): """Test the status of remote negotiated Telnet options.""" if option not in self.telnet_opt_dict: self.telnet_opt_dict[option] = TelnetOption() return self.telnet_opt_dict[option].remote_option
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def _check_reply_pending(self, option): """Test the status of requested Telnet options.""" if option not in self.telnet_opt_dict: self.telnet_opt_dict[option] = TelnetOption() return self.telnet_opt_dict[option].reply_pending
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def _iac_do(self, option): """Send a Telnet IAC "DO" sequence.""" self.send("{}{}{}".format(IAC, DO, option))
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def _iac_will(self, option): """Send a Telnet IAC "WILL" sequence.""" self.send("{}{}{}".format(IAC, WILL, option))
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def __init__(self, port=23, address='', on_connect=None, on_disconnect=None, max_connections=MAX_CONNECTIONS, timeout=0.1, server_socket=None, create_client=True): """ Create a new Telnet server. :param int port: The port to listen for new connection on; on ...
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def client_count(self): """Return the number of active connections. :returns int: The client count """ return len(self.clients)
whutch/atria
[ 16, 4, 16, 22, 1394417605 ]
def create(kernel): result = Intangible() result.template = "object/draft_schematic/food/shared_drink_charde.iff" result.attribute_template_id = -1 result.stfName("string_id_table","")
anhstudios/swganh
[ 62, 37, 62, 37, 1297996365 ]
def validate(self): self.set_active() self.create_custom_field_for_workflow_state() self.update_default_workflow_status() self.validate_docstatus()
frappe/frappe
[ 4495, 2418, 4495, 1493, 1307520856 ]
def create_custom_field_for_workflow_state(self): frappe.clear_cache(doctype=self.document_type) meta = frappe.get_meta(self.document_type) if not meta.get_field(self.workflow_state_field): # create custom field frappe.get_doc({ "doctype":"Custom Field", "dt": self.document_type, "__islocal": 1,...
frappe/frappe
[ 4495, 2418, 4495, 1493, 1307520856 ]
def update_doc_status(self): ''' Checks if the docstatus of a state was updated. If yes then the docstatus of the document with same state will be updated ''' doc_before_save = self.get_doc_before_save() before_save_states, new_states = {}, {} if doc_before_save: for d in doc_before_save.states: ...
frappe/frappe
[ 4495, 2418, 4495, 1493, 1307520856 ]
def get_state(state): for s in self.states: if s.state==state: return s frappe.throw(frappe._("{0} not a valid State").format(state))
frappe/frappe
[ 4495, 2418, 4495, 1493, 1307520856 ]
def set_active(self): if int(self.is_active or 0): # clear all other frappe.db.sql("""UPDATE `tabWorkflow` SET `is_active`=0 WHERE `document_type`=%s""", self.document_type)
frappe/frappe
[ 4495, 2418, 4495, 1493, 1307520856 ]
def get_fieldnames_for(doctype): return [f.fieldname for f in frappe.get_meta(doctype).fields \ if f.fieldname not in no_value_fields]
frappe/frappe
[ 4495, 2418, 4495, 1493, 1307520856 ]
def create(kernel): result = Tangible() result.template = "object/tangible/furniture/all/shared_frn_all_lamp_candlestick_tbl_s03.iff" result.attribute_template_id = 6 result.stfName("frn_n","frn_lamp_candlestick_coronet")
anhstudios/swganh
[ 62, 37, 62, 37, 1297996365 ]
def get_parser(): parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description='OpenStack provisioning and orchestration library with command-line tools' ) parser.add_argument( '-v', '--version', action='version', version=__version__...
jiasir/playback
[ 5, 5, 5, 2, 1425471009 ]
def main(): try: _main() except: pass
jiasir/playback
[ 5, 5, 5, 2, 1425471009 ]
def __init__(self, lat_tile_start, lat_tile_end, lon_tile_start, lon_tile_end, username, password, arcsecond_sampling = 1, mask_water = True, store_geolocation_grids=False): ''' Initialize Data Fetcher @param lat_tile_start: Latitude of the southwest corner of ...
skdaccess/skdaccess
[ 44, 13, 44, 1, 1463415207 ]
def output(self): ''' Generate SRTM data wrapper @return SRTM Image Wrapper ''' lat_tile_array = np.arange(self.lat_tile_start, self.lat_tile_end+1) lon_tile_array = np.arange(self.lon_tile_start, self.lon_tile_end+1) lat_grid,lon_grid = np.meshgrid(lat_tile_ar...
skdaccess/skdaccess
[ 44, 13, 44, 1, 1463415207 ]
def getCoordinates(filename): ''' Determine the longitude and latitude of the lowerleft corner of the input filename @param in_filename: Input SRTM filename @return Latitude of southwest corner, Longitude of southwest corner ''' lat_start = int(f...
skdaccess/skdaccess
[ 44, 13, 44, 1, 1463415207 ]
def create(kernel): result = Tangible() result.template = "object/tangible/wearables/ithorian/shared_ith_backpack_s01.iff" result.attribute_template_id = 11 result.stfName("wearables_name","ith_backpack_s01")
anhstudios/swganh
[ 62, 37, 62, 37, 1297996365 ]
def complete_login(self, request, app, token, **kwargs): resp = requests.get( self.profile_url, headers={"Authorization": "Bearer " + token.token}, ) extra_data = resp.json().get("data") if USE_API_V2: # Extract tier/pledge level for Patreon API v2: ...
pennersr/django-allauth
[ 7816, 2745, 7816, 352, 1286741452 ]
def make_target(args): try: target = NovaCompute(user=args.user, hosts=args.hosts.split(','), key_filename=args.key_filename, password=args.password) except AttributeError: sys.stderr.write('No hosts found. Please using --hosts param.') sys.exit(1) return...
jiasir/playback
[ 5, 5, 5, 2, 1425471009 ]
def get_parser(self, prog_name): parser = super(Install, self).get_parser(prog_name) parser.add_argument('--user', help='the username to connect to the remote host', action='store', default='ubuntu', dest='user') parser.add_argument('--host...
jiasir/playback
[ 5, 5, 5, 2, 1425471009 ]
def create(kernel): result = Tangible() result.template = "object/tangible/loot/simple_kit/shared_tumble_blender.iff" result.attribute_template_id = -1 result.stfName("loot_n","tumble_blender")
anhstudios/swganh
[ 62, 37, 62, 37, 1297996365 ]
def __init__(self, get_response): self.get_response = get_response # One-time configuration and initialization.
bnzk/djangocms-misc
[ 2, 1, 2, 15, 1471614214 ]
def __init__(self): self.monitor = TacticMonitor()
Southpaw-TACTIC/TACTIC
[ 473, 170, 473, 29, 1378771601 ]
def init(self): self.monitor.mode = "init" self.monitor.execute()
Southpaw-TACTIC/TACTIC
[ 473, 170, 473, 29, 1378771601 ]
def write_stop_monitor(): '''write a stop.monitor file to notify TacticMonitor to exit''' log_dir = "%s/log" % Environment.get_tmp_dir() if not os.path.exists(log_dir): os.makedirs(log_dir)
Southpaw-TACTIC/TACTIC
[ 473, 170, 473, 29, 1378771601 ]
def stop():
Southpaw-TACTIC/TACTIC
[ 473, 170, 473, 29, 1378771601 ]
def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) # create an event that SvcDoRun can wait on and SvcStop # can set. self.stop_event = win32event.CreateEvent(None, 0, 0, None)
Southpaw-TACTIC/TACTIC
[ 473, 170, 473, 29, 1378771601 ]
def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) stop() win32event.SetEvent(self.stop_event)
Southpaw-TACTIC/TACTIC
[ 473, 170, 473, 29, 1378771601 ]
def setUp(self): super().setUp() self.host = "abc.com" self.port = 80 self.api_path = "/v1/" self.path_list = ['test', 'more', 'test'] self.complete_path = "/v1/test/more/test" self.ws = MagicMock(auto_spec=WebService) self.api = APIHelper(self.host, self....
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def test_get(self): self.api.get(self.path_list, None) self._test_ws_function_args(self.ws.get)
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def test_put(self): self.api.put(self.path_list, None, None) self._test_ws_function_args(self.ws.put)
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def setUp(self): super().setUp() self.config = {'server_host': "mb.org", "server_port": 443} self.set_config_values(self.config) self.ws = MagicMock(auto_spec=WebService) self.api = MBAPIHelper(self.ws)
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def assertInPath(self, ws_function, path): self.assertIn(path, ws_function.call_args[0][2])
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def assertInQuery(self, ws_function, argname, value=None): query_args = ws_function.call_args[1]['queryargs'] self.assertIn(argname, query_args) self.assertEqual(value, query_args[argname])
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def test_get_release(self): inc_args_list = ['test'] self.api.get_release_by_id("1", None, inc=inc_args_list) self._test_ws_function_args(self.ws.get) self.assertInPath(self.ws.get, "/release/1") self._test_inc_args(self.ws.get, inc_args_list)
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def test_get_collection(self): inc_args_list = ["releases", "artist-credits", "media"] self.api.get_collection("1", None) self._test_ws_function_args(self.ws.get) self.assertInPath(self.ws.get, "collection") self.assertInPath(self.ws.get, "1/releases") self._test_inc_args...
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def test_put_collection(self): self.api.put_to_collection("1", ["1", "2", "3"], None) self._test_ws_function_args(self.ws.put) self.assertInPath(self.ws.put, "collection/1/releases/1;2;3")
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def test_xml_ratings_empty(self): ratings = dict() xmldata = self.api._xml_ratings(ratings) self.assertEqual( xmldata, '<?xml version="1.0" encoding="UTF-8"?>' '<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">' '<recording-list></recording-lis...
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def test_xml_ratings_multiple(self): ratings = { ("recording", 'a'): 1, ("recording", 'b'): 2, ("nonrecording", 'c'): 3, } xmldata = self.api._xml_ratings(ratings) self.assertEqual( xmldata, '<?xml version="1.0" encoding="UTF-8"...
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def test_xml_ratings_raises_value_error(self): ratings = {("recording", 'a'): 'foo'} self.assertRaises(ValueError, self.api._xml_ratings, ratings)
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def setUp(self): super().setUp() self.config = {'acoustid_apikey': "apikey"} self.set_config_values(self.config) self.ws = MagicMock(auto_spec=WebService) self.api = AcoustIdAPIHelper(self.ws) self.api.acoustid_host = 'acoustid_host' self.api.acoustid_port = 443 ...
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def test_encode_acoustid_args_static_empty(self): args = dict() result = self.api._encode_acoustid_args(args) expected = 'client=key&clientversion=ver&format=json' self.assertEqual(result, expected)
metabrainz/picard
[ 3087, 366, 3087, 9, 1313533823 ]
def testMediaChange(app): vmname = "test-many-devices" app.uri = tests.utils.URIs.test_remote app.open(show_console=vmname) win = app.find_details_window(vmname, click_details=True, shutdown=True) hw = win.find("hw-list") tab = win.find("disk-tab") combo = win.find("media-combo")...
virt-manager/virt-manager
[ 1688, 378, 1688, 80, 1432252820 ]
def db2a(db): return np.power(10, (db / 20.0))
reuk/waveguide
[ 135, 19, 135, 7, 1440435580 ]
def series_coeffs(c): return reduce(lambda (a, b), (x, y): ( np.convolve(a, x), np.convolve(b, y)), c)
reuk/waveguide
[ 135, 19, 135, 7, 1440435580 ]
def get_linkwitz_riley_coeffs(gain, lo, hi, sr): def get_c(cutoff, sr): wcT = pi * cutoff / sr return 1 / tan(wcT) def get_lopass_coeffs(gain, cutoff, sr): c = get_c(cutoff, sr) a0 = c * c + c * sqrt(2) + 1 b = [gain / a0, 2 * gain / a0, gain / a0] a = [1, (-2 * ...
reuk/waveguide
[ 135, 19, 135, 7, 1440435580 ]
def get_peak_coeffs(gain, centre, sr, Q): A = db2a(gain / 2) w0 = 2 * pi * centre / sr cw0 = cos(w0) sw0 = sin(w0) alpha = sw0 / 2 * Q a0 = 1 + alpha / A b = [(1 + (alpha * A)) / a0, (-2 * cw0) / a0, (1 - alpha * A) / a0] a = [1, (-2 * cw0) / a0, (1 - alpha / A) / a0] return b, a
reuk/waveguide
[ 135, 19, 135, 7, 1440435580 ]
def biquad_step(i, bm, bc): out = i * bc.b0 + bm.z1 bm.z1 = i * bc.b1 - bc.a1 * out + bm.z2 bm.z2 = i * bc.b2 - bc.a2 * out return out
reuk/waveguide
[ 135, 19, 135, 7, 1440435580 ]
def impedance_filter(c): num = c[0] den = c[1] summed = [a + b for a, b in zip(den, num)] subbed = [a - b for a, b in zip(den, num)] norm = 1 / subbed[0] summed = [i * norm for i in summed] subbed = [i * norm for i in subbed] return [summed, subbed]
reuk/waveguide
[ 135, 19, 135, 7, 1440435580 ]
def main(): edges = [30, 60, 120, 240] corners = zip(edges[:-1], edges[1:]) centres = [(a + b) / 2 for a, b in corners]
reuk/waveguide
[ 135, 19, 135, 7, 1440435580 ]