function
stringlengths
11
56k
repo_name
stringlengths
5
60
features
list
def build_schema(self): """ Returns a dictionary of all the fields on the resource and some properties about those fields.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def dehydrate_resource_uri(self, bundle): """ For the automatically included ``resource_uri`` field, dehydrate the URI for the given bundle.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def generate_cache_key(self, *args, **kwargs): """ Creates a unique-enough cache key.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def get_object_list(self, request): """ A hook to allow making returning the list of available objects.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def apply_authorization_limits(self, request, object_list): """ Allows the ``Authorization`` class to further limit the object list. Also a hook to customize per ``Resource``. """ if hasattr(self._meta.authorization, 'apply_limits'): object_list = self._meta.authoriza...
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_get_list(self, request=None, **kwargs): """ Fetches the list of objects available on the resource.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def cached_obj_get_list(self, request=None, **kwargs): """ A version of ``obj_get_list`` that uses the cache as a means to get commonly-accessed data faster. """ cache_key = self.generate_cache_key('list', **kwargs) obj_list = self._meta.cache.get(cache_key)
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_get(self, request=None, **kwargs): """ Fetches an individual object on the resource.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def cached_obj_get(self, request=None, **kwargs): """ A version of ``obj_get`` that uses the cache as a means to get commonly-accessed data faster. """ cache_key = self.generate_cache_key('detail', **kwargs) bundle = self._meta.cache.get(cache_key)
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_create(self, bundle, request=None, **kwargs): """ Creates a new object based on the provided data.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_update(self, bundle, request=None, **kwargs): """ Updates an existing object (or creates a new object) based on the provided data.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_delete_list(self, request=None, **kwargs): """ Deletes an entire list of objects.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_delete(self, request=None, **kwargs): """ Deletes a single object.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def create_response(self, request, data): """ Extracts the common "which-format/serialize/return-response" cycle.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def is_valid(self, bundle, request=None): """ Handles checking if the data provided by the user is valid.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def rollback(self, bundles): """ Given the list of bundles, delete all objects pertaining to those bundles.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def get_list(self, request, **kwargs): """ Returns a serialized list of resources.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def get_detail(self, request, **kwargs): """ Returns a single serialized resource.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def put_list(self, request, **kwargs): """ Replaces a collection of resources with another collection.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def put_detail(self, request, **kwargs): """ Either updates an existing resource or creates a new one with the provided data.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def post_list(self, request, **kwargs): """ Creates a new resource/object with the provided data.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def post_detail(self, request, **kwargs): """ Creates a new subcollection of the resource under a resource.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def delete_list(self, request, **kwargs): """ Destroys a collection of resources/objects.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def delete_detail(self, request, **kwargs): """ Destroys a single resource/object.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def get_schema(self, request, **kwargs): """ Returns a serialized form of the schema of the resource.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def get_multiple(self, request, **kwargs): """ Returns a serialized list of resources based on the identifiers from the URL.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def __new__(cls, name, bases, attrs): new_class = super(ModelDeclarativeMetaclass, cls).__new__(cls, name, bases, attrs) fields = getattr(new_class._meta, 'fields', []) excludes = getattr(new_class._meta, 'excludes', []) field_names = new_class.base_fields.keys()
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def should_skip_field(cls, field): """ Given a Django model field, return if it should be included in the contributed ApiFields. """ # Ignore certain fields (related fields). if getattr(field, 'rel'): return True
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def api_field_from_django_field(cls, f, default=CharField): """ Returns the field type that would likely be associated with each Django type. """ result = default
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def get_fields(cls, fields=None, excludes=None): """ Given any explicit fields to include and fields to exclude, add additional fields based on the associated model. """ final_fields = {} fields = fields or [] excludes = excludes or []
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def build_filters(self, filters=None): """ Given a dictionary of filters, create the necessary ORM-level filters.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def apply_sorting(self, obj_list, options=None): """ Given a dictionary of options, apply some ORM-level sorting to the provided ``QuerySet``.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def get_object_list(self, request): """ An ORM-specific implementation of ``get_object_list``.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_get_list(self, request=None, **kwargs): """ A ORM-specific implementation of ``obj_get_list``.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_get(self, request=None, **kwargs): """ A ORM-specific implementation of ``obj_get``.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_create(self, bundle, request=None, **kwargs): """ A ORM-specific implementation of ``obj_create``. """ bundle.obj = self._meta.object_class()
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_update(self, bundle, request=None, **kwargs): """ A ORM-specific implementation of ``obj_update``. """ if not bundle.obj or not bundle.obj.pk: # Attempt to hydrate data from kwargs before doing a lookup for the object. # This step is needed so certain valu...
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_delete_list(self, request=None, **kwargs): """ A ORM-specific implementation of ``obj_delete_list``.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def obj_delete(self, request=None, **kwargs): """ A ORM-specific implementation of ``obj_delete``.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def rollback(self, bundles): """ A ORM-specific implementation of ``rollback``.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def save_m2m(self, bundle): """ Handles the saving of related M2M data.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def get_resource_uri(self, bundle_or_obj): """ Handles generating a resource URI for a single resource.
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def _build_reverse_url(self, name, args=None, kwargs=None): namespaced = "%s:%s" % (self._meta.urlconf_namespace, name) return reverse(namespaced, args=args, kwargs=kwargs)
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def convert_post_to_put(request): """ Force Django to process the PUT. """ if request.method == "PUT": if hasattr(request, '_post'): del request._post del request._files
colinsullivan/bingo-board
[ 5, 1, 5, 6, 1293081853 ]
def launch(self): logger = self.logger logger.debug('getDmidecode: start') res = {}
naparuba/kunai
[ 37, 6, 37, 56, 1424895275 ]
def replace_getOp(line): line2 = line if 'MI->getOperand(0)' in line: line2 = line.replace('MI->getOperand(0)', 'MCInst_getOperand(MI, 0)') elif 'MI->getOperand(1)' in line: line2 = line.replace('MI->getOperand(1)', 'MCInst_getOperand(MI, 1)') elif 'MI->getOperand(2)' in line: li...
capstone-rust/capstone-rs
[ 169, 64, 169, 16, 1428200612 ]
def extract_paren(line, text): i = line.index(text) return line[line.index('(', i)+1 : line.index(')', i)]
capstone-rust/capstone-rs
[ 169, 64, 169, 16, 1428200612 ]
def extract_brackets(line): if '<' in line: return line[line.index('<')+1 : line.index('>')] else: return ''
capstone-rust/capstone-rs
[ 169, 64, 169, 16, 1428200612 ]
def del_brackets(line): if '<' in line: return line[:line.index('<')] + line[line.index('>') + 1:] else: return line
capstone-rust/capstone-rs
[ 169, 64, 169, 16, 1428200612 ]
def connection_made(self, transport): self.transport = transport
1st1/uvloop
[ 9209, 537, 9209, 69, 1446956094 ]
def data_received(self, data): self.transport.write(data)
1st1/uvloop
[ 9209, 537, 9209, 69, 1446956094 ]
def connection_made(self, transport): self.transport = transport # Here the buffer is intended to be copied, so that the outgoing buffer # won't be wrongly updated by next read self.buffer = bytearray(256 * 1024)
1st1/uvloop
[ 9209, 537, 9209, 69, 1446956094 ]
def get_buffer(self, sizehint): return self.buffer
1st1/uvloop
[ 9209, 537, 9209, 69, 1446956094 ]
def request_account(): """Provides a form to request an account.""" return flask.render_template("request_account.html")
ASCIT/donut
[ 5, 3, 5, 14, 1422746684 ]
def request_account_submit(): """Handles an account creation request.""" uid = flask.request.form.get("uid", None) last_name = flask.request.form.get("last_name", None) if uid is None or last_name is None: flask.flash("Invalid request.") return flask.redirect(flask.url_for("account.reque...
ASCIT/donut
[ 5, 3, 5, 14, 1422746684 ]
def create_account(create_account_key): """Checks the key. If valid, displays the create account page.""" user_id = auth_utils.check_create_account_key(create_account_key) if user_id is None: flask.current_app.logger.warn( f'Invalid create_account_key: {create_account_key}') flas...
ASCIT/donut
[ 5, 3, 5, 14, 1422746684 ]
def reconnect(sheet, manager, **kwargs): """Performs reconnections (vertex merging / splitting) following Finegan et al. 2019 kwargs overwrite their corresponding `sheet.settings` entries Keyword Arguments ----------------- threshold_length : the threshold length at which vertex merging is perform...
CellModels/tyssue
[ 50, 17, 50, 22, 1426782444 ]
def division(sheet, manager, **kwargs): """Cell division happens through cell growth up to a critical volume, followed by actual division of the face. Parameters ---------- sheet : a `Sheet` object manager : an `EventManager` instance face_id : int, index of the mother face growth...
CellModels/tyssue
[ 50, 17, 50, 22, 1426782444 ]
def contraction(sheet, manager, **kwargs): """Single step contraction event.""" contraction_spec = default_contraction_spec contraction_spec.update(**kwargs) face = contraction_spec["face"] if (sheet.face_df.loc[face, "area"] < contraction_spec["critical_area"]) or ( sheet.face_df.loc[face,...
CellModels/tyssue
[ 50, 17, 50, 22, 1426782444 ]
def type1_transition(sheet, manager, **kwargs): """Custom type 1 transition event that tests if the the shorter edge of the face is smaller than the critical length. """ type1_transition_spec = default_type1_transition_spec type1_transition_spec.update(**kwargs) face = type1_transition_spec[...
CellModels/tyssue
[ 50, 17, 50, 22, 1426782444 ]
def face_elimination(sheet, manager, **kwargs): """Removes the face with if face_id from the sheet.""" face_elimination_spec = default_face_elimination_spec face_elimination_spec.update(**kwargs) remove(sheet, face_elimination_spec["face"], face_elimination_spec["geom"])
CellModels/tyssue
[ 50, 17, 50, 22, 1426782444 ]
def check_tri_faces(sheet, manager, **kwargs): """Three neighbourghs cell elimination Add all cells with three neighbourghs in the manager to be eliminated at the next time step. Parameters ---------- sheet : a :class:`tyssue.sheet` object manager : a :class:`tyssue.events.EventManager` obje...
CellModels/tyssue
[ 50, 17, 50, 22, 1426782444 ]
def __init__(self): pass
ezScrum/ezScrum
[ 31, 21, 31, 47, 1383034582 ]
def is_delete(self, tableName): reservedTableNameList = ["mantis_user_table", "mantis_tokens_table", "mantis_config_table"] isDeleteFlag = 1 for name in reservedTableNameList: isIdentical = cmp(tableName, name) if isIdentical == 0: isDeleteFlag = 0 ...
ezScrum/ezScrum
[ 31, 21, 31, 47, 1383034582 ]
def Clean_Database(self, hostUrl, account, password, databaseName): print 'clean database1' db = MySQLdb.connect(host=hostUrl, user=account, passwd=password, db=databaseName) cursor = db.cursor() cursor.execute("Show Tables from " + databaseName) result = cursor.fetchall() ...
ezScrum/ezScrum
[ 31, 21, 31, 47, 1383034582 ]
def __init__(self, name="generate" ): if name == "generate": self.name=socket.gethostname() else: self.name=name self.type="gc" self.decoded=""
LibraryBox-Dev/LibraryBox-core
[ 63, 35, 63, 5, 1374670088 ]
def get ( self ): # TODO Split decoded part message_parts = string.split ( self.decoded , ";" ) if message_parts[0] != "piratebox": return None b64_content_part = message_parts[4]
LibraryBox-Dev/LibraryBox-core
[ 63, 35, 63, 5, 1374670088 ]
def get_sendername (self): return self.name
LibraryBox-Dev/LibraryBox-core
[ 63, 35, 63, 5, 1374670088 ]
def set_message ( self , decoded): self.decoded = decoded
LibraryBox-Dev/LibraryBox-core
[ 63, 35, 63, 5, 1374670088 ]
def title(s): return re.sub(r'#+ ', '', s)
resamsel/dbmanagr
[ 4, 1, 4, 8, 1380777396 ]
def depth(s): return len(re.match(r'(#*)', s).group(0))
resamsel/dbmanagr
[ 4, 1, 4, 8, 1380777396 ]
def resolve_archive_name(repository, archive, storage_config, local_path='borg', remote_path=None): ''' Given a local or remote repository path, an archive name, a storage config dict, a local Borg path, and a remote Borg path, simply return the archive name. But if the archive name is "latest", then in...
witten/borgmatic
[ 1335, 77, 1335, 1, 1416363878 ]
def __init__(self, field, **kwargs): super().__init__(field) self.args.update(kwargs) self.output_key = 'hist_logscale' self.action = 'histogram_logscale'
stadelmanma/netl-ap-map-flow
[ 3, 3, 3, 12, 1453294533 ]
def _add_subparser(cls, subparsers, parent): r""" Adds a specific action based sub-parser to the supplied arg_parser instance. """ parser = subparsers.add_parser(cls.__name__, aliases=['histlog'], paren...
stadelmanma/netl-ap-map-flow
[ 3, 3, 3, 12, 1453294533 ]
def main(): parser = argparse.ArgumentParser() parser.add_argument("day", help="The day of the results, with format yyyymmdd") args = parser.parse_args() install_autopkgtest_results_formatter() with tempfile.TemporaryDirectory(dir=os.environ.get("HOME")) as temp_dir: clone_results_repo(temp_...
snapcore/snapcraft
[ 1092, 435, 1092, 66, 1446139395 ]
def clone_results_repo(dest_dir): subprocess.check_call( ["git", "clone", "https://github.com/elopio/autopkgtest-results.git", dest_dir] )
snapcore/snapcraft
[ 1092, 435, 1092, 66, 1446139395 ]
def commit_and_push(repo_dir, day): subprocess.check_call( ["git", "config", "--global", "user.email", "u1test+m-o@canonical.com"] ) subprocess.check_call(["git", "config", "--global", "user.name", "snappy-m-o"]) subprocess.check_call(["git", "-C", repo_dir, "add", "--all"]) subprocess.chec...
snapcore/snapcraft
[ 1092, 435, 1092, 66, 1446139395 ]
def __init__(self, query_params, pretty=False, **kwargs): self.pretty = pretty self._query_params = query_params self._fileName = None self._lastModified = None self._extra_args = kwargs
belokop/indico_bare
[ 1, 1, 1, 5, 1465204236 ]
def register(cls, tag, serializer): cls.registry[tag] = serializer
belokop/indico_bare
[ 1, 1, 1, 5, 1465204236 ]
def getAllFormats(cls): return list(cls.registry)
belokop/indico_bare
[ 1, 1, 1, 5, 1465204236 ]
def create(cls, dformat, query_params=None, **kwargs): """ A serializer factory """ query_params = query_params or {} serializer = cls.registry.get(dformat) if serializer: return serializer(query_params, **kwargs) else: raise Exception("...
belokop/indico_bare
[ 1, 1, 1, 5, 1465204236 ]
def set_headers(self, response): response.content_type = self.getMIMEType()
belokop/indico_bare
[ 1, 1, 1, 5, 1465204236 ]
def __str__(self): """Provides string to display on front end for referral. For FQHC referrals, returns referral kind and date. For non-FQHC referrals, returns referral location and date. """ formatted_date = self.written_datetime.strftime("%D") if self.kind.is_fq...
SaturdayNeighborhoodHealthClinic/osler
[ 14, 9, 14, 62, 1433002833 ]
def aggregate_referral_status(referrals): referral_status_output = "" if referrals: all_successful = all(referral.status == Referral.STATUS_SUCCESSFUL for referral in referrals) if all_successful: referral_status_output = (dict(Ref...
SaturdayNeighborhoodHealthClinic/osler
[ 14, 9, 14, 62, 1433002833 ]
def class_name(self): return self.__class__.__name__
SaturdayNeighborhoodHealthClinic/osler
[ 14, 9, 14, 62, 1433002833 ]
def summary(self): return self.contact_instructions
SaturdayNeighborhoodHealthClinic/osler
[ 14, 9, 14, 62, 1433002833 ]
def admin_url(self): return reverse( 'admin:referral_followuprequest_change', args=(self.id,) )
SaturdayNeighborhoodHealthClinic/osler
[ 14, 9, 14, 62, 1433002833 ]
def upgrade(): # Break op.create_table( 'breaks', sa.Column('id', sa.Integer(), nullable=False), sa.Column('title', sa.String(), nullable=False), sa.Column('description', sa.Text(), nullable=False), sa.Column('duration', sa.Interval(), nullable=False), sa.Column('...
belokop/indico_bare
[ 1, 1, 1, 5, 1465204236 ]
def abstract_serial_server(): return AbstractSerialServer()
AdvancedClimateSystems/python-modbus
[ 189, 68, 189, 36, 1444769179 ]
def set_print_granularity(p): global print_granularity print_granularity = p print("%s: print granularity = %s" % (sys.argv[0], print_granularity))
scalien/keyspace
[ 44, 17, 44, 1, 1271265059 ]
def setUp(self): super().setUp() self.anonymous_client = APIClient() self.different_user = UserFactory.create(password=TEST_PASSWORD) self.different_client = APIClient() self.staff_user = UserFactory(is_staff=True, password=TEST_PASSWORD) self.staff_client = APIClient() ...
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]
def send_post(self, client, json_data, content_type='application/json', expected_status=201): """ Helper method for sending a post to the server, defaulting to application/json content_type. Verifies the expected status and returns the response. """ # pylint: disable=no-member ...
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]
def post_search_api(self, client, json_data, content_type='application/json', expected_status=200): """ Helper method for sending a post to the server, defaulting to application/merge-patch+json content_type. Verifies the expected status and returns the response. """ # pylint: di...
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]
def send_put(self, client, json_data, content_type="application/json", expected_status=204): """ Helper method for sending a PUT to the server. Verifies the expected status and returns the response. """ response = client.put(self.url, data=json.dumps(json_data), content_type=content_type...
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]
def send_delete(self, client, expected_status=204): """ Helper method for sending a DELETE to the server. Verifies the expected status and returns the response. """ response = client.delete(self.url) assert expected_status == response.status_code return response
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]
def create_mock_verified_name(self, user): """ Helper method to create an approved VerifiedName entry in name affirmation. """ legacy_profile = UserProfile.objects.get(id=user.id) create_verified_name(user, self.VERIFIED_NAME, legacy_profile.name, status=VerifiedNameStatus.APPROV...
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]
def _verify_profile_image_data(self, data, has_profile_image): """ Verify the profile image data in a GET response for self.user corresponds to whether the user has or hasn't set a profile image. """ template = '{root}/{filename}_{{size}}.{extension}' if has_profi...
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]
def setUp(self): super().setUp() self.url = reverse("own_username_api")
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]
def test_get_username(self): """ Test that a client (logged in) can get her own username. """ self.client.login(username=self.user.username, password=TEST_PASSWORD) self._verify_get_own_username(17)
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]
def test_get_username_not_logged_in(self): """ Test that a client (not logged in) gets a 401 when trying to retrieve their username. """ # verify that the endpoint is inaccessible when not logged in self._verify_get_own_username(13, expected_status=401)
edx/edx-platform
[ 6290, 3437, 6290, 280, 1369945238 ]