function
stringlengths
11
56k
repo_name
stringlengths
5
60
features
list
def __init__(self): self.api = compute_api.AggregateAPI()
ntt-sic/nova
[ 1, 2, 1, 1, 1382427064 ]
def create(self, req, body): """Creates an aggregate, given its name and availability_zone.""" context = _get_context(req) authorize(context) if len(body) != 1: raise exc.HTTPBadRequest() try: host_aggregate = body["aggregate"] name = host_agg...
ntt-sic/nova
[ 1, 2, 1, 1, 1382427064 ]
def update(self, req, id, body): """Updates the name and/or availability_zone of given aggregate.""" context = _get_context(req) authorize(context) if len(body) != 1: raise exc.HTTPBadRequest() try: updates = body["aggregate"] except KeyError: ...
ntt-sic/nova
[ 1, 2, 1, 1, 1382427064 ]
def action(self, req, id, body): _actions = { 'add_host': self._add_host, 'remove_host': self._remove_host, 'set_metadata': self._set_metadata, } for action, data in body.iteritems(): if action not in _actions.keys(): msg = _('Aggre...
ntt-sic/nova
[ 1, 2, 1, 1, 1382427064 ]
def _add_host(self, req, id, host): """Adds a host to the specified aggregate.""" context = _get_context(req) authorize(context) try: aggregate = self.api.add_host_to_aggregate(context, id, host) except (exception.AggregateNotFound, exception.ComputeHostNotFound): ...
ntt-sic/nova
[ 1, 2, 1, 1, 1382427064 ]
def _remove_host(self, req, id, host): """Removes a host from the specified aggregate.""" context = _get_context(req) authorize(context) try: aggregate = self.api.remove_host_from_aggregate(context, id, host) except (exception.AggregateNotFound, exception.AggregateHos...
ntt-sic/nova
[ 1, 2, 1, 1, 1382427064 ]
def _marshall_aggregate(self, aggregate): _aggregate = {} for key, value in aggregate.items(): # NOTE(danms): The original API specified non-TZ-aware timestamps if isinstance(value, datetime.datetime): value = value.replace(tzinfo=None) _aggregate[key]...
ntt-sic/nova
[ 1, 2, 1, 1, 1382427064 ]
def __init__(self, ext_mgr): ext_mgr.register(self)
ntt-sic/nova
[ 1, 2, 1, 1, 1382427064 ]
def mul(a, b): if a == 0 or b == 0: return 0 return alog[(log[a & 0xFF] + log[b & 0xFF]) % 255]
azumimuo/family-xbmc-addon
[ 1, 3, 1, 2, 1456692116 ]
def mul4(a, bs): if a == 0: return 0 r = 0 for b in bs: r <<= 8 if b != 0: r = r | mul(a, b) return r
azumimuo/family-xbmc-addon
[ 1, 3, 1, 2, 1456692116 ]
def __init__(self, key, block_size=16): if block_size != 16 and block_size != 24 and block_size != 32: raise ValueError('Invalid block size: ' + str(block_size)) if len(key) != 16 and len(key) != 24 and len(key) != 32: raise ValueError('Invalid key size: ' + str(len(key))) ...
azumimuo/family-xbmc-addon
[ 1, 3, 1, 2, 1456692116 ]
def decrypt(self, ciphertext): if len(ciphertext) != self.block_size: raise ValueError('wrong block length, expected ' + str(self.block_size) + ' got ' + str(len(ciphertext))) Kd = self.Kd BC = self.block_size // 4 ROUNDS = len(Kd) - 1 if BC == 4: SC = 0 ...
azumimuo/family-xbmc-addon
[ 1, 3, 1, 2, 1456692116 ]
def getStdMonthNames(): return list(map(string.lower,_monthName))
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def getStdDayNames(): return list(map(string.lower,_dayOfWeekName))
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def isLeapYear(year): """determine if specified year is leap year, returns Python boolean""" if year < 1600: if year % 4: return 0 else: return 1 elif year % 4 != 0: return 0 elif year % 100 != 0: return 1 elif year % 400 != 0: return 0...
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def __init__(self, normalDate=None): """ Accept 1 of 4 values to initialize a NormalDate: 1. None - creates a NormalDate for the current day 2. integer in yyyymmdd format 3. string in yyyymmdd format 4. tuple in (yyyy, mm, dd) - localtime/gmtime can also b...
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def __add__(self, days): """add integer to normalDate and return a new, calculated value""" if not isinstance(days,int): raise NormalDateException( \ '__add__ parameter must be integer type') cloned = self.clone() cloned.add(days) return cloned
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def clone(self): """return a cloned instance of this normalDate""" return self.__class__(self.normalDate)
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def day(self): """return the day as integer 1-31""" return int(repr(self.normalDate)[-2:])
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def dayOfWeekAbbrev(self): """return day of week abbreviation for current date: Mon, Tue, etc.""" return _dayOfWeekName[self.dayOfWeek()][:3]
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def dayOfYear(self): """day of year""" if self.isLeapYear(): daysByMonth = _daysInMonthLeapYear else: daysByMonth = _daysInMonthNormal priorMonthDays = 0 for m in range(self.month() - 1): priorMonthDays = priorMonthDays + daysByMonth[m] ...
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def equals(self, target): if isinstance(target,NormalDate): if target is None: return self.normalDate is None else: return self.normalDate == target.normalDate else: return 0
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def firstDayOfMonth(self): """returns (cloned) first day of month""" return self.__class__(self.__repr__()[-8:-2]+"01")
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def formatUSCentury(self): """return date as string in 4-digit year US format: MM/DD/YYYY""" d = self.__repr__() return "%s/%s/%s" % (d[-4:-2], d[-2:], d[-8:-4])
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def _fmtMM(self): return '%02d' % self.month()
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def _fmtMMMM(self): return self.monthName()
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def _fmtD(self): return str(self.day())
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def _fmtDDD(self): return self.dayOfWeekAbbrev()
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def _fmtYY(self): return '%02d' % (self.year()%100)
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def formatMS(self,fmt): '''format like MS date using the notation {YY} --> 2 digit year {YYYY} --> 4 digit year {M} --> month as digit {MM} --> 2 digit month {MMM} --> abbreviated month name {MMMM} --> monthname {MMMMM} --> first character of...
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def __hash__(self): return hash(self.normalDate)
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def isLeapYear(self): """ determine if specified year is leap year, returning true (1) or false (0) """ return isLeapYear(self.year())
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def lastDayOfMonth(self): """returns last day of the month as integer 28-31""" if self.isLeapYear(): return _daysInMonthLeapYear[self.month() - 1] else: return _daysInMonthNormal[self.month() - 1]
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def month(self): """returns month as integer 1-12""" return int(repr(self.normalDate)[-4:-2])
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def monthName(self): """returns month name, i.e. January, February, etc.""" return _monthName[self.month() - 1]
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def range(self, days): """Return a range of normalDates as a list. Parameter may be an int or normalDate.""" if not isinstance(days,int): days = days - self # if not int, assume arg is normalDate type r = [] for i in range(days): r.append(self + i) ...
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def scalar(self): """days since baseline date: Jan 1, 1900""" (year, month, day) = self.toTuple() days = firstDayOfYear(year) + day - 1 if self.isLeapYear(): for m in range(month - 1): days = days + _daysInMonthLeapYear[m] else: for m in ra...
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def setMonth(self, month): """set the month [1-12]""" if month < 1 or month > 12: raise NormalDateException('month is outside range 1 to 12') (y, m, d) = self.toTuple() self.setNormalDate((y, month, d))
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def setYear(self, year): if year == 0: raise NormalDateException('cannot set year to zero') elif year < -9999: raise NormalDateException('year cannot be less than -9999') elif year > 9999: raise NormalDateException('year cannot be greater than 9999') (...
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def __sub__(self, v): if isinstance(v,int): return self.__add__(-v) return self.scalar() - v.scalar()
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def toTuple(self): """return date as (year, month, day) tuple""" return (self.year(), self.month(), self.day())
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def bigBang(): """return lower boundary as a NormalDate""" return NormalDate((-9999, 1, 1))
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def dayOfWeek(y, m, d): """return integer representing day of week, Mon=0, Tue=1, etc.""" if m == 1 or m == 2: m = m + 12 y = y - 1 return (d + 2*m + 3*(m+1)//5 + y + y//4 - y//100 + y//400) % 7
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def FND(d): '''convert to ND if required''' return isinstance(d,NormalDate) and d or ND(d)
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def add(self, days): """add days to date; use negative integers to subtract""" if not isinstance(days,int): raise NormalDateException('add method parameter must be integer') self.normalize(self.scalar() + days)
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def __sub__(self, v): return isinstance(v,int) and self.__add__(-v) or self.scalar() - v.scalar()
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def daysBetweenDates(self, normalDate): return self.asNormalDate.daysBetweenDates(normalDate)
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def normalize(self, i): i = int(i) NormalDate.normalize(self,(i//5)*7+i%5+BDEpochScalar)
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def setNormalDate(self, normalDate): NormalDate.setNormalDate(self,normalDate) self._checkDOW()
Microvellum/Fluid-Designer
[ 69, 30, 69, 37, 1461884765 ]
def build_reimage_request_initial( resource_group_name: str, vm_scale_set_name: str, instance_id: str, subscription_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def build_deallocate_request_initial( resource_group_name: str, vm_scale_set_name: str, instance_id: str, subscription_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def build_delete_request_initial( resource_group_name: str, vm_scale_set_name: str, instance_id: str, subscription_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def build_get_request( resource_group_name: str, vm_scale_set_name: str, instance_id: str, subscription_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def build_get_instance_view_request( resource_group_name: str, vm_scale_set_name: str, instance_id: str, subscription_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def build_list_request( resource_group_name: str, virtual_machine_scale_set_name: str, subscription_id: str, *, filter: Optional[str] = None, select: Optional[str] = None, expand: Optional[str] = None, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def build_power_off_request_initial( resource_group_name: str, vm_scale_set_name: str, instance_id: str, subscription_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def build_restart_request_initial( resource_group_name: str, vm_scale_set_name: str, instance_id: str, subscription_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def build_start_request_initial( resource_group_name: str, vm_scale_set_name: str, instance_id: str, subscription_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def __init__(self, client, config, serializer, deserializer): self._client = client self._serialize = serializer self._deserialize = deserializer self._config = config
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def begin_reimage( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def get_long_running_output(pipeline_response): response = pipeline_response.http_response deserialized = self._deserialize('OperationStatusResponse', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def _deallocate_initial( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def begin_deallocate( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def get_long_running_output(pipeline_response): response = pipeline_response.http_response deserialized = self._deserialize('OperationStatusResponse', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def _delete_initial( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def begin_delete( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def get_long_running_output(pipeline_response): response = pipeline_response.http_response deserialized = self._deserialize('OperationStatusResponse', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def get( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def get_instance_view( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def list( self, resource_group_name: str, virtual_machine_scale_set_name: str, filter: Optional[str] = None, select: Optional[str] = None, expand: Optional[str] = None, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def prepare_request(next_link=None): if not next_link:
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def extract_data(pipeline_response): deserialized = self._deserialize("VirtualMachineScaleSetVMListResult", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) return deserialized.next_link or None, iter(list_of_el...
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def _power_off_initial( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def begin_power_off( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def get_long_running_output(pipeline_response): response = pipeline_response.http_response deserialized = self._deserialize('OperationStatusResponse', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def _restart_initial( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def begin_restart( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def get_long_running_output(pipeline_response): response = pipeline_response.http_response deserialized = self._deserialize('OperationStatusResponse', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def _start_initial( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def begin_start( self, resource_group_name: str, vm_scale_set_name: str, instance_id: str, **kwargs: Any
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def get_long_running_output(pipeline_response): response = pipeline_response.http_response deserialized = self._deserialize('OperationStatusResponse', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized
Azure/azure-sdk-for-python
[ 3526, 2256, 3526, 986, 1335285972 ]
def f2(): b, d = Base, Derived try: class MyNewClass(b, d): pass except: e2
github/codeql
[ 5783, 1304, 5783, 842, 1533054951 ]
def f4(): if cond: local = 1 try: local except: e4
github/codeql
[ 5783, 1304, 5783, 842, 1533054951 ]
def f6(): local = a_global try: local() except: e6
github/codeql
[ 5783, 1304, 5783, 842, 1533054951 ]
def f7(): try: 4 except: e7
github/codeql
[ 5783, 1304, 5783, 842, 1533054951 ]
def f9(): try: a, b = 1, 2 except: e9
github/codeql
[ 5783, 1304, 5783, 842, 1533054951 ]
def fb(): a, b, c = a_global try: seq = a, b, c except: eb
github/codeql
[ 5783, 1304, 5783, 842, 1533054951 ]
def fc(): a, b = a_global try: return a[b] except: ec
github/codeql
[ 5783, 1304, 5783, 842, 1533054951 ]
def fe(): try: call() except: ee else: ef
github/codeql
[ 5783, 1304, 5783, 842, 1533054951 ]
def set_test_params(self): self.num_nodes = 1 self.supports_cli = False
syscoin/syscoin
[ 164, 70, 164, 5, 1456717652 ]
def __init__(self, server_url, port, message_callback): """ server_url: url at which the server is to be run port: port for the socket to operate on message_callback: function to be called on incoming message objects (format: message_callback(self, data)) ...
facebookresearch/ParlAI
[ 9846, 2003, 9846, 72, 1493053844 ]
def _ensure_closed(self): try: self.ws.close() except websocket.WebSocketConnectionClosedException: pass
facebookresearch/ParlAI
[ 9846, 2003, 9846, 72, 1493053844 ]
def __init__( self, plotly_name="thicknessmode", parent_name="densitymapbox.colorbar", **kwargs
plotly/python-api
[ 13052, 2308, 13052, 1319, 1385013188 ]
def comb_sort(data: list) -> list: """Pure implementation of comb sort algorithm in Python :param data: mutable collection with comparable items :return: the same collection in ascending order Examples: >>> comb_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> comb_sort([]) [] >>> comb_sort...
TheAlgorithms/Python
[ 154959, 39275, 154959, 147, 1468662241 ]
def header_length(bytearray): """Return the length of s when it is encoded with base64.""" groups_of_3, leftover = divmod(len(bytearray), 3) # 4 bytes out for each 3 bytes (or nonzero fraction thereof) in. n = groups_of_3 * 4 if leftover: n += 4 return n
thonkify/thonkify
[ 17, 1, 17, 3, 1501859450 ]
def body_encode(s, maxlinelen=76, eol=NL): r"""Encode a string with base64. Each line will be wrapped at, at most, maxlinelen characters (defaults to 76 characters). Each line of encoded text will end with eol, which defaults to "\n". Set this to "\r\n" if you will be using the result of this fun...
thonkify/thonkify
[ 17, 1, 17, 3, 1501859450 ]
def loop_var01(): for i in range(10): pass return i
ktok07b6/polyphony
[ 90, 7, 90, 1, 1448846734 ]
def test(): loop_var01()
ktok07b6/polyphony
[ 90, 7, 90, 1, 1448846734 ]
def getCacheKeysAndQueries( cls, affected_refs: TAffectedReferences
the-blue-alliance/the-blue-alliance
[ 334, 153, 334, 422, 1283632451 ]
def updateMerge( cls, new_model: Media, old_model: Media, auto_union: bool = True
the-blue-alliance/the-blue-alliance
[ 334, 153, 334, 422, 1283632451 ]