uid stringlengths 24 24 | split stringclasses 1
value | category stringclasses 2
values | content stringlengths 5 482k | signature stringlengths 1 14k | suffix stringlengths 1 482k | prefix stringlengths 9 14k | prefix_token_count int64 3 5.01k | prefix_token_budget int64 64 256 | element_token_count int64 1 292k | signature_token_count int64 1 5.01k | prefix_context_token_count int64 0 255 | repo stringlengths 7 112 | path stringlengths 4 208 | language stringclasses 1
value | name stringlengths 1 218 | qualname stringlengths 1 218 | start_line int64 1 26.7k | end_line int64 1 26.7k | signature_start_line int64 1 26.7k | signature_end_line int64 1 26.7k | source_hash stringlengths 40 40 | source_dataset stringclasses 1
value | source_split stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
b05940228502a357cec32480 | train | function | async def async_setup(hass):
"""Enable the Device Registry views."""
hass.components.websocket_api.async_register_command(
WS_TYPE_LIST, websocket_list_devices, SCHEMA_WS_LIST
)
hass.components.websocket_api.async_register_command(
WS_TYPE_UPDATE, websocket_update_device, SCHEMA_WS_UPDAT... | async def async_setup(hass):
| """Enable the Device Registry views."""
hass.components.websocket_api.async_register_command(
WS_TYPE_LIST, websocket_list_devices, SCHEMA_WS_LIST
)
hass.components.websocket_api.async_register_command(
WS_TYPE_UPDATE, websocket_update_device, SCHEMA_WS_UPDATE
)
return True
| .BASE_COMMAND_MESSAGE_SCHEMA.extend(
{
vol.Required("type"): WS_TYPE_UPDATE,
vol.Required("device_id"): str,
vol.Optional("area_id"): vol.Any(str, None),
vol.Optional("name_by_user"): vol.Any(str, None),
}
)
async def async_setup(hass):
| 64 | 64 | 69 | 7 | 57 | erogleva/core | homeassistant/components/config/device_registry.py | Python | async_setup | async_setup | 28 | 36 | 28 | 28 | 12bd4b18c967a66cfbe1ca3cc60ef2c415f1ae18 | bigcode/the-stack | train |
ea1c7d5a76b37f237c093d9b | train | class | class test_cublasxt(TestCase):
@classmethod
def setUpClass(cls):
np.random.seed(0)
cls.handle = cublasxt.cublasXtCreate()
cls.nbDevices = 1
cls.deviceId = np.array([0], np.int32)
cublasxt.cublasXtDeviceSelect(cls.handle, cls.nbDevices,
... | class test_cublasxt(TestCase):
@classmethod
| def setUpClass(cls):
np.random.seed(0)
cls.handle = cublasxt.cublasXtCreate()
cls.nbDevices = 1
cls.deviceId = np.array([0], np.int32)
cublasxt.cublasXtDeviceSelect(cls.handle, cls.nbDevices,
cls.deviceId)
@classmethod
def tearDo... | #!/usr/bin/env python
"""
Unit tests for scikits.cuda.cublasxt
"""
from unittest import main, makeSuite, TestCase, TestSuite
import numpy as np
import pycuda.autoinit
import skcuda.cublasxt as cublasxt
import skcuda.misc as misc
class test_cublasxt(TestCase):
@classmethod
| 79 | 237 | 792 | 13 | 65 | Randl/scikit-cuda | tests/test_cublasxt.py | Python | test_cublasxt | test_cublasxt | 15 | 77 | 15 | 16 | 983ddb5edea21356dce0b6c02bcfcccf9423bf8c | bigcode/the-stack | train |
90d94cbc3e7bd591fafbce97 | train | function | def suite():
s = TestSuite()
s.addTest(test_cublasxt('test_cublasXtSgemm'))
s.addTest(test_cublasxt('test_cublasXtCgemm'))
if misc.get_compute_capability(pycuda.autoinit.device) >= 1.3:
s.addTest(test_cublasxt('test_cublasXtDgemm'))
s.addTest(test_cublasxt('test_cublasXtZgemm'))
retu... | def suite():
| s = TestSuite()
s.addTest(test_cublasxt('test_cublasXtSgemm'))
s.addTest(test_cublasxt('test_cublasXtCgemm'))
if misc.get_compute_capability(pycuda.autoinit.device) >= 1.3:
s.addTest(test_cublasxt('test_cublasXtDgemm'))
s.addTest(test_cublasxt('test_cublasXtZgemm'))
return s
| np.complex256(1.0),
a.ctypes.data, 4, b.ctypes.data, 4, np.complex256(0.0),
c.ctypes.data, 4)
np.allclose(np.dot(b.T, a.T).T, c)
def suite():
| 64 | 64 | 110 | 3 | 61 | Randl/scikit-cuda | tests/test_cublasxt.py | Python | suite | suite | 79 | 86 | 79 | 79 | 51dc91712b24df9a2dc4cea15177b91d40d8a794 | bigcode/the-stack | train |
0140cd94839386f42c9eff0f | train | class | class LitterRobotPropertySensor(LitterRobotEntity, SensorEntity):
"""Litter-Robot property sensor."""
def __init__(
self, robot: Robot, entity_type: str, hub: LitterRobotHub, sensor_attribute: str
) -> None:
"""Pass robot, entity_type and hub to LitterRobotEntity."""
super().__init_... | class LitterRobotPropertySensor(LitterRobotEntity, SensorEntity):
| """Litter-Robot property sensor."""
def __init__(
self, robot: Robot, entity_type: str, hub: LitterRobotHub, sensor_attribute: str
) -> None:
"""Pass robot, entity_type and hub to LitterRobotEntity."""
super().__init__(robot, entity_type, hub)
self.sensor_attribute = sensor_... | return "mdi:gauge-empty"
if gauge_level > 70 + offset:
return "mdi:gauge-full"
if gauge_level > 30 + offset:
return "mdi:gauge"
return "mdi:gauge-low"
class LitterRobotPropertySensor(LitterRobotEntity, SensorEntity):
| 64 | 64 | 124 | 14 | 50 | MrDelik/core | homeassistant/components/litterrobot/sensor.py | Python | LitterRobotPropertySensor | LitterRobotPropertySensor | 30 | 43 | 30 | 30 | 1e071be8edb27533e90e894de320776de854b12c | bigcode/the-stack | train |
6596b79bc376bf0149ffae48 | train | class | class LitterRobotWasteSensor(LitterRobotPropertySensor):
"""Litter-Robot waste sensor."""
@property
def native_unit_of_measurement(self) -> str:
"""Return unit of measurement."""
return PERCENTAGE
@property
def icon(self) -> str:
"""Return the icon to use in the frontend, i... | class LitterRobotWasteSensor(LitterRobotPropertySensor):
| """Litter-Robot waste sensor."""
@property
def native_unit_of_measurement(self) -> str:
"""Return unit of measurement."""
return PERCENTAGE
@property
def icon(self) -> str:
"""Return the icon to use in the frontend, if any."""
return icon_for_gauge_level(self.state,... | super().__init__(robot, entity_type, hub)
self.sensor_attribute = sensor_attribute
@property
def native_value(self) -> StateType | datetime:
"""Return the state."""
return getattr(self.robot, self.sensor_attribute)
class LitterRobotWasteSensor(LitterRobotPropertySensor):
| 64 | 64 | 89 | 12 | 52 | MrDelik/core | homeassistant/components/litterrobot/sensor.py | Python | LitterRobotWasteSensor | LitterRobotWasteSensor | 46 | 57 | 46 | 46 | 7480d4e2a30c4f67dee1372f67913eb06d74e46f | bigcode/the-stack | train |
694c2f2f2e7f4f6e0548df73 | train | class | class LitterRobotSleepTimeSensor(LitterRobotPropertySensor):
"""Litter-Robot sleep time sensor."""
@property
def native_value(self) -> StateType | datetime:
"""Return the state."""
if self.robot.sleep_mode_enabled:
return super().native_value
return None
@property
... | class LitterRobotSleepTimeSensor(LitterRobotPropertySensor):
| """Litter-Robot sleep time sensor."""
@property
def native_value(self) -> StateType | datetime:
"""Return the state."""
if self.robot.sleep_mode_enabled:
return super().native_value
return None
@property
def device_class(self) -> str:
"""Return the devic... | """Return unit of measurement."""
return PERCENTAGE
@property
def icon(self) -> str:
"""Return the icon to use in the frontend, if any."""
return icon_for_gauge_level(self.state, 10)
class LitterRobotSleepTimeSensor(LitterRobotPropertySensor):
| 64 | 64 | 95 | 13 | 51 | MrDelik/core | homeassistant/components/litterrobot/sensor.py | Python | LitterRobotSleepTimeSensor | LitterRobotSleepTimeSensor | 60 | 73 | 60 | 60 | 65f3d3220cbcb956efad29d8411e81cc60a30d23 | bigcode/the-stack | train |
516bad06864b88ff98ef4adf | train | function | def icon_for_gauge_level(gauge_level: int | None = None, offset: int = 0) -> str:
"""Return a gauge icon valid identifier."""
if gauge_level is None or gauge_level <= 0 + offset:
return "mdi:gauge-empty"
if gauge_level > 70 + offset:
return "mdi:gauge-full"
if gauge_level > 30 + offset:
... | def icon_for_gauge_level(gauge_level: int | None = None, offset: int = 0) -> str:
| """Return a gauge icon valid identifier."""
if gauge_level is None or gauge_level <= 0 + offset:
return "mdi:gauge-empty"
if gauge_level > 70 + offset:
return "mdi:gauge-full"
if gauge_level > 30 + offset:
return "mdi:gauge"
return "mdi:gauge-low"
| HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .entity import LitterRobotEntity
from .hub import LitterRobotHub
def icon_for_gauge_level(gauge_level: int | None = None, offset: int = 0) -> str:
| 64 | 64 | 101 | 26 | 37 | MrDelik/core | homeassistant/components/litterrobot/sensor.py | Python | icon_for_gauge_level | icon_for_gauge_level | 19 | 27 | 19 | 19 | c160059d6dc71bb30a42aeec513698f8250c4949 | bigcode/the-stack | train |
20d6492b76a111821f5ae462 | train | function | async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Litter-Robot sensors using config entry."""
hub: LitterRobotHub = hass.data[DOMAIN][entry.entry_id]
entities = []
for robot in hub.account.robots:
for ... | async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
| """Set up Litter-Robot sensors using config entry."""
hub: LitterRobotHub = hass.data[DOMAIN][entry.entry_id]
entities = []
for robot in hub.account.robots:
for (sensor_class, entity_type, sensor_attribute) in ROBOT_SENSORS:
entities.append(
sensor_class(
... | Sleep Mode Start Time", "sleep_mode_start_time"),
(LitterRobotSleepTimeSensor, "Sleep Mode End Time", "sleep_mode_end_time"),
]
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
| 64 | 64 | 136 | 31 | 33 | MrDelik/core | homeassistant/components/litterrobot/sensor.py | Python | async_setup_entry | async_setup_entry | 83 | 103 | 83 | 87 | d1a5017f7bd272c67bd30fd3b5ef670b188024cd | bigcode/the-stack | train |
6567366b0301d84093b035bb | train | class | class ProductAttributeFilter(Filter):
field_class = AttributeField
def filter(self, qs, value):
if isinstance(value, Lookup):
value = value.value
if not value:
return qs.distinct() if self.distinct else qs
attributes = ProductAttribute.objects.prefetch_related(... | class ProductAttributeFilter(Filter):
| field_class = AttributeField
def filter(self, qs, value):
if isinstance(value, Lookup):
value = value.value
if not value:
return qs.distinct() if self.distinct else qs
attributes = ProductAttribute.objects.prefetch_related('values')
attributes_map = {
... | import functools
import operator
from collections import defaultdict
from django.db.models import Q
from django_filters import OrderingFilter
from django_filters.fields import Lookup
from graphene_django.filter.filterset import Filter
from ...product.filters import SORT_BY_FIELDS
from ...product.models import Product... | 84 | 99 | 332 | 6 | 77 | TysonRV/saleor | saleor/graphql/product/filters.py | Python | ProductAttributeFilter | ProductAttributeFilter | 16 | 51 | 16 | 16 | d6173c326c68eb4e1a623d6537a0c2027ddfea95 | bigcode/the-stack | train |
d49b4429670f39f83cf875f0 | train | class | class ProductFilterSet(DistinctFilterSet):
sort_by = OrderingFilter(
fields=SORT_BY_FIELDS.keys(), field_labels=SORT_BY_FIELDS)
class Meta:
model = Product
fields = {
'category': ['exact'],
'price': ['exact', 'range', 'lte', 'gte'],
'attributes': ['ex... | class ProductFilterSet(DistinctFilterSet):
| sort_by = OrderingFilter(
fields=SORT_BY_FIELDS.keys(), field_labels=SORT_BY_FIELDS)
class Meta:
model = Product
fields = {
'category': ['exact'],
'price': ['exact', 'range', 'lte', 'gte'],
'attributes': ['exact'],
'name': ['exact', 'icont... | % (key, ): v}) for v in values])
for key, values in queries.items()]
query = functools.reduce(operator.and_, combine_and)
qs = self.get_method(qs)(query)
return qs.distinct() if self.distinct else qs
class ProductFilterSet(DistinctFilterSet):
| 66 | 66 | 223 | 10 | 55 | TysonRV/saleor | saleor/graphql/product/filters.py | Python | ProductFilterSet | ProductFilterSet | 54 | 78 | 54 | 54 | c5bce558aa5b09fa4bc47c884aba8622ebe46c2d | bigcode/the-stack | train |
856f7bd55317964fb14f47e3 | train | class | class NotebookFinder(object):
"""Module finder that locates Jupyter Notebooks"""
def __init__(self):
self.loaders = {}
def find_module(self, fullname, path=None):
nb_path = find_notebook(fullname, path)
if not nb_path:
return
key = path
if path:
... | class NotebookFinder(object):
| """Module finder that locates Jupyter Notebooks"""
def __init__(self):
self.loaders = {}
def find_module(self, fullname, path=None):
nb_path = find_notebook(fullname, path)
if not nb_path:
return
key = path
if path:
# lists aren't hashable
... | code':
# transform the input to executable Python
code = self.shell.input_transformer_manager.transform_cell(cell.source)
# run the code in themodule
exec(code, mod.__dict__)
finally:
self.shell.user_ns = save_user_ns
return mod... | 64 | 64 | 114 | 5 | 58 | neo-pan/RL_notebook | Ipynb_importer.py | Python | NotebookFinder | NotebookFinder | 67 | 84 | 67 | 67 | 5f12c95c024fba6a592a3d5dbe01704d8ac97e81 | bigcode/the-stack | train |
f6fd22e89f1078732a33bfe0 | train | function | def find_notebook(fullname, path=None):
"""find a notebook, given its fully qualified name and an optional path
This turns "foo.bar" into "foo/bar.ipynb"
and tries turning "Foo_Bar" into "Foo Bar" if Foo_Bar
does not exist.
"""
name = fullname.rsplit('.', 1)[-1]
if not path:
path = ... | def find_notebook(fullname, path=None):
| """find a notebook, given its fully qualified name and an optional path
This turns "foo.bar" into "foo/bar.ipynb"
and tries turning "Foo_Bar" into "Foo Bar" if Foo_Bar
does not exist.
"""
name = fullname.rsplit('.', 1)[-1]
if not path:
path = ['']
for d in path:
nb_path ... | import io, os, sys, types
from IPython import get_ipython
from nbformat import read
from IPython.core.interactiveshell import InteractiveShell
def find_notebook(fullname, path=None):
| 45 | 64 | 163 | 10 | 34 | neo-pan/RL_notebook | Ipynb_importer.py | Python | find_notebook | find_notebook | 6 | 23 | 6 | 6 | a4c8cd0122f5d3b9c57148057ed4be9a28c8e35b | bigcode/the-stack | train |
0106e8845c81794688e06d6c | train | class | class NotebookLoader(object):
"""Module Loader for Jupyter Notebooks"""
def __init__(self, path=None):
self.shell = InteractiveShell.instance()
self.path = path
def load_module(self, fullname):
"""import a notebook as a module"""
path = find_notebook(fullname, self.path)
... | class NotebookLoader(object):
| """Module Loader for Jupyter Notebooks"""
def __init__(self, path=None):
self.shell = InteractiveShell.instance()
self.path = path
def load_module(self, fullname):
"""import a notebook as a module"""
path = find_notebook(fullname, self.path)
print ("importing Jupyte... | 1)[-1]
if not path:
path = ['']
for d in path:
nb_path = os.path.join(d, name + ".ipynb")
if os.path.isfile(nb_path):
return nb_path
# let import Notebook_Name find "Notebook Name.ipynb"
nb_path = nb_path.replace("_", " ")
if os.path.isfile(nb_path):
... | 94 | 94 | 316 | 5 | 88 | neo-pan/RL_notebook | Ipynb_importer.py | Python | NotebookLoader | NotebookLoader | 25 | 65 | 25 | 25 | ab69af89ecbfeb17b1f7f12eae47a5ad1c34c811 | bigcode/the-stack | train |
2bce63c3ba1296658970c32b | train | class | class AppSettings:
"""
A settings object. It defines access to the BMA API using API key or
access token and other setting parameters.
"""
def __init__(self, defaults=None):
self.defaults = defaults or {}
for attr, value in self.defaults.items():
setattr(self, attr, val... | class AppSettings:
| """
A settings object. It defines access to the BMA API using API key or
access token and other setting parameters.
"""
def __init__(self, defaults=None):
self.defaults = defaults or {}
for attr, value in self.defaults.items():
setattr(self, attr, value)
| 'BMA_ACCESS_TOKEN': '',
'BMA_API_CLASS': None,
'BMA_API_HOST': '',
'BMA_API_KEY': '',
'BMA_API_PROTOCOL': '',
'IGNORE_BMA_REQUEST_CACHE': False,
'TIME_ZONE': TIME_ZONE,
}
class AppSettings:
| 64 | 64 | 69 | 4 | 60 | bpptkg/komapy | komapy/settings.py | Python | AppSettings | AppSettings | 18 | 28 | 18 | 18 | d4f3e09bd4c2dd5c5725347c16ec7a4dda0458d3 | bigcode/the-stack | train |
f6e28b6ad6807b9768bea82d | train | class | class TestConfig(unittest.TestCase):
@staticmethod
def _createConfig():
c = config.Config("A: b\nB:\n C: d")
return c
def test_direct(self):
c = self._createConfig()
self.assertEqual(c["A"], 'b')
self.assertRaises(KeyError, lambda: c['f'])
def test_get(self):
... | class TestConfig(unittest.TestCase):
@staticmethod
| def _createConfig():
c = config.Config("A: b\nB:\n C: d")
return c
def test_direct(self):
c = self._createConfig()
self.assertEqual(c["A"], 'b')
self.assertRaises(KeyError, lambda: c['f'])
def test_get(self):
c = self._createConfig()
self.assertEqua... | import unittest
import os
import config
class TestConfig(unittest.TestCase):
@staticmethod
| 20 | 64 | 143 | 11 | 8 | frankE/postfix-helper | tests/test_config.py | Python | TestConfig | TestConfig | 6 | 24 | 6 | 7 | 42a6e66d473c0d12110f11263763b52418432c7b | bigcode/the-stack | train |
331d7657d48cf2b73504b4dc | train | class | class TestFilesConfig(unittest.TestCase):
CONFIG = """
filesystem:
files:
a: /A/B/testabs
b: testmap
c: testdefault
pathes:
default: /C/D
b: /E/F
file-path-map:
b: b
"""
CONFIG_2 = """
filesystem:
... | class TestFilesConfig(unittest.TestCase):
| CONFIG = """
filesystem:
files:
a: /A/B/testabs
b: testmap
c: testdefault
pathes:
default: /C/D
b: /E/F
file-path-map:
b: b
"""
CONFIG_2 = """
filesystem:
files:
a: nodefault
... | import unittest
import os
import config
class TestConfig(unittest.TestCase):
@staticmethod
def _createConfig():
c = config.Config("A: b\nB:\n C: d")
return c
def test_direct(self):
c = self._createConfig()
self.assertEqual(c["A"], 'b')
self.assertRaises(KeyError, ... | 160 | 161 | 538 | 8 | 152 | frankE/postfix-helper | tests/test_config.py | Python | TestFilesConfig | TestFilesConfig | 27 | 112 | 27 | 27 | 88a00438c3924c06a76f7d4e63f4b61a68001856 | bigcode/the-stack | train |
8b6ebbbb31080d8281d7f7c7 | train | class | @mock.patch('swift.common.middleware.crypto.crypto_utils.Crypto.create_iv',
lambda *args: FAKE_IV)
class TestEncrypter(unittest.TestCase):
def setUp(self):
self.app = FakeSwift()
self.encrypter = encrypter.Encrypter(self.app, {})
self.encrypter.logger = debug_logger()
def _v... | @mock.patch('swift.common.middleware.crypto.crypto_utils.Crypto.create_iv',
lambda *args: FAKE_IV)
class TestEncrypter(unittest.TestCase):
| def setUp(self):
self.app = FakeSwift()
self.encrypter = encrypter.Encrypter(self.app, {})
self.encrypter.logger = debug_logger()
def _verify_user_metadata(self, req_hdrs, name, value, key):
# verify encrypted version of user metadata
self.assertNotIn('X-Object-Meta-' + ... | or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import base64
import hashlib
import h... | 256 | 256 | 10,737 | 33 | 222 | 10088/swift | test/unit/common/middleware/crypto/test_encrypter.py | Python | TestEncrypter | TestEncrypter | 40 | 1,023 | 40 | 42 | 568e6d44aa695295cc252be62699e668435e49ec | bigcode/the-stack | train |
c677f9cdbffb3e53e4051b19 | train | class | class Solution:
def summaryRanges(self, nums: List[int]) -> List[str]:
if len(nums) == 0:
return []
nums.append(99999999999)
res = []
pre = 0
start = 0
for i, n in enumerate(nums):
if i == 0:
start = n
else:
... | class Solution:
| def summaryRanges(self, nums: List[int]) -> List[str]:
if len(nums) == 0:
return []
nums.append(99999999999)
res = []
pre = 0
start = 0
for i, n in enumerate(nums):
if i == 0:
start = n
else:
if pre +... | class Solution:
| 3 | 64 | 132 | 3 | 0 | OhYee/code-questions | leetcode/228/228.py | Python | Solution | Solution | 1 | 21 | 1 | 1 | f7e402da16324b616094cdba95afebb2e74039d8 | bigcode/the-stack | train |
4098835ebfe5c54e5cf177dd | train | class | class OptPtrTarget(Nonterm):
def reduce_empty(self, *kids):
self.val = None
def reduce_PtrTarget(self, *kids):
self.val = kids[0].val
| class OptPtrTarget(Nonterm):
| def reduce_empty(self, *kids):
self.val = None
def reduce_PtrTarget(self, *kids):
self.val = kids[0].val
| SetAnnotation,
ConcreteConstraintBlock,
ConcreteConstraintShort,
)
class PtrTarget(Nonterm):
def reduce_ARROW_FullTypeExpr(self, *kids):
self.val = kids[1].val
self.context = kids[1].val.context
class OptPtrTarget(Nonterm):
| 64 | 64 | 44 | 8 | 55 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | OptPtrTarget | OptPtrTarget | 535 | 541 | 535 | 536 | ada4869074318984d0becb8f84a2f36e430da2f8 | bigcode/the-stack | train |
9c3c377b4fe7c82c9f466c67 | train | class | class IndexDeclarationShort(Nonterm):
def reduce_INDEX_OnExpr(self, *kids):
self.val = qlast.CreateIndex(
name=qlast.ObjectRef(name='idx'),
expr=kids[1].val,
)
| class IndexDeclarationShort(Nonterm):
| def reduce_INDEX_OnExpr(self, *kids):
self.val = qlast.CreateIndex(
name=qlast.ObjectRef(name='idx'),
expr=kids[1].val,
)
| def reduce_INDEX_OnExpr_CreateIndexSDLCommandsBlock(self, *kids):
self.val = qlast.CreateIndex(
name=qlast.ObjectRef(name='idx'),
expr=kids[1].val,
commands=kids[2].val,
)
class IndexDeclarationShort(Nonterm):
| 64 | 64 | 50 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | IndexDeclarationShort | IndexDeclarationShort | 487 | 492 | 487 | 487 | 062c5b34c5fa21009414a3e4330dbbfdc953ec38 | bigcode/the-stack | train |
6fb5423cbe8cbe6fa69f0362 | train | class | class AnnotationDeclarationShort(Nonterm):
def reduce_CreateAnnotation(self, *kids):
r"""%reduce ABSTRACT ANNOTATION ShortNodeName OptExtendingSimple"""
self.val = qlast.CreateAnnotation(
is_abstract=True,
name=kids[2].val,
bases=kids[3].val,
inheritab... | class AnnotationDeclarationShort(Nonterm):
| def reduce_CreateAnnotation(self, *kids):
r"""%reduce ABSTRACT ANNOTATION ShortNodeName OptExtendingSimple"""
self.val = qlast.CreateAnnotation(
is_abstract=True,
name=kids[2].val,
bases=kids[3].val,
inheritable=False,
)
def reduce_CreateI... | endingSimple CreateSDLCommandsBlock"""
self.val = qlast.CreateAnnotation(
is_abstract=True,
name=kids[3].val,
bases=kids[4].val,
inheritable=True,
commands=kids[4].val,
)
class AnnotationDeclarationShort(Nonterm):
| 64 | 64 | 151 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | AnnotationDeclarationShort | AnnotationDeclarationShort | 449 | 467 | 449 | 449 | d3f9438694f4096225ae3c1e71c5859dbae73344 | bigcode/the-stack | train |
f8465aeb79e8974ab67915bd | train | class | class ConcretePropertyShort(Nonterm):
def reduce_CreateRegularProperty(self, *kids):
"""%reduce
PROPERTY ShortNodeName OptExtendingSimple PtrTarget
"""
self.val = qlast.CreateConcreteProperty(
name=kids[1].val,
bases=kids[2].val,
target=kids[3]... | class ConcretePropertyShort(Nonterm):
| def reduce_CreateRegularProperty(self, *kids):
"""%reduce
PROPERTY ShortNodeName OptExtendingSimple PtrTarget
"""
self.val = qlast.CreateConcreteProperty(
name=kids[1].val,
bases=kids[2].val,
target=kids[3].val,
)
def reduce_Create... | loadedProperty(self, *kids):
"""%reduce
OVERLOADED OptPtrQuals PROPERTY ShortNodeName OptExtendingSimple
OptPtrTarget CreateConcretePropertySDLCommandsBlock
"""
self.val = qlast.CreateConcreteProperty(
name=kids[3].val,
bases=kids[4].val,
... | 127 | 127 | 425 | 8 | 119 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ConcretePropertyShort | ConcretePropertyShort | 587 | 642 | 587 | 587 | 9fa4c5027790ab5ad39ab9b2b4d56808374b4164 | bigcode/the-stack | train |
0d7a496942b3e8c25c013330 | train | class | class ConcreteConstraintShort(Nonterm):
def reduce_CreateConstraint(self, *kids):
r"""%reduce CONSTRAINT \
NodeName OptConcreteConstraintArgList OptOnExpr"""
self.val = qlast.CreateConcreteConstraint(
name=kids[1].val,
args=kids[2].val,
subject... | class ConcreteConstraintShort(Nonterm):
| def reduce_CreateConstraint(self, *kids):
r"""%reduce CONSTRAINT \
NodeName OptConcreteConstraintArgList OptOnExpr"""
self.val = qlast.CreateConcreteConstraint(
name=kids[1].val,
args=kids[2].val,
subjectexpr=kids[3].val,
)
def red... | CommandsBlock"""
self.val = qlast.CreateConcreteConstraint(
delegated=True,
name=kids[2].val,
args=kids[3].val,
subjectexpr=kids[4].val,
commands=kids[5].val,
)
class ConcreteConstraintShort(Nonterm):
| 64 | 64 | 157 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ConcreteConstraintShort | ConcreteConstraintShort | 317 | 335 | 317 | 317 | 09e82b0bce10da3e6af9d52af661e0988db9d3cc | bigcode/the-stack | train |
04e0986e79e942b345efc07f | train | class | class SetField(Nonterm):
# field := <expr>
def reduce_ShortNodeName_ASSIGN_Expr(self, *kids):
self.val = qlast.SetField(name=kids[0].val, value=kids[2].val)
| class SetField(Nonterm):
# field := <expr>
| def reduce_ShortNodeName_ASSIGN_Expr(self, *kids):
self.val = qlast.SetField(name=kids[0].val, value=kids[2].val)
| ._singleton_list
clsdict[f'reduce_{cmd_b.__name__}'] = \
SDLProductionHelper._singleton_list
_new_nonterm(parent + 'SingleSDLCommandBlock', clsdict=clsdict)
class SetField(Nonterm):
# field := <expr>
| 64 | 64 | 53 | 14 | 50 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | SetField | SetField | 227 | 230 | 227 | 228 | 24b9368a6e8615668ec89ad7b5ccae62a8de345a | bigcode/the-stack | train |
8386ab11ea441ba4ba52831f | train | function | def sdl_commands_block(parent, *commands, opt=True):
if parent is None:
parent = ''
# SDLCommand := SDLCommand1 | SDLCommand2 ...
#
# All the "short" commands, ones that need a ";" are gathered as
# SDLCommandShort.
#
# All the "block" commands, ones that have a "{...}" and don't
... | def sdl_commands_block(parent, *commands, opt=True):
| if parent is None:
parent = ''
# SDLCommand := SDLCommand1 | SDLCommand2 ...
#
# All the "short" commands, ones that need a ";" are gathered as
# SDLCommandShort.
#
# All the "block" commands, ones that have a "{...}" and don't
# need a ";" are gathered as SDLCommandBlock.
c... | Identifier(self, *kids):
self.val = qlast.ImportModule(module=kids[0].val,
alias=kids[2].val)
class ImportModuleList(ListNonterm, element=ImportModule,
separator=tokens.T_COMMA):
pass
class SDLProductionHelper:
def _passthrough(self, *cmds... | 216 | 216 | 723 | 13 | 203 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | sdl_commands_block | sdl_commands_block | 159 | 224 | 159 | 159 | eb2e9dff55f353124a7d143eb92ae47d643c1e7e | bigcode/the-stack | train |
a29a0413ac61ec299f674657 | train | class | class FunctionDeclaration(Nonterm, commondl.ProcessFunctionBlockMixin):
def reduce_CreateFunction(self, *kids):
r"""%reduce FUNCTION ShortNodeName CreateFunctionArgs \
ARROW OptTypeQualifier FunctionType \
CreateFunctionSDLCommandsBlock
"""
self.val = qlast.Cr... | class FunctionDeclaration(Nonterm, commondl.ProcessFunctionBlockMixin):
| def reduce_CreateFunction(self, *kids):
r"""%reduce FUNCTION ShortNodeName CreateFunctionArgs \
ARROW OptTypeQualifier FunctionType \
CreateFunctionSDLCommandsBlock
"""
self.val = qlast.CreateFunction(
name=kids[1].val,
params=kids[2].v... | val,
commands=kids[2].val,
)
#
# Functions
#
sdl_commands_block(
'CreateFunction',
commondl.FromFunction,
SetField,
SetAnnotation,
opt=False
)
class FunctionDeclaration(Nonterm, commondl.ProcessFunctionBlockMixin):
| 64 | 64 | 118 | 15 | 49 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | FunctionDeclaration | FunctionDeclaration | 938 | 950 | 938 | 938 | c0840c404d5428e1fb3a778905740ffb962687b0 | bigcode/the-stack | train |
d2dd7db1816ac914a5ae6623 | train | class | class ImportModule(Nonterm):
def reduce_DotName(self, *kids):
self.val = qlast.ImportModule(module=kids[0].val)
def reduce_DotName_AS_AnyIdentifier(self, *kids):
self.val = qlast.ImportModule(module=kids[0].val,
alias=kids[2].val)
| class ImportModule(Nonterm):
| def reduce_DotName(self, *kids):
self.val = qlast.ImportModule(module=kids[0].val)
def reduce_DotName_AS_AnyIdentifier(self, *kids):
self.val = qlast.ImportModule(module=kids[0].val,
alias=kids[2].val)
| val
def reduce_FunctionDeclarationShort(self, *kids):
self.val = kids[0].val
class DotName(Nonterm):
def reduce_ModuleName(self, *kids):
self.val = '.'.join(part for part in kids[0].val)
class ImportModule(Nonterm):
| 64 | 64 | 74 | 7 | 57 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ImportModule | ImportModule | 125 | 131 | 125 | 125 | 64691ce6b606109ce4775c5bd69417e9249fd10b | bigcode/the-stack | train |
e411829dace083ae8f4de084 | train | class | class ConcreteLinkBlock(Nonterm):
def _validate(self):
on_target_delete = None
for cmd in self.val.commands:
if isinstance(cmd, qlast.OnTargetDelete):
if on_target_delete:
raise errors.EdgeQLSyntaxError(
f"more than one 'on targ... | class ConcreteLinkBlock(Nonterm):
| def _validate(self):
on_target_delete = None
for cmd in self.val.commands:
if isinstance(cmd, qlast.OnTargetDelete):
if on_target_delete:
raise errors.EdgeQLSyntaxError(
f"more than one 'on target delete' specification",
... | ].val,
)
class LinkDeclarationShort(Nonterm):
def reduce_CreateLink(self, *kids):
r"""%reduce \
ABSTRACT LINK ShortNodeName OptExtendingSimple"""
self.val = qlast.CreateLink(
name=kids[2].val,
bases=kids[3].val,
)
sdl_commands_block(
'Creat... | 126 | 126 | 421 | 8 | 118 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ConcreteLinkBlock | ConcreteLinkBlock | 697 | 751 | 697 | 697 | ef5e7a829238668be7620f2938280382c071ab1b | bigcode/the-stack | train |
56f526fb44cba6d173271513 | train | class | class ObjectTypeDeclarationShort(Nonterm):
def reduce_CreateAbstractObjectTypeStmt(self, *kids):
r"""%reduce \
ABSTRACT TYPE ShortNodeName OptExtendingSimple"""
self.val = qlast.CreateObjectType(
is_abstract=True,
name=kids[2].val,
bases=kids[3].val,
... | class ObjectTypeDeclarationShort(Nonterm):
| def reduce_CreateAbstractObjectTypeStmt(self, *kids):
r"""%reduce \
ABSTRACT TYPE ShortNodeName OptExtendingSimple"""
self.val = qlast.CreateObjectType(
is_abstract=True,
name=kids[2].val,
bases=kids[3].val,
)
def reduce_CreateRegularObjec... | Name OptExtendingSimple \
CreateObjectTypeSDLCommandsBlock \
"""
self.val = qlast.CreateObjectType(
name=kids[1].val,
bases=kids[2].val,
commands=kids[3].val,
)
class ObjectTypeDeclarationShort(Nonterm):
| 64 | 64 | 134 | 9 | 55 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ObjectTypeDeclarationShort | ObjectTypeDeclarationShort | 857 | 873 | 857 | 857 | b61a211f8ea7fd4a83092b656ba0415abd4c5ebd | bigcode/the-stack | train |
ef7fc1eebc27035317bae5a3 | train | class | class LinkDeclarationShort(Nonterm):
def reduce_CreateLink(self, *kids):
r"""%reduce \
ABSTRACT LINK ShortNodeName OptExtendingSimple"""
self.val = qlast.CreateLink(
name=kids[2].val,
bases=kids[3].val,
)
| class LinkDeclarationShort(Nonterm):
| def reduce_CreateLink(self, *kids):
r"""%reduce \
ABSTRACT LINK ShortNodeName OptExtendingSimple"""
self.val = qlast.CreateLink(
name=kids[2].val,
bases=kids[3].val,
)
| LINK ShortNodeName OptExtendingSimple \
CreateLinkSDLCommandsBlock \
"""
self.val = qlast.CreateLink(
name=kids[2].val,
bases=kids[3].val,
commands=kids[4].val,
)
class LinkDeclarationShort(Nonterm):
| 64 | 64 | 64 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | LinkDeclarationShort | LinkDeclarationShort | 675 | 682 | 675 | 675 | e4a0e6a89528f7372968afce04b8511cf3fbaa9a | bigcode/the-stack | train |
0ec204473675eefd89e1420d | train | class | class FunctionDeclarationShort(Nonterm, commondl.ProcessFunctionBlockMixin):
def reduce_CreateFunction(self, *kids):
r"""%reduce FUNCTION ShortNodeName CreateFunctionArgs \
ARROW OptTypeQualifier FunctionType \
CreateFunctionSingleSDLCommandBlock
"""
self.val ... | class FunctionDeclarationShort(Nonterm, commondl.ProcessFunctionBlockMixin):
| def reduce_CreateFunction(self, *kids):
r"""%reduce FUNCTION ShortNodeName CreateFunctionArgs \
ARROW OptTypeQualifier FunctionType \
CreateFunctionSingleSDLCommandBlock
"""
self.val = qlast.CreateFunction(
name=kids[1].val,
params=kids... | 1].val,
params=kids[2].val,
returning=kids[5].val,
returning_typemod=kids[4].val,
**self._process_function_body(kids[6]),
)
class FunctionDeclarationShort(Nonterm, commondl.ProcessFunctionBlockMixin):
| 64 | 64 | 120 | 16 | 48 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | FunctionDeclarationShort | FunctionDeclarationShort | 953 | 965 | 953 | 953 | fc557b953dd069fc16be96bb7cdffd1bc84e8128 | bigcode/the-stack | train |
32437e4c090f367c250c0450 | train | class | class AnnotationDeclaration(Nonterm):
def reduce_CreateAnnotation(self, *kids):
r"""%reduce ABSTRACT ANNOTATION ShortNodeName OptExtendingSimple \
CreateSDLCommandsBlock"""
self.val = qlast.CreateAnnotation(
is_abstract=True,
name=kids[2].val,
... | class AnnotationDeclaration(Nonterm):
| def reduce_CreateAnnotation(self, *kids):
r"""%reduce ABSTRACT ANNOTATION ShortNodeName OptExtendingSimple \
CreateSDLCommandsBlock"""
self.val = qlast.CreateAnnotation(
is_abstract=True,
name=kids[2].val,
bases=kids[3].val,
inherit... | r"""%reduce \
SCALAR TYPE ShortNodeName \
OptExtending \
"""
self.val = qlast.CreateScalarType(
name=kids[2].val,
bases=kids[3].val,
)
#
# Annotations
#
class AnnotationDeclaration(Nonterm):
| 64 | 64 | 178 | 7 | 57 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | AnnotationDeclaration | AnnotationDeclaration | 425 | 446 | 425 | 425 | 43e935de392795cf955ed28682e8405912e211a5 | bigcode/the-stack | train |
9f67ad3ffb07399e71af9214 | train | class | class SDLBlockStatement(Nonterm):
def reduce_ScalarTypeDeclaration(self, *kids):
self.val = kids[0].val
def reduce_AnnotationDeclaration(self, *kids):
self.val = kids[0].val
def reduce_ObjectTypeDeclaration(self, *kids):
self.val = kids[0].val
def reduce_ViewDeclaration(self, ... | class SDLBlockStatement(Nonterm):
| def reduce_ScalarTypeDeclaration(self, *kids):
self.val = kids[0].val
def reduce_AnnotationDeclaration(self, *kids):
self.val = kids[0].val
def reduce_ObjectTypeDeclaration(self, *kids):
self.val = kids[0].val
def reduce_ViewDeclaration(self, *kids):
self.val = kids[0]... | , *kids):
self.val = kids[0].val
# a list of SDL statements with optional semicolon separators
class SDLStatements(ListNonterm, element=SDLStatement,
separator=OptSemicolons):
pass
# These statements have a block
class SDLBlockStatement(Nonterm):
| 64 | 64 | 173 | 8 | 55 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | SDLBlockStatement | SDLBlockStatement | 61 | 84 | 61 | 61 | 9b17cd862c5bcadefbcdb5f0e105c2f833746661 | bigcode/the-stack | train |
5c3b07c48fa4789bbaef6589 | train | class | class ScalarTypeDeclaration(Nonterm):
def reduce_CreateAbstractScalarTypeStmt(self, *kids):
r"""%reduce \
ABSTRACT SCALAR TYPE ShortNodeName \
OptExtending CreateScalarTypeSDLCommandsBlock \
"""
self.val = qlast.CreateScalarType(
is_abstract=True,
... | class ScalarTypeDeclaration(Nonterm):
| def reduce_CreateAbstractScalarTypeStmt(self, *kids):
r"""%reduce \
ABSTRACT SCALAR TYPE ShortNodeName \
OptExtending CreateScalarTypeSDLCommandsBlock \
"""
self.val = qlast.CreateScalarType(
is_abstract=True,
name=kids[3].val,
base... | delegated=True,
name=kids[2].val,
args=kids[3].val,
subjectexpr=kids[4].val,
)
#
# Scalar Types
#
sdl_commands_block(
'CreateScalarType',
SetField,
SetAnnotation,
ConcreteConstraintBlock,
ConcreteConstraintShort,
)
class ScalarTypeDeclaration(Nonterm):... | 77 | 77 | 257 | 8 | 69 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ScalarTypeDeclaration | ScalarTypeDeclaration | 351 | 385 | 351 | 351 | e495ca7319405816055acdb8a5b9819cdacae197 | bigcode/the-stack | train |
b92fca4a5ab3ff5903789e63 | train | class | class ScalarTypeDeclarationShort(Nonterm):
def reduce_CreateAbstractScalarTypeStmt(self, *kids):
r"""%reduce \
ABSTRACT SCALAR TYPE ShortNodeName \
OptExtending \
"""
self.val = qlast.CreateScalarType(
is_abstract=True,
name=kids[3].val,
... | class ScalarTypeDeclarationShort(Nonterm):
| def reduce_CreateAbstractScalarTypeStmt(self, *kids):
r"""%reduce \
ABSTRACT SCALAR TYPE ShortNodeName \
OptExtending \
"""
self.val = qlast.CreateScalarType(
is_abstract=True,
name=kids[3].val,
bases=kids[4].val,
)
def... | NodeName \
OptExtending CreateScalarTypeSDLCommandsBlock \
"""
self.val = qlast.CreateScalarType(
name=kids[2].val,
bases=kids[3].val,
commands=kids[4].val,
)
class ScalarTypeDeclarationShort(Nonterm):
| 64 | 64 | 213 | 9 | 55 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ScalarTypeDeclarationShort | ScalarTypeDeclarationShort | 388 | 419 | 388 | 388 | 9620ee3a7b945f232057fc67c90521e6571eab3e | bigcode/the-stack | train |
058745c816a2b2cb563b4700 | train | class | class SDLStatements(ListNonterm, element=SDLStatement,
separator=OptSemicolons):
pass
| class SDLStatements(ListNonterm, element=SDLStatement,
separator=OptSemicolons):
| pass
| kids[0].val
def reduce_SDLShortStatement_SEMICOLON(self, *kids):
self.val = kids[0].val
# a list of SDL statements with optional semicolon separators
class SDLStatements(ListNonterm, element=SDLStatement,
separator=OptSemicolons):
| 64 | 64 | 23 | 20 | 43 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | SDLStatements | SDLStatements | 55 | 57 | 55 | 56 | 8438aef011a65f92ae0b177311c90289c3732035 | bigcode/the-stack | train |
84b0fc7afc3cf3e459f458d2 | train | class | class ConcretePropertyBlock(Nonterm):
def reduce_CreateRegularProperty(self, *kids):
"""%reduce
PROPERTY ShortNodeName OptExtendingSimple
PtrTarget CreateConcretePropertySDLCommandsBlock
"""
self.val = qlast.CreateConcreteProperty(
name=kids[1].val,
... | class ConcretePropertyBlock(Nonterm):
| def reduce_CreateRegularProperty(self, *kids):
"""%reduce
PROPERTY ShortNodeName OptExtendingSimple
PtrTarget CreateConcretePropertySDLCommandsBlock
"""
self.val = qlast.CreateConcreteProperty(
name=kids[1].val,
bases=kids[2].val,
t... | ConcreteConstraintShort,
)
class PtrTarget(Nonterm):
def reduce_ARROW_FullTypeExpr(self, *kids):
self.val = kids[1].val
self.context = kids[1].val.context
class OptPtrTarget(Nonterm):
def reduce_empty(self, *kids):
self.val = None
def reduce_PtrTarget(self, *kids):
... | 99 | 99 | 331 | 8 | 90 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ConcretePropertyBlock | ConcretePropertyBlock | 544 | 584 | 544 | 544 | ab3b61ac0577a6501a68e5fe5d8cb219468d8a80 | bigcode/the-stack | train |
8d157369f3e5b6a51a432f98 | train | class | class ImportModuleList(ListNonterm, element=ImportModule,
separator=tokens.T_COMMA):
pass
| class ImportModuleList(ListNonterm, element=ImportModule,
separator=tokens.T_COMMA):
| pass
| ].val)
def reduce_DotName_AS_AnyIdentifier(self, *kids):
self.val = qlast.ImportModule(module=kids[0].val,
alias=kids[2].val)
class ImportModuleList(ListNonterm, element=ImportModule,
separator=tokens.T_COMMA):
| 64 | 64 | 24 | 21 | 43 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ImportModuleList | ImportModuleList | 134 | 136 | 134 | 135 | 396361139f3c1197a8e5b3cb412cb061a706ecdd | bigcode/the-stack | train |
8cc9798ef8fffc2aa6735d81 | train | class | class LinkDeclaration(Nonterm):
def reduce_CreateLink(self, *kids):
r"""%reduce \
ABSTRACT LINK ShortNodeName OptExtendingSimple \
CreateLinkSDLCommandsBlock \
"""
self.val = qlast.CreateLink(
name=kids[2].val,
bases=kids[3].val,
co... | class LinkDeclaration(Nonterm):
| def reduce_CreateLink(self, *kids):
r"""%reduce \
ABSTRACT LINK ShortNodeName OptExtendingSimple \
CreateLinkSDLCommandsBlock \
"""
self.val = qlast.CreateLink(
name=kids[2].val,
bases=kids[3].val,
commands=kids[4].val,
)
| ,
)
#
# Links
#
sdl_commands_block(
'CreateLink',
SetField,
SetAnnotation,
ConcreteConstraintBlock,
ConcreteConstraintShort,
ConcretePropertyBlock,
ConcretePropertyShort,
IndexDeclarationBlock,
IndexDeclarationShort,
)
class LinkDeclaration(Nonterm):
| 64 | 64 | 81 | 7 | 57 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | LinkDeclaration | LinkDeclaration | 662 | 672 | 662 | 662 | 85f7425c799bacb866200078fd0ff7ca9bdd1b2f | bigcode/the-stack | train |
c205b0c1abf1dfd6d49d851e | train | class | class ObjectTypeDeclaration(Nonterm):
def reduce_CreateAbstractObjectTypeStmt(self, *kids):
r"""%reduce \
ABSTRACT TYPE ShortNodeName OptExtendingSimple \
CreateObjectTypeSDLCommandsBlock \
"""
self.val = qlast.CreateObjectType(
is_abstract=True,
... | class ObjectTypeDeclaration(Nonterm):
| def reduce_CreateAbstractObjectTypeStmt(self, *kids):
r"""%reduce \
ABSTRACT TYPE ShortNodeName OptExtendingSimple \
CreateObjectTypeSDLCommandsBlock \
"""
self.val = qlast.CreateObjectType(
is_abstract=True,
name=kids[2].val,
bases... | #
# Object Types
#
sdl_commands_block(
'CreateObjectType',
SetField,
SetAnnotation,
ConcretePropertyBlock,
ConcretePropertyShort,
ConcreteLinkBlock,
ConcreteLinkShort,
IndexDeclarationBlock,
IndexDeclarationShort,
)
class ObjectTypeDeclaration(Nonterm):
| 64 | 64 | 171 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ObjectTypeDeclaration | ObjectTypeDeclaration | 832 | 854 | 832 | 832 | 9feb5908d9ab0388e6bcfed29df482976bd51a37 | bigcode/the-stack | train |
2d79836bf4573c83247ead4c | train | class | class SDLStatement(Nonterm):
def reduce_SDLBlockStatement(self, *kids):
self.val = kids[0].val
def reduce_SDLShortStatement_SEMICOLON(self, *kids):
self.val = kids[0].val
| class SDLStatement(Nonterm):
| def reduce_SDLBlockStatement(self, *kids):
self.val = kids[0].val
def reduce_SDLShortStatement_SEMICOLON(self, *kids):
self.val = kids[0].val
| = commondl.OptSemicolons
ListNonterm = parsing.ListNonterm
sdl_nontem_helper = commondl.NewNontermHelper(__name__)
_new_nonterm = sdl_nontem_helper._new_nonterm
# top-level SDL statements
class SDLStatement(Nonterm):
| 64 | 64 | 55 | 7 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | SDLStatement | SDLStatement | 46 | 51 | 46 | 46 | 1180233caaae97b63388c2647f837dd264a435e0 | bigcode/the-stack | train |
fb25743678db856db9e2e8a2 | train | class | class DotName(Nonterm):
def reduce_ModuleName(self, *kids):
self.val = '.'.join(part for part in kids[0].val)
| class DotName(Nonterm):
| def reduce_ModuleName(self, *kids):
self.val = '.'.join(part for part in kids[0].val)
| (self, *kids):
self.val = kids[0].val
def reduce_PropertyDeclarationShort(self, *kids):
self.val = kids[0].val
def reduce_FunctionDeclarationShort(self, *kids):
self.val = kids[0].val
class DotName(Nonterm):
| 64 | 64 | 34 | 7 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | DotName | DotName | 120 | 122 | 120 | 120 | 039ba13201f21c7afe8705f7e9dbaef240d93ad5 | bigcode/the-stack | train |
9e6dce8ce8a8b472d68ddbbf | train | class | class ConstraintDeclarationShort(Nonterm):
def reduce_CreateConstraint(self, *kids):
r"""%reduce ABSTRACT CONSTRAINT ShortNodeName OptOnExpr \
OptExtendingSimple"""
self.val = qlast.CreateConstraint(
name=kids[2].val,
subject=kids[3].val,
exten... | class ConstraintDeclarationShort(Nonterm):
| def reduce_CreateConstraint(self, *kids):
r"""%reduce ABSTRACT CONSTRAINT ShortNodeName OptOnExpr \
OptExtendingSimple"""
self.val = qlast.CreateConstraint(
name=kids[2].val,
subject=kids[3].val,
extends=kids[4].val,
)
def reduce_C... | self.val = qlast.CreateConstraint(
name=kids[2].val,
params=kids[3].val,
subjectexpr=kids[4].val,
bases=kids[5].val,
commands=kids[6].val,
)
class ConstraintDeclarationShort(Nonterm):
| 64 | 64 | 161 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ConstraintDeclarationShort | ConstraintDeclarationShort | 271 | 289 | 271 | 271 | 2868e9c78891c0a9ecd4ef839ad7249a2b7d4e62 | bigcode/the-stack | train |
81aa354c0c1c6d418c9e9545 | train | class | class ConcreteConstraintBlock(Nonterm):
def reduce_CreateConstraint(self, *kids):
r"""%reduce CONSTRAINT \
NodeName OptConcreteConstraintArgList OptOnExpr \
CreateSDLCommandsBlock"""
self.val = qlast.CreateConcreteConstraint(
name=kids[1].val,
... | class ConcreteConstraintBlock(Nonterm):
| def reduce_CreateConstraint(self, *kids):
r"""%reduce CONSTRAINT \
NodeName OptConcreteConstraintArgList OptOnExpr \
CreateSDLCommandsBlock"""
self.val = qlast.CreateConcreteConstraint(
name=kids[1].val,
args=kids[2].val,
su... | OptOnExpr OptExtendingSimple"""
self.val = qlast.CreateConstraint(
name=kids[2].val,
params=kids[3].val,
subject=kids[4].val,
extends=kids[5].val,
)
class ConcreteConstraintBlock(Nonterm):
| 64 | 64 | 187 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ConcreteConstraintBlock | ConcreteConstraintBlock | 292 | 314 | 292 | 292 | b53092bc7272f1f47d74972fd788143ed8c046d0 | bigcode/the-stack | train |
74578b021b7be6c057cbcd0e | train | class | class SetAnnotation(Nonterm):
def reduce_ANNOTATION_ShortNodeName_ASSIGN_Expr(self, *kids):
self.val = qlast.CreateAnnotationValue(
name=kids[1].val, value=kids[3].val)
| class SetAnnotation(Nonterm):
| def reduce_ANNOTATION_ShortNodeName_ASSIGN_Expr(self, *kids):
self.val = qlast.CreateAnnotationValue(
name=kids[1].val, value=kids[3].val)
| clsdict)
class SetField(Nonterm):
# field := <expr>
def reduce_ShortNodeName_ASSIGN_Expr(self, *kids):
self.val = qlast.SetField(name=kids[0].val, value=kids[2].val)
class SetAnnotation(Nonterm):
| 64 | 64 | 52 | 7 | 57 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | SetAnnotation | SetAnnotation | 233 | 236 | 233 | 233 | 57147495002729bbdf70c5c703bf407a87835f27 | bigcode/the-stack | train |
10038ce392a8311df5c19c26 | train | class | class ViewDeclarationShort(Nonterm):
def reduce_CreateViewShortStmt(self, *kids):
r"""%reduce \
VIEW ShortNodeName ASSIGN Expr \
"""
self.val = qlast.CreateView(
name=kids[1].val,
commands=[
qlast.SetField(
name=qlast.Ob... | class ViewDeclarationShort(Nonterm):
| def reduce_CreateViewShortStmt(self, *kids):
r"""%reduce \
VIEW ShortNodeName ASSIGN Expr \
"""
self.val = qlast.CreateView(
name=kids[1].val,
commands=[
qlast.SetField(
name=qlast.ObjectRef(name='expr'),
... | ViewRegularStmt(self, *kids):
r"""%reduce \
VIEW ShortNodeName CreateViewSDLCommandsBlock \
"""
self.val = qlast.CreateView(
name=kids[1].val,
commands=kids[2].val,
)
class ViewDeclarationShort(Nonterm):
| 64 | 64 | 151 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ViewDeclarationShort | ViewDeclarationShort | 899 | 921 | 899 | 899 | d490a8f22f647f819956ce09b402687746ebb1ba | bigcode/the-stack | train |
ced4a4ff3a4e52cd21b35244 | train | class | class PropertyDeclarationShort(Nonterm):
def reduce_CreateProperty(self, *kids):
r"""%reduce ABSTRACT PROPERTY ShortNodeName OptExtendingSimple"""
self.val = qlast.CreateProperty(
name=kids[2].val,
bases=kids[3].val,
)
| class PropertyDeclarationShort(Nonterm):
| def reduce_CreateProperty(self, *kids):
r"""%reduce ABSTRACT PROPERTY ShortNodeName OptExtendingSimple"""
self.val = qlast.CreateProperty(
name=kids[2].val,
bases=kids[3].val,
)
| ABSTRACT PROPERTY ShortNodeName OptExtendingSimple \
CreateSDLCommandsBlock \
"""
self.val = qlast.CreateProperty(
name=kids[2].val,
bases=kids[3].val,
commands=kids[4].val,
)
class PropertyDeclarationShort(Nonterm):
| 64 | 64 | 62 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | PropertyDeclarationShort | PropertyDeclarationShort | 510 | 516 | 510 | 510 | a857f3dbe4ef75ac872e02b7b67238d13c21784c | bigcode/the-stack | train |
37beb78ed545c79493b380be | train | class | class ConcreteLinkShort(Nonterm):
def reduce_CreateRegularLink(self, *kids):
"""%reduce
LINK ShortNodeName OptExtendingSimple
PtrTarget
"""
self.val = qlast.CreateConcreteLink(
name=kids[1].val,
bases=kids[2].val,
target=kids[3].va... | class ConcreteLinkShort(Nonterm):
| def reduce_CreateRegularLink(self, *kids):
"""%reduce
LINK ShortNodeName OptExtendingSimple
PtrTarget
"""
self.val = qlast.CreateConcreteLink(
name=kids[1].val,
bases=kids[2].val,
target=kids[3].val,
)
def reduce_Create... | *kids):
"""%reduce
OVERLOADED OptPtrQuals LINK ShortNodeName OptExtendingSimple
OptPtrTarget CreateConcreteLinkSDLCommandsBlock
"""
self.val = qlast.CreateConcreteLink(
is_required=kids[1].val.required,
cardinality=kids[1].val.cardinality,
... | 128 | 128 | 429 | 8 | 120 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ConcreteLinkShort | ConcreteLinkShort | 754 | 812 | 754 | 755 | 22f2d0d6a32af0ecdd626abb7ab6569089398261 | bigcode/the-stack | train |
b15557ece111f8be4d80675f | train | class | class SDLShortStatement(Nonterm):
def reduce_IMPORT_ImportModuleList(self, *kids):
self.val = qlast.Import(modules=kids[1].val)
def reduce_IMPORT_LPAREN_ImportModuleList_RPAREN(self, *kids):
self.val = qlast.Import(modules=kids[2].val)
def reduce_ScalarTypeDeclarationShort(self, *kids):
... | class SDLShortStatement(Nonterm):
| def reduce_IMPORT_ImportModuleList(self, *kids):
self.val = qlast.Import(modules=kids[1].val)
def reduce_IMPORT_LPAREN_ImportModuleList_RPAREN(self, *kids):
self.val = qlast.Import(modules=kids[2].val)
def reduce_ScalarTypeDeclarationShort(self, *kids):
self.val = kids[0].val
... | _LinkDeclaration(self, *kids):
self.val = kids[0].val
def reduce_PropertyDeclaration(self, *kids):
self.val = kids[0].val
def reduce_FunctionDeclaration(self, *kids):
self.val = kids[0].val
# these statements have no {} block
class SDLShortStatement(Nonterm):
| 73 | 73 | 245 | 8 | 64 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | SDLShortStatement | SDLShortStatement | 88 | 117 | 88 | 88 | 0264b9f6d390d11e35023f3a81c5e57ce3227768 | bigcode/the-stack | train |
34b15d53e96d47febd533293 | train | class | class ViewDeclaration(Nonterm):
def reduce_CreateViewRegularStmt(self, *kids):
r"""%reduce \
VIEW ShortNodeName CreateViewSDLCommandsBlock \
"""
self.val = qlast.CreateView(
name=kids[1].val,
commands=kids[2].val,
)
| class ViewDeclaration(Nonterm):
| def reduce_CreateViewRegularStmt(self, *kids):
r"""%reduce \
VIEW ShortNodeName CreateViewSDLCommandsBlock \
"""
self.val = qlast.CreateView(
name=kids[1].val,
commands=kids[2].val,
)
| self.val = qlast.CreateObjectType(
name=kids[1].val,
bases=kids[2].val,
)
#
# Views
#
sdl_commands_block(
'CreateView',
SetField,
SetAnnotation,
opt=False
)
class ViewDeclaration(Nonterm):
| 64 | 64 | 67 | 7 | 57 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ViewDeclaration | ViewDeclaration | 888 | 896 | 888 | 888 | edb958ffc3157fbe1ee52b3cf569b2d2ba8e037d | bigcode/the-stack | train |
6cb9b6a087fe28c0e76ab8f8 | train | class | class ConstraintDeclaration(Nonterm):
def reduce_CreateConstraint(self, *kids):
r"""%reduce ABSTRACT CONSTRAINT ShortNodeName OptOnExpr \
OptExtendingSimple CreateSDLCommandsBlock"""
self.val = qlast.CreateConstraint(
name=kids[2].val,
subjectexpr=kids[3].... | class ConstraintDeclaration(Nonterm):
| def reduce_CreateConstraint(self, *kids):
r"""%reduce ABSTRACT CONSTRAINT ShortNodeName OptOnExpr \
OptExtendingSimple CreateSDLCommandsBlock"""
self.val = qlast.CreateConstraint(
name=kids[2].val,
subjectexpr=kids[3].val,
bases=kids[4].val,
... | _ASSIGN_Expr(self, *kids):
self.val = qlast.CreateAnnotationValue(
name=kids[1].val, value=kids[3].val)
sdl_commands_block(
'Create',
SetField,
SetAnnotation)
#
# Constraints
#
class ConstraintDeclaration(Nonterm):
| 64 | 64 | 188 | 7 | 57 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | ConstraintDeclaration | ConstraintDeclaration | 248 | 268 | 248 | 248 | f9795362d8faa81ead7555c6f314369a6f198038 | bigcode/the-stack | train |
783c25f2ffc3ac31dcf07d27 | train | class | class PropertyDeclaration(Nonterm):
def reduce_CreateProperty(self, *kids):
r"""%reduce ABSTRACT PROPERTY ShortNodeName OptExtendingSimple \
CreateSDLCommandsBlock \
"""
self.val = qlast.CreateProperty(
name=kids[2].val,
bases=kids[3].val,
... | class PropertyDeclaration(Nonterm):
| def reduce_CreateProperty(self, *kids):
r"""%reduce ABSTRACT PROPERTY ShortNodeName OptExtendingSimple \
CreateSDLCommandsBlock \
"""
self.val = qlast.CreateProperty(
name=kids[2].val,
bases=kids[3].val,
commands=kids[4].val,
)
| )
class IndexDeclarationShort(Nonterm):
def reduce_INDEX_OnExpr(self, *kids):
self.val = qlast.CreateIndex(
name=qlast.ObjectRef(name='idx'),
expr=kids[1].val,
)
#
# Properties
#
class PropertyDeclaration(Nonterm):
| 64 | 64 | 78 | 7 | 57 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | PropertyDeclaration | PropertyDeclaration | 498 | 507 | 498 | 498 | 5660875f4eab60b312a23d055715f1b65fcdd751 | bigcode/the-stack | train |
bbf5fe67a78920d2e294b864 | train | class | class PtrTarget(Nonterm):
def reduce_ARROW_FullTypeExpr(self, *kids):
self.val = kids[1].val
self.context = kids[1].val.context
| class PtrTarget(Nonterm):
| def reduce_ARROW_FullTypeExpr(self, *kids):
self.val = kids[1].val
self.context = kids[1].val.context
| .val = qlast.CreateProperty(
name=kids[2].val,
bases=kids[3].val,
)
sdl_commands_block(
'CreateConcreteProperty',
SetField,
SetAnnotation,
ConcreteConstraintBlock,
ConcreteConstraintShort,
)
class PtrTarget(Nonterm):
| 64 | 64 | 41 | 7 | 57 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | PtrTarget | PtrTarget | 528 | 532 | 528 | 529 | 282859b1d411a2bce55e9f7684cf8f6a9ca86445 | bigcode/the-stack | train |
cfed8a5899f6435e47fd3011 | train | class | class IndexDeclarationBlock(Nonterm):
def reduce_INDEX_OnExpr_CreateIndexSDLCommandsBlock(self, *kids):
self.val = qlast.CreateIndex(
name=qlast.ObjectRef(name='idx'),
expr=kids[1].val,
commands=kids[2].val,
)
| class IndexDeclarationBlock(Nonterm):
| def reduce_INDEX_OnExpr_CreateIndexSDLCommandsBlock(self, *kids):
self.val = qlast.CreateIndex(
name=qlast.ObjectRef(name='idx'),
expr=kids[1].val,
commands=kids[2].val,
)
| qlast.CreateAnnotation(
is_abstract=True,
name=kids[3].val,
bases=kids[4].val,
inheritable=True,
)
#
# Indexes
#
sdl_commands_block(
'CreateIndex',
SetAnnotation)
class IndexDeclarationBlock(Nonterm):
| 64 | 64 | 64 | 8 | 56 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | IndexDeclarationBlock | IndexDeclarationBlock | 478 | 484 | 478 | 478 | 0369bae68994ca2782de387d34ae249d360362a3 | bigcode/the-stack | train |
1d66b74563245c6985bb26d5 | train | class | class SDLProductionHelper:
def _passthrough(self, *cmds):
self.val = cmds[0].val
def _singleton_list(self, cmd):
self.val = [cmd.val]
def _empty(self):
self.val = []
def _block(self, lbrace, sc1, cmdl, rbrace):
self.val = [cmdl.val]
def _block2(self, lbrace, sc1, ... | class SDLProductionHelper:
| def _passthrough(self, *cmds):
self.val = cmds[0].val
def _singleton_list(self, cmd):
self.val = [cmd.val]
def _empty(self):
self.val = []
def _block(self, lbrace, sc1, cmdl, rbrace):
self.val = [cmdl.val]
def _block2(self, lbrace, sc1, cmdlist, sc2, rbrace):
... | Name_AS_AnyIdentifier(self, *kids):
self.val = qlast.ImportModule(module=kids[0].val,
alias=kids[2].val)
class ImportModuleList(ListNonterm, element=ImportModule,
separator=tokens.T_COMMA):
pass
class SDLProductionHelper:
| 64 | 64 | 148 | 5 | 58 | tailhook/edgedb | edb/edgeql/parser/grammar/sdl.py | Python | SDLProductionHelper | SDLProductionHelper | 139 | 156 | 139 | 139 | 94ef7c7e50369dc25fa06fc3499259666f22640d | bigcode/the-stack | train |
45b85190266638021bfb8673 | train | function | def make_path(*p):
return os.path.realpath(os.path.normpath(os.path.expanduser(os.path.join(*p))))
| def make_path(*p):
| return os.path.realpath(os.path.normpath(os.path.expanduser(os.path.join(*p))))
| try:
return rcall(("base", ".packages"), **{"all.available": True, "_convert": True})
except Exception:
return []
def source_file(path):
rcall(("base", "source"), path, rcall(("base", "new.env")))
def make_path(*p):
| 63 | 64 | 26 | 6 | 57 | gvelasq/radian | radian/rutils.py | Python | make_path | make_path | 41 | 42 | 41 | 41 | 5bdc0a3aacd05f91cc837a1cb0993c641d9927e3 | bigcode/the-stack | train |
79aa72a6613aeca735f1e7a1 | train | function | def package_is_loaded(pkg):
return pkg in rcopy(rcall(("base", "loadedNamespaces")))
| def package_is_loaded(pkg):
| return pkg in rcopy(rcall(("base", "loadedNamespaces")))
| orig_stderr = sys.stderr
sys.stderr = None
with protected(s), suppress_stderr():
lib.R_ParseVector(s, -1, status, lib.R_NilValue)
sys.stderr = orig_stderr
return status[0] != 2
def package_is_loaded(pkg):
| 64 | 64 | 21 | 6 | 57 | gvelasq/radian | radian/rutils.py | Python | package_is_loaded | package_is_loaded | 22 | 23 | 22 | 22 | 2b5281fab7212b6955425e0a6efb7ca52e9683a8 | bigcode/the-stack | train |
f4c337f02bbdb9a32324d21a | train | function | def package_is_installed(pkg):
return pkg in installed_packages()
| def package_is_installed(pkg):
| return pkg in installed_packages()
| lib.R_ParseVector(s, -1, status, lib.R_NilValue)
sys.stderr = orig_stderr
return status[0] != 2
def package_is_loaded(pkg):
return pkg in rcopy(rcall(("base", "loadedNamespaces")))
def package_is_installed(pkg):
| 63 | 64 | 14 | 7 | 56 | gvelasq/radian | radian/rutils.py | Python | package_is_installed | package_is_installed | 26 | 27 | 26 | 26 | 7b5a2ad7fdd83e47421cc50369646a956a181ebc | bigcode/the-stack | train |
8ca148087caf0327f4465f1c | train | function | def load_custom_key_bindings(*args):
esc_keymap = roption("radian.escape_key_map", [])
for m in esc_keymap:
map_key(("escape", m["key"]), m["value"], mode=m["mode"] if "mode" in m else "r")
| def load_custom_key_bindings(*args):
| esc_keymap = roption("radian.escape_key_map", [])
for m in esc_keymap:
map_key(("escape", m["key"]), m["value"], mode=m["mode"] if "mode" in m else "r")
| ("win"):
# for backward compatibility
global_profile = user_path(".radian_profile")
if os.path.exists(global_profile):
source_file(global_profile)
if os.path.exists(local_profile) and local_profile != global_profile:
source_file(local_profile)
def... | 64 | 64 | 61 | 9 | 55 | gvelasq/radian | radian/rutils.py | Python | load_custom_key_bindings | load_custom_key_bindings | 80 | 83 | 80 | 80 | 7c7188a1a76e0ffbea4f3239f5d382c0919014ab | bigcode/the-stack | train |
528d112a87359a2aa8a40b57 | train | function | def prase_text_complete(text):
status = ffi.new("ParseStatus[1]")
s = rstring_p(text)
orig_stderr = sys.stderr
sys.stderr = None
with protected(s), suppress_stderr():
lib.R_ParseVector(s, -1, status, lib.R_NilValue)
sys.stderr = orig_stderr
return status[0] != 2
| def prase_text_complete(text):
| status = ffi.new("ParseStatus[1]")
s = rstring_p(text)
orig_stderr = sys.stderr
sys.stderr = None
with protected(s), suppress_stderr():
lib.R_ParseVector(s, -1, status, lib.R_NilValue)
sys.stderr = orig_stderr
return status[0] != 2
| sys
from rchitect import rcopy, rcall
from rchitect._cffi import ffi, lib
from rchitect.interface import roption, protected, rstring_p
from .key_bindings import map_key
from .console import suppress_stderr
def prase_text_complete(text):
| 64 | 64 | 85 | 7 | 56 | gvelasq/radian | radian/rutils.py | Python | prase_text_complete | prase_text_complete | 11 | 19 | 11 | 11 | e3882b0a3831475c78518a517fb454d346ded39f | bigcode/the-stack | train |
92246edcd7de49eca47cea9d | train | function | def installed_packages():
try:
return rcall(("base", ".packages"), **{"all.available": True, "_convert": True})
except Exception:
return []
| def installed_packages():
| try:
return rcall(("base", ".packages"), **{"all.available": True, "_convert": True})
except Exception:
return []
| lib.R_NilValue)
sys.stderr = orig_stderr
return status[0] != 2
def package_is_loaded(pkg):
return pkg in rcopy(rcall(("base", "loadedNamespaces")))
def package_is_installed(pkg):
return pkg in installed_packages()
def installed_packages():
| 64 | 64 | 36 | 4 | 60 | gvelasq/radian | radian/rutils.py | Python | installed_packages | installed_packages | 30 | 34 | 30 | 30 | cfc8e0c493126ece568fe1be9c9045001ea23316 | bigcode/the-stack | train |
a81f43d489680f8f4d2a75cc | train | function | def register_cleanup(cleanup):
rcall(("base", "reg.finalizer"),
rcall(("base", "getOption"), "rchitect.py_tools"),
cleanup,
onexit=True)
| def register_cleanup(cleanup):
| rcall(("base", "reg.finalizer"),
rcall(("base", "getOption"), "rchitect.py_tools"),
cleanup,
onexit=True)
| _key_bindings(*args):
esc_keymap = roption("radian.escape_key_map", [])
for m in esc_keymap:
map_key(("escape", m["key"]), m["value"], mode=m["mode"] if "mode" in m else "r")
def register_cleanup(cleanup):
| 64 | 64 | 41 | 6 | 58 | gvelasq/radian | radian/rutils.py | Python | register_cleanup | register_cleanup | 86 | 90 | 86 | 86 | c73212e78915604f295f7e8028ad6e4f32b3f150 | bigcode/the-stack | train |
c9355820af695c713a4d27d2 | train | function | def user_path(*args):
return make_path(rcopy(rcall(("base", "path.expand"), "~")), *args)
| def user_path(*args):
| return make_path(rcopy(rcall(("base", "path.expand"), "~")), *args)
| :
return []
def source_file(path):
rcall(("base", "source"), path, rcall(("base", "new.env")))
def make_path(*p):
return os.path.realpath(os.path.normpath(os.path.expanduser(os.path.join(*p))))
def user_path(*args):
| 63 | 64 | 26 | 6 | 57 | gvelasq/radian | radian/rutils.py | Python | user_path | user_path | 45 | 46 | 45 | 45 | 072671ee8adabd0d6591949f67e47f791fc3a209 | bigcode/the-stack | train |
eaa65b2e2a7604996fcb1399 | train | function | def run_on_load_hooks():
hooks = roption("radian.on_load_hooks", [])
for hook in hooks:
hook()
| def run_on_load_hooks():
| hooks = roption("radian.on_load_hooks", [])
for hook in hooks:
hook()
| value"], mode=m["mode"] if "mode" in m else "r")
def register_cleanup(cleanup):
rcall(("base", "reg.finalizer"),
rcall(("base", "getOption"), "rchitect.py_tools"),
cleanup,
onexit=True)
def run_on_load_hooks():
| 64 | 64 | 28 | 6 | 58 | gvelasq/radian | radian/rutils.py | Python | run_on_load_hooks | run_on_load_hooks | 93 | 96 | 93 | 93 | daa395177acc96ec8cac3df399456773773609e4 | bigcode/the-stack | train |
20a279ec495d756b41107f2b | train | function | def source_file(path):
rcall(("base", "source"), path, rcall(("base", "new.env")))
| def source_file(path):
| rcall(("base", "source"), path, rcall(("base", "new.env")))
| (("base", "loadedNamespaces")))
def package_is_installed(pkg):
return pkg in installed_packages()
def installed_packages():
try:
return rcall(("base", ".packages"), **{"all.available": True, "_convert": True})
except Exception:
return []
def source_file(path):
| 63 | 64 | 25 | 5 | 58 | gvelasq/radian | radian/rutils.py | Python | source_file | source_file | 37 | 38 | 37 | 37 | 46b521821501e9efe174f9a522ce463f652857e4 | bigcode/the-stack | train |
cd9c02bfd8c74d7867b25292 | train | function | def source_radian_profile(path):
if path:
path = os.path.expanduser(path)
if os.path.exists(path):
source_file(path)
else:
if "XDG_CONFIG_HOME" in os.environ:
xdg_profile = make_path(os.environ["XDG_CONFIG_HOME"], "radian", "profile")
elif not sys.platform... | def source_radian_profile(path):
| if path:
path = os.path.expanduser(path)
if os.path.exists(path):
source_file(path)
else:
if "XDG_CONFIG_HOME" in os.environ:
xdg_profile = make_path(os.environ["XDG_CONFIG_HOME"], "radian", "profile")
elif not sys.platform.startswith("win"):
x... | call(("base", "new.env")))
def make_path(*p):
return os.path.realpath(os.path.normpath(os.path.expanduser(os.path.join(*p))))
def user_path(*args):
return make_path(rcopy(rcall(("base", "path.expand"), "~")), *args)
def source_radian_profile(path):
| 69 | 69 | 233 | 7 | 62 | gvelasq/radian | radian/rutils.py | Python | source_radian_profile | source_radian_profile | 49 | 77 | 49 | 49 | 5e0df0a0eccbfd37fe9506c5c8431e81b8b7fa72 | bigcode/the-stack | train |
ec1a47242bbede78fc88cf18 | train | function | def verify(img1_path, img2_path=''
, model_name ='VGG-Face', distance_metric = 'cosine', model = None, enforce_detection = True):
tic = time.time()
if type(img1_path) == list:
bulkProcess = True
img_list = img1_path.copy()
else:
bulkProcess = False
img_list = [[img1_path, img2_path]]
#------------------... | def verify(img1_path, img2_path=''
, model_name ='VGG-Face', distance_metric = 'cosine', model = None, enforce_detection = True):
| tic = time.time()
if type(img1_path) == list:
bulkProcess = True
img_list = img1_path.copy()
else:
bulkProcess = False
img_list = [[img1_path, img2_path]]
#------------------------------
if model == None:
if model_name == 'VGG-Face':
print("Using VGG-Face model backend and", distance_metric,"distan... | from keras.preprocessing import image
import warnings
warnings.filterwarnings("ignore")
import time
import os
import numpy as np
import pandas as pd
from tqdm import tqdm
import json
import cv2
from keras import backend as K
import keras
import tensorflow as tf
#from basemodels import VGGFace, OpenFace, Facenet, FbDee... | 187 | 256 | 920 | 36 | 150 | omrylcn/deepface | deepface/DeepFace.py | Python | verify | verify | 23 | 155 | 23 | 25 | e8b66d51a41770852b6e5005c31aa8f7156713bb | bigcode/the-stack | train |
8eda243e54a4187d3d4de0c3 | train | function | def analyze(img_path, actions = [], models = {}, enforce_detection = True):
if type(img_path) == list:
img_paths = img_path.copy()
bulkProcess = True
else:
img_paths = [img_path]
bulkProcess = False
#---------------------------------
#if a specific target is not passed, then find them all
if len(actions... | def analyze(img_path, actions = [], models = {}, enforce_detection = True):
| if type(img_path) == list:
img_paths = img_path.copy()
bulkProcess = True
else:
img_paths = [img_path]
bulkProcess = False
#---------------------------------
#if a specific target is not passed, then find them all
if len(actions) == 0:
actions= ['emotion', 'age', 'gender', 'race']
print("Actions to d... | distance\": "+str(distance)
resp_obj += ", \"max_threshold_to_verify\": "+str(threshold)
resp_obj += ", \"model\": \""+model_name+"\""
resp_obj += ", \"similarity_metric\": \""+distance_metric+"\""
resp_obj += "}"
resp_obj = json.loads(resp_obj) #string to json
if bulkProcess == True:
resp_objec... | 256 | 256 | 1,245 | 16 | 239 | omrylcn/deepface | deepface/DeepFace.py | Python | analyze | analyze | 159 | 322 | 159 | 160 | e248043d5abc64a23840aa48f089648ac5603f6f | bigcode/the-stack | train |
cec6bbed3890af66310d53f2 | train | function | def stream(db_path = '', model_name ='VGG-Face', distance_metric = 'cosine', enable_face_analysis = True):
realtime.analysis(db_path, model_name, distance_metric, enable_face_analysis)
| def stream(db_path = '', model_name ='VGG-Face', distance_metric = 'cosine', enable_face_analysis = True):
| realtime.analysis(db_path, model_name, distance_metric, enable_face_analysis)
| .detectFace(img_path)[0] #detectFace returns (1, 224, 224, 3)
return img[:, :, ::-1] #bgr to rgb
def stream(db_path = '', model_name ='VGG-Face', distance_metric = 'cosine', enable_face_analysis = True):
| 64 | 64 | 43 | 27 | 36 | omrylcn/deepface | deepface/DeepFace.py | Python | stream | stream | 331 | 332 | 331 | 331 | ff9eacecbdd7ccbc10d22fa347471bfe429e7ab8 | bigcode/the-stack | train |
30764d7aa5d1728c0130c67f | train | function | def detectFace(img_path):
img = functions.detectFace(img_path)[0] #detectFace returns (1, 224, 224, 3)
return img[:, :, ::-1] #bgr to rgb
| def detectFace(img_path):
| img = functions.detectFace(img_path)[0] #detectFace returns (1, 224, 224, 3)
return img[:, :, ::-1] #bgr to rgb
| ])
if i > 0:
resp_obj += ", "
resp_obj += "\"instance_"+str(i+1)+"\": "+resp_item
resp_obj += "}"
resp_obj = json.loads(resp_obj)
return resp_obj
#return resp_objects
def detectFace(img_path):
| 64 | 64 | 46 | 6 | 57 | omrylcn/deepface | deepface/DeepFace.py | Python | detectFace | detectFace | 326 | 328 | 326 | 326 | dc19dd069b67fdca5b181326c4e7a63d5bd5b15a | bigcode/the-stack | train |
b3d52195f663b9045b68a4b9 | train | function | def allocateMemory():
print("Analyzing your system...")
functions.allocateMemory()
| def allocateMemory():
| print("Analyzing your system...")
functions.allocateMemory()
| 3)
return img[:, :, ::-1] #bgr to rgb
def stream(db_path = '', model_name ='VGG-Face', distance_metric = 'cosine', enable_face_analysis = True):
realtime.analysis(db_path, model_name, distance_metric, enable_face_analysis)
def allocateMemory():
| 64 | 64 | 16 | 4 | 60 | omrylcn/deepface | deepface/DeepFace.py | Python | allocateMemory | allocateMemory | 334 | 336 | 334 | 334 | db1a064488ca0e2e13a4f6927f4c24247da18dd2 | bigcode/the-stack | train |
3249582a8756fc2a890590d4 | train | function | def _dnsmasq_pid_for(dev):
"""Returns the pid for prior dnsmasq instance for a bridge/device.
Returns None if no pid file exists.
If machine has rebooted pid might be incorrect (caller should check).
"""
pid_file = _dhcp_file(dev, 'pid')
if os.path.exists(pid_file):
try:
... | def _dnsmasq_pid_for(dev):
| """Returns the pid for prior dnsmasq instance for a bridge/device.
Returns None if no pid file exists.
If machine has rebooted pid might be incorrect (caller should check).
"""
pid_file = _dhcp_file(dev, 'pid')
if os.path.exists(pid_file):
try:
with open(pid_file, 'r') as... | ):
"""Return path to a pid or conf file for a bridge/device."""
fileutils.ensure_tree(CONF.networks_path)
return os.path.abspath('%s/nova-ra-%s.%s' % (CONF.networks_path,
dev,
kind))
def _dnsmasq_pid_for(dev):
| 64 | 64 | 105 | 9 | 55 | bopopescu/nested_quota | nova/network/linux_net.py | Python | _dnsmasq_pid_for | _dnsmasq_pid_for | 1,252 | 1,267 | 1,252 | 1,252 | 774c3f83cf739dc90519665d149493c51c1d09ef | bigcode/the-stack | train |
0df5033de7106cb523b5f54c | train | function | def bind_floating_ip(floating_ip, device):
"""Bind ip to public interface."""
_execute('ip', 'addr', 'add', str(floating_ip) + '/32',
'dev', device,
run_as_root=True, check_exit_code=[0, 2, 254])
if CONF.send_arp_for_ha and CONF.send_arp_for_ha_count > 0:
send_arp_for_ip(f... | def bind_floating_ip(floating_ip, device):
| """Bind ip to public interface."""
_execute('ip', 'addr', 'add', str(floating_ip) + '/32',
'dev', device,
run_as_root=True, check_exit_code=[0, 2, 254])
if CONF.send_arp_for_ha and CONF.send_arp_for_ha_count > 0:
send_arp_for_ip(floating_ip, device, CONF.send_arp_for_ha_co... | arping', '-U', ip,
'-A', '-I', device,
'-c', str(count),
run_as_root=True, check_exit_code=False)
if err:
LOG.debug('arping error for ip %s', ip)
def bind_floating_ip(floating_ip, device):
| 64 | 64 | 107 | 11 | 53 | bopopescu/nested_quota | nova/network/linux_net.py | Python | bind_floating_ip | bind_floating_ip | 730 | 737 | 730 | 730 | bd822a5c277d3dc562159d7efec2efd67ed59f1e | bigcode/the-stack | train |
7fa1fa694ebafcf078d1c550 | train | function | def init_host(ip_range, is_external=False):
"""Basic networking setup goes here."""
# NOTE(devcamcar): Cloud public SNAT entries and the default
# SNAT rule for outbound traffic.
add_snat_rule(ip_range, is_external)
rules = []
if is_external:
for snat_range in CONF.force_snat_range:
... | def init_host(ip_range, is_external=False):
| """Basic networking setup goes here."""
# NOTE(devcamcar): Cloud public SNAT entries and the default
# SNAT rule for outbound traffic.
add_snat_rule(ip_range, is_external)
rules = []
if is_external:
for snat_range in CONF.force_snat_range:
rules.append('PREROUTING -p ipv4 -... | -d %s -j SNAT --to-source %s'
% (ip_range, dest_range, CONF.routing_source_ip))
if not is_external and CONF.public_interface:
rule += ' -o %s' % CONF.public_interface
iptables_manager.ipv4['nat'].add_rule('snat', rule)
iptables_manager.apply()
def ini... | 86 | 86 | 289 | 10 | 76 | bopopescu/nested_quota | nova/network/linux_net.py | Python | init_host | init_host | 687 | 717 | 687 | 687 | 1e55d1110356630d088308d7465f3f32fcd31eb0 | bigcode/the-stack | train |
c88f8cbcc422c3de4f2c8788 | train | function | def ensure_vpn_forward(public_ip, port, private_ip):
"""Sets up forwarding rules for vlan."""
iptables_manager.ipv4['filter'].add_rule('FORWARD',
'-d %s -p udp '
'--dport 1194 '
... | def ensure_vpn_forward(public_ip, port, private_ip):
| """Sets up forwarding rules for vlan."""
iptables_manager.ipv4['filter'].add_rule('FORWARD',
'-d %s -p udp '
'--dport 1194 '
'-j ACCEPT' % private_ip)
iptables_manager.ipv4[... | ('ip', 'addr', 'add', '169.254.169.254/32',
'scope', 'link', 'dev', 'lo',
run_as_root=True, check_exit_code=[0, 2, 254])
def ensure_vpn_forward(public_ip, port, private_ip):
| 64 | 64 | 179 | 13 | 51 | bopopescu/nested_quota | nova/network/linux_net.py | Python | ensure_vpn_forward | ensure_vpn_forward | 754 | 768 | 754 | 754 | 6cd28d8b886ed89ecccab41aca2fbbe9589e4320 | bigcode/the-stack | train |
20c55fd3359e386ab79bb043 | train | function | def _enable_ipv4_forwarding():
sysctl_key = 'net.ipv4.ip_forward'
stdout, stderr = _execute('sysctl', '-n', sysctl_key)
if stdout.strip() is not '1':
_execute('sysctl', '-w', '%s=1' % sysctl_key, run_as_root=True)
| def _enable_ipv4_forwarding():
| sysctl_key = 'net.ipv4.ip_forward'
stdout, stderr = _execute('sysctl', '-n', sysctl_key)
if stdout.strip() is not '1':
_execute('sysctl', '-w', '%s=1' % sysctl_key, run_as_root=True)
| :
_execute('conntrack', '-D', '-r', fixed_ip, run_as_root=True,
check_exit_code=[0, 1])
except processutils.ProcessExecutionError:
LOG.exception(_('Error deleting conntrack entries for %s'), fixed_ip)
def _enable_ipv4_forwarding():
| 64 | 64 | 74 | 8 | 56 | bopopescu/nested_quota | nova/network/linux_net.py | Python | _enable_ipv4_forwarding | _enable_ipv4_forwarding | 828 | 832 | 828 | 828 | 41d433ad48f85454dad09994fab1b6dab43038b0 | bigcode/the-stack | train |
45c2c9973d3876ab8e9e45ca | train | function | def unbind_floating_ip(floating_ip, device):
"""Unbind a public ip from public interface."""
_execute('ip', 'addr', 'del', str(floating_ip) + '/32',
'dev', device,
run_as_root=True, check_exit_code=[0, 2, 254])
| def unbind_floating_ip(floating_ip, device):
| """Unbind a public ip from public interface."""
_execute('ip', 'addr', 'del', str(floating_ip) + '/32',
'dev', device,
run_as_root=True, check_exit_code=[0, 2, 254])
| =[0, 2, 254])
if CONF.send_arp_for_ha and CONF.send_arp_for_ha_count > 0:
send_arp_for_ip(floating_ip, device, CONF.send_arp_for_ha_count)
def unbind_floating_ip(floating_ip, device):
| 64 | 64 | 68 | 12 | 52 | bopopescu/nested_quota | nova/network/linux_net.py | Python | unbind_floating_ip | unbind_floating_ip | 740 | 744 | 740 | 740 | bdde1eaa29676bb2c13370573cfe5724b504df1d | bigcode/the-stack | train |
5492a44ff5210e21fc4009ca | train | function | def get_gateway_rules(bridge):
interfaces = CONF.forward_bridge_interface
if 'all' in interfaces:
return [('FORWARD', '-i %s -j ACCEPT' % bridge),
('FORWARD', '-o %s -j ACCEPT' % bridge)]
rules = []
for iface in CONF.forward_bridge_interface:
if iface:
rules.a... | def get_gateway_rules(bridge):
| interfaces = CONF.forward_bridge_interface
if 'all' in interfaces:
return [('FORWARD', '-i %s -j ACCEPT' % bridge),
('FORWARD', '-o %s -j ACCEPT' % bridge)]
rules = []
for iface in CONF.forward_bridge_interface:
if iface:
rules.append(('FORWARD', '-i %s -o %s ... | IPv4 -o %s --ip-protocol udp '
'--ip-destination-port 67:68 -j DROP'
% interface)
remove_ebtables_rules(rules)
# NOTE(vish): the above is not possible with iptables/arptables
def get_gateway_rules(bridge):
| 64 | 64 | 208 | 7 | 56 | bopopescu/nested_quota | nova/network/linux_net.py | Python | get_gateway_rules | get_gateway_rules | 1,692 | 1,709 | 1,692 | 1,692 | 19029d2509a6cf85e32d69ae64b2765e6c620606 | bigcode/the-stack | train |
e9c9554afcdc5c5021c23330 | train | class | class LinuxOVSInterfaceDriver(LinuxNetInterfaceDriver):
def plug(self, network, mac_address, gateway=True):
dev = self.get_dev(network)
if not device_exists(dev):
bridge = CONF.linuxnet_ovs_integration_bridge
_ovs_vsctl(['--', '--may-exist', 'add-port', bridge, dev,
... | class LinuxOVSInterfaceDriver(LinuxNetInterfaceDriver):
| def plug(self, network, mac_address, gateway=True):
dev = self.get_dev(network)
if not device_exists(dev):
bridge = CONF.linuxnet_ovs_integration_bridge
_ovs_vsctl(['--', '--may-exist', 'add-port', bridge, dev,
'--', 'set', 'Interface', dev, 'type=inte... | _interface:
if iface:
rules.append(('FORWARD', '-i %s -o %s -j ACCEPT' % (bridge,
iface)))
rules.append(('FORWARD', '-i %s -o %s -j ACCEPT' % (iface,
bridge)))
... | 161 | 161 | 537 | 12 | 148 | bopopescu/nested_quota | nova/network/linux_net.py | Python | LinuxOVSInterfaceDriver | LinuxOVSInterfaceDriver | 1,713 | 1,761 | 1,713 | 1,714 | f44e5caab5e486b42cc7645bc79859dc293e0bbf | bigcode/the-stack | train |
10189e0dd55940ff68b4f6fa | train | function | def unplug(network):
return _get_interface_driver().unplug(network)
| def unplug(network):
| return _get_interface_driver().unplug(network)
| _driver():
global interface_driver
if not interface_driver:
interface_driver = importutils.import_object(
CONF.linuxnet_interface_driver)
return interface_driver
def plug(network, mac_address, gateway=True):
return _get_interface_driver().plug(network, mac_address, gateway)
def... | 64 | 64 | 15 | 4 | 60 | bopopescu/nested_quota | nova/network/linux_net.py | Python | unplug | unplug | 1,406 | 1,407 | 1,406 | 1,406 | 4591faacf783231fe9a950f921fdc037a2a64860 | bigcode/the-stack | train |
6ac9c1e09736bc820984d6c2 | train | function | def get_dhcp_hosts(context, network_ref, fixedips):
"""Get network's hosts config in dhcp-host format."""
hosts = []
macs = set()
for fixedip in fixedips:
if fixedip.allocated:
if fixedip.virtual_interface.address not in macs:
hosts.append(_host_dhcp(fixedip))
... | def get_dhcp_hosts(context, network_ref, fixedips):
| """Get network's hosts config in dhcp-host format."""
hosts = []
macs = set()
for fixedip in fixedips:
if fixedip.allocated:
if fixedip.virtual_interface.address not in macs:
hosts.append(_host_dhcp(fixedip))
macs.add(fixedip.virtual_interface.address)... | host):
# NOTE(cfb): Don't return a lease entry if the IP isn't
# already leased
if fixedip.leased:
hosts.append(_host_lease(fixedip))
return '\n'.join(hosts)
def get_dhcp_hosts(context, network_ref, fixedips):
| 64 | 64 | 94 | 13 | 51 | bopopescu/nested_quota | nova/network/linux_net.py | Python | get_dhcp_hosts | get_dhcp_hosts | 908 | 917 | 908 | 908 | d59b7f11b6bf5cffc301ac6bddcf86ba95539a5c | bigcode/the-stack | train |
40153f46a39996152409b406 | train | function | def get_dhcp_opts(context, network_ref, fixedips):
"""Get network's hosts config in dhcp-opts format."""
gateway = network_ref['gateway']
# NOTE(vish): if we are in multi-host mode and we are not sharing
# addresses, then we actually need to hand out the
# dhcp server address... | def get_dhcp_opts(context, network_ref, fixedips):
| """Get network's hosts config in dhcp-opts format."""
gateway = network_ref['gateway']
# NOTE(vish): if we are in multi-host mode and we are not sharing
# addresses, then we actually need to hand out the
# dhcp server address as the gateway.
if network_ref['multi_host'] a... | v4['mangle']
table.remove_rule('POSTROUTING',
'-o %s -p udp -m udp --dport 68 -j CHECKSUM '
'--checksum-fill' % dev)
iptables_manager.apply()
def get_dhcp_opts(context, network_ref, fixedips):
| 64 | 64 | 212 | 13 | 51 | bopopescu/nested_quota | nova/network/linux_net.py | Python | get_dhcp_opts | get_dhcp_opts | 971 | 991 | 971 | 971 | 585f97c55b7d811c2c0a6943889ce7f09333eb72 | bigcode/the-stack | train |
829b82f13fd66d5451d128de | train | function | def _remove_dhcp_mangle_rule(dev):
table = iptables_manager.ipv4['mangle']
table.remove_rule('POSTROUTING',
'-o %s -p udp -m udp --dport 68 -j CHECKSUM '
'--checksum-fill' % dev)
iptables_manager.apply()
| def _remove_dhcp_mangle_rule(dev):
| table = iptables_manager.ipv4['mangle']
table.remove_rule('POSTROUTING',
'-o %s -p udp -m udp --dport 68 -j CHECKSUM '
'--checksum-fill' % dev)
iptables_manager.apply()
| tables_manager.ipv4['mangle']
table.add_rule('POSTROUTING',
'-o %s -p udp -m udp --dport 68 -j CHECKSUM '
'--checksum-fill' % dev)
iptables_manager.apply()
def _remove_dhcp_mangle_rule(dev):
| 64 | 64 | 68 | 10 | 54 | bopopescu/nested_quota | nova/network/linux_net.py | Python | _remove_dhcp_mangle_rule | _remove_dhcp_mangle_rule | 963 | 968 | 963 | 963 | e72d483a5db97c495654d3a7f9fd83ff24f39405 | bigcode/the-stack | train |
f27df259f6fb2d1e3c3d2e57 | train | function | def get_dns_hosts(context, network_ref):
"""Get network's DNS hosts in hosts format."""
hosts = []
for fixedip in objects.FixedIPList.get_by_network(context, network_ref):
if fixedip.allocated:
hosts.append(_host_dns(fixedip))
return '\n'.join(hosts)
| def get_dns_hosts(context, network_ref):
| """Get network's DNS hosts in hosts format."""
hosts = []
for fixedip in objects.FixedIPList.get_by_network(context, network_ref):
if fixedip.allocated:
hosts.append(_host_dns(fixedip))
return '\n'.join(hosts)
| ip in fixedips:
if fixedip.allocated:
if fixedip.virtual_interface.address not in macs:
hosts.append(_host_dhcp(fixedip))
macs.add(fixedip.virtual_interface.address)
return '\n'.join(hosts)
def get_dns_hosts(context, network_ref):
| 64 | 64 | 67 | 9 | 55 | bopopescu/nested_quota | nova/network/linux_net.py | Python | get_dns_hosts | get_dns_hosts | 920 | 926 | 920 | 920 | 7209dfa737b27aefc4c3fa3f28f056a7a48b3f2d | bigcode/the-stack | train |
e42e5af0efcd1cb82e5a641a | train | function | def ensure_floating_forward(floating_ip, fixed_ip, device, network):
"""Ensure floating ip forwarding rule."""
# NOTE(vish): Make sure we never have duplicate rules for the same ip
regex = '.*\s+%s(/32|\s+|$)' % floating_ip
num_rules = iptables_manager.ipv4['nat'].remove_rules_regex(regex)
if num_ru... | def ensure_floating_forward(floating_ip, fixed_ip, device, network):
| """Ensure floating ip forwarding rule."""
# NOTE(vish): Make sure we never have duplicate rules for the same ip
regex = '.*\s+%s(/32|\s+|$)' % floating_ip
num_rules = iptables_manager.ipv4['nat'].remove_rules_regex(regex)
if num_rules:
msg = _('Removed %(num)d duplicate rules for floating ip... | _rule('OUTPUT',
'-d %s -p udp '
'--dport %s -j DNAT --to %s:1194' %
(public_ip, port, private_ip))
iptables_manager.apply()
def ensure_floating_forward(floating_ip, fixed_ip, device, network... | 64 | 64 | 187 | 16 | 48 | bopopescu/nested_quota | nova/network/linux_net.py | Python | ensure_floating_forward | ensure_floating_forward | 771 | 783 | 771 | 771 | ba7682214ebeb99cfab577416636e3b866c480a7 | bigcode/the-stack | train |
37c93b80a72250d6658ad1ae | train | function | def _set_device_mtu(dev, mtu=None):
"""Set the device MTU."""
if not mtu:
mtu = CONF.network_device_mtu
if mtu:
utils.execute('ip', 'link', 'set', dev, 'mtu',
mtu, run_as_root=True,
check_exit_code=[0, 2, 254])
| def _set_device_mtu(dev, mtu=None):
| """Set the device MTU."""
if not mtu:
mtu = CONF.network_device_mtu
if mtu:
utils.execute('ip', 'link', 'set', dev, 'mtu',
mtu, run_as_root=True,
check_exit_code=[0, 2, 254])
| def _ip_bridge_cmd(action, params, device):
"""Build commands to add/del ips to bridges/devices."""
cmd = ['ip', 'addr', action]
cmd.extend(params)
cmd.extend(['dev', device])
return cmd
def _set_device_mtu(dev, mtu=None):
| 64 | 64 | 76 | 11 | 52 | bopopescu/nested_quota | nova/network/linux_net.py | Python | _set_device_mtu | _set_device_mtu | 1,293 | 1,301 | 1,293 | 1,293 | 506043216fbcce3c5cf4eaa5306f6811f7f21251 | bigcode/the-stack | train |
aefe469ecbcd0153ccdae596 | train | class | class NeutronLinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
BRIDGE_NAME_PREFIX = 'brq'
GATEWAY_INTERFACE_PREFIX = 'gw-'
def plug(self, network, mac_address, gateway=True):
dev = self.get_dev(network)
bridge = self.get_bridge(network)
if not gateway:
# If we weren'... | class NeutronLinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
| BRIDGE_NAME_PREFIX = 'brq'
GATEWAY_INTERFACE_PREFIX = 'gw-'
def plug(self, network, mac_address, gateway=True):
dev = self.get_dev(network)
bridge = self.get_bridge(network)
if not gateway:
# If we weren't instructed to act as a gateway then add the
# appropr... | 4['filter'].add_rule('FORWARD',
'--out-interface %s -j %s' % (bridge,
CONF.iptables_drop_action))
else:
for rule in get_gateway_rules(bridge):
iptables_manager.ipv4['filter'].add_rule(*rule)
re... | 170 | 170 | 567 | 13 | 156 | bopopescu/nested_quota | nova/network/linux_net.py | Python | NeutronLinuxBridgeInterfaceDriver | NeutronLinuxBridgeInterfaceDriver | 1,765 | 1,822 | 1,765 | 1,766 | ae5686a3a884122674375c6a65e8439653f5791b | bigcode/the-stack | train |
0da10e5d4cdd3cd45d7c8c66 | train | function | def isolate_dhcp_address(interface, address):
# block arp traffic to address across the interface
rules = []
rules.append('INPUT -p ARP -i %s --arp-ip-dst %s -j DROP'
% (interface, address))
rules.append('OUTPUT -p ARP -o %s --arp-ip-src %s -j DROP'
% (interface, addres... | def isolate_dhcp_address(interface, address):
# block arp traffic to address across the interface
| rules = []
rules.append('INPUT -p ARP -i %s --arp-ip-dst %s -j DROP'
% (interface, address))
rules.append('OUTPUT -p ARP -o %s --arp-ip-src %s -j DROP'
% (interface, address))
rules.append('FORWARD -p IPv4 -i %s --ip-protocol udp '
'--ip-destination-por... | ='filter'):
for rule in rules:
cmd = ['ebtables', '-t', table, '-D'] + rule.split()
_execute(*cmd, check_exit_code=False, run_as_root=True)
def isolate_dhcp_address(interface, address):
# block arp traffic to address across the interface
| 64 | 64 | 188 | 20 | 44 | bopopescu/nested_quota | nova/network/linux_net.py | Python | isolate_dhcp_address | isolate_dhcp_address | 1,658 | 1,672 | 1,658 | 1,659 | 5b9c4bc700756c74614ee32a78613d04455f874a | bigcode/the-stack | train |
b1f79c57e3a37d3193e92a26 | train | function | def plug(network, mac_address, gateway=True):
return _get_interface_driver().plug(network, mac_address, gateway)
| def plug(network, mac_address, gateway=True):
| return _get_interface_driver().plug(network, mac_address, gateway)
| hcp/vpn/etc. endpoints not VM interfaces.
interface_driver = None
def _get_interface_driver():
global interface_driver
if not interface_driver:
interface_driver = importutils.import_object(
CONF.linuxnet_interface_driver)
return interface_driver
def plug(network, mac_address, gatew... | 64 | 64 | 25 | 10 | 53 | bopopescu/nested_quota | nova/network/linux_net.py | Python | plug | plug | 1,402 | 1,403 | 1,402 | 1,402 | 46d903677e9ff895b3794b4831b8e97a77454abe | bigcode/the-stack | train |
901f7371777c16b339039e98 | train | function | def _ra_file(dev, kind):
"""Return path to a pid or conf file for a bridge/device."""
fileutils.ensure_tree(CONF.networks_path)
return os.path.abspath('%s/nova-ra-%s.%s' % (CONF.networks_path,
dev,
kind))
| def _ra_file(dev, kind):
| """Return path to a pid or conf file for a bridge/device."""
fileutils.ensure_tree(CONF.networks_path)
return os.path.abspath('%s/nova-ra-%s.%s' % (CONF.networks_path,
dev,
kind))
| """Return path to a pid, leases, hosts or conf file for a bridge/device."""
fileutils.ensure_tree(CONF.networks_path)
return os.path.abspath('%s/nova-%s.%s' % (CONF.networks_path,
dev,
kind))
def _ra_file(dev, kind):
| 64 | 64 | 62 | 8 | 56 | bopopescu/nested_quota | nova/network/linux_net.py | Python | _ra_file | _ra_file | 1,244 | 1,249 | 1,244 | 1,244 | ebe7dee4a1a6e172d9cf80d9917f5f781b3d16b8 | bigcode/the-stack | train |
53485e5423474aee0ccc8030 | train | function | def _execute(*cmd, **kwargs):
"""Wrapper around utils._execute for fake_network."""
if CONF.fake_network:
LOG.debug('FAKE NET: %s', ' '.join(map(str, cmd)))
return 'fake', 0
else:
return utils.execute(*cmd, **kwargs)
| def _execute(*cmd, **kwargs):
| """Wrapper around utils._execute for fake_network."""
if CONF.fake_network:
LOG.debug('FAKE NET: %s', ' '.join(map(str, cmd)))
return 'fake', 0
else:
return utils.execute(*cmd, **kwargs)
| :
values.append(_host_dhcp_network(vif_id))
# NOTE(vish): 3 is the dhcp option for gateway.
values.append('3')
if gateway:
values.append('%s' % gateway)
return ','.join(values)
def _execute(*cmd, **kwargs):
| 64 | 64 | 66 | 9 | 55 | bopopescu/nested_quota | nova/network/linux_net.py | Python | _execute | _execute | 1,222 | 1,228 | 1,222 | 1,222 | ed7fd89616c587730509a2ff7b211e558b447396 | bigcode/the-stack | train |
6a795d1e964cea62e0bd99e9 | train | function | def remove_isolate_dhcp_address(interface, address):
# block arp traffic to address across the interface
rules = []
rules.append('INPUT -p ARP -i %s --arp-ip-dst %s -j DROP'
% (interface, address))
rules.append('OUTPUT -p ARP -o %s --arp-ip-src %s -j DROP'
% (interface,... | def remove_isolate_dhcp_address(interface, address):
# block arp traffic to address across the interface
| rules = []
rules.append('INPUT -p ARP -i %s --arp-ip-dst %s -j DROP'
% (interface, address))
rules.append('OUTPUT -p ARP -o %s --arp-ip-src %s -j DROP'
% (interface, address))
rules.append('FORWARD -p IPv4 -i %s --ip-protocol udp '
'--ip-destination-por... | -destination-port 67:68 -j DROP'
% interface)
# NOTE(vish): the above is not possible with iptables/arptables
ensure_ebtables_rules(rules)
def remove_isolate_dhcp_address(interface, address):
# block arp traffic to address across the interface
| 64 | 64 | 172 | 22 | 42 | bopopescu/nested_quota | nova/network/linux_net.py | Python | remove_isolate_dhcp_address | remove_isolate_dhcp_address | 1,675 | 1,688 | 1,675 | 1,676 | af29e140544da14d8a369f034d40442bfdf9383e | bigcode/the-stack | train |
35f808e91e6eb52ecb7e2459 | train | function | def metadata_forward():
"""Create forwarding rule for metadata."""
if CONF.metadata_host != '127.0.0.1':
iptables_manager.ipv4['nat'].add_rule('PREROUTING',
'-s 0.0.0.0/0 -d 169.254.169.254/32 '
'-p tcp -m tcp --dport 80... | def metadata_forward():
| """Create forwarding rule for metadata."""
if CONF.metadata_host != '127.0.0.1':
iptables_manager.ipv4['nat'].add_rule('PREROUTING',
'-s 0.0.0.0/0 -d 169.254.169.254/32 '
'-p tcp -m tcp --dport 80 -j DNAT '
... | return new_filter
# NOTE(jkoelker) This is just a nice little stub point since mocking
# builtins with mox is a nightmare
def write_to_file(file, data, mode='w'):
with open(file, mode) as f:
f.write(data)
def metadata_forward():
| 64 | 64 | 194 | 4 | 60 | bopopescu/nested_quota | nova/network/linux_net.py | Python | metadata_forward | metadata_forward | 640 | 655 | 640 | 640 | d1c858d35355348b298bbfea152adf6da0b1e251 | bigcode/the-stack | train |
9085f2adff370cbf239d1fab | train | function | def _add_dhcp_mangle_rule(dev):
table = iptables_manager.ipv4['mangle']
table.add_rule('POSTROUTING',
'-o %s -p udp -m udp --dport 68 -j CHECKSUM '
'--checksum-fill' % dev)
iptables_manager.apply()
| def _add_dhcp_mangle_rule(dev):
| table = iptables_manager.ipv4['mangle']
table.add_rule('POSTROUTING',
'-o %s -p udp -m udp --dport 68 -j CHECKSUM '
'--checksum-fill' % dev)
iptables_manager.apply()
| j ACCEPT' % args)
iptables_manager.apply()
# NOTE(russellb) Curious why this is needed? Check out this explanation from
# markmc: https://bugzilla.redhat.com/show_bug.cgi?id=910619#c6
def _add_dhcp_mangle_rule(dev):
| 64 | 64 | 68 | 10 | 53 | bopopescu/nested_quota | nova/network/linux_net.py | Python | _add_dhcp_mangle_rule | _add_dhcp_mangle_rule | 955 | 960 | 955 | 955 | a69703222104d2f2bd39506e87185b59979cc69f | bigcode/the-stack | train |
4965c6a089b81d4206fd7d4d | train | function | def _host_dhcp_opts(vif_id=None, gateway=None):
"""Return an empty gateway option."""
values = []
if vif_id is not None:
values.append(_host_dhcp_network(vif_id))
# NOTE(vish): 3 is the dhcp option for gateway.
values.append('3')
if gateway:
values.append('%s' % gateway)
retu... | def _host_dhcp_opts(vif_id=None, gateway=None):
| """Return an empty gateway option."""
values = []
if vif_id is not None:
values.append(_host_dhcp_network(vif_id))
# NOTE(vish): 3 is the dhcp option for gateway.
values.append('3')
if gateway:
values.append('%s' % gateway)
return ','.join(values)
| ip.instance.hostname,
CONF.dhcp_domain,
fixedip.address)
def _host_dns(fixedip):
return '%s\t%s.%s' % (fixedip.address,
fixedip.instance.hostname,
CONF.dhcp_domain)
def _host_dhcp_opts(vif_id=None, ga... | 64 | 64 | 88 | 14 | 50 | bopopescu/nested_quota | nova/network/linux_net.py | Python | _host_dhcp_opts | _host_dhcp_opts | 1,210 | 1,219 | 1,210 | 1,210 | f157e2f185d0ee9e1241f8445d07aa31378dc997 | bigcode/the-stack | train |
2871466f4fb320d97e5a631e | train | function | @utils.synchronized('radvd_start')
def update_ra(context, dev, network_ref):
conffile = _ra_file(dev, 'conf')
conf_str = """
interface %s
{
AdvSendAdvert on;
MinRtrAdvInterval 3;
MaxRtrAdvInterval 10;
prefix %s
{
AdvOnLink on;
AdvAutonomous on;
};
};
""" % (dev, network_ref['ci... | @utils.synchronized('radvd_start')
def update_ra(context, dev, network_ref):
| conffile = _ra_file(dev, 'conf')
conf_str = """
interface %s
{
AdvSendAdvert on;
MinRtrAdvInterval 3;
MaxRtrAdvInterval 10;
prefix %s
{
AdvOnLink on;
AdvAutonomous on;
};
};
""" % (dev, network_ref['cidr_v6'])
write_to_file(conffile, conf_str)
# Make sure radvd can act... | multi_host']:
cmd.append('--addn-hosts=%s' % _dhcp_file(dev, 'hosts'))
if dns_servers:
cmd.append('--no-resolv')
for dns_server in dns_servers:
cmd.append('--server=%s' % dns_server)
_execute(*cmd, run_as_root=True)
_add_dnsmasq_accept_rules(dev)
@utils.synchronized('radvd_star... | 98 | 98 | 329 | 20 | 78 | bopopescu/nested_quota | nova/network/linux_net.py | Python | update_ra | update_ra | 1,132 | 1,171 | 1,132 | 1,133 | 574c8b230f4c664eebf3db9c995c435c882ab1c6 | bigcode/the-stack | train |
938c696f7282ce17e1cc95a7 | train | function | def send_arp_for_ip(ip, device, count):
out, err = _execute('arping', '-U', ip,
'-A', '-I', device,
'-c', str(count),
run_as_root=True, check_exit_code=False)
if err:
LOG.debug('arping error for ip %s', ip)
| def send_arp_for_ip(ip, device, count):
| out, err = _execute('arping', '-U', ip,
'-A', '-I', device,
'-c', str(count),
run_as_root=True, check_exit_code=False)
if err:
LOG.debug('arping error for ip %s', ip)
| '].add_rule('POSTROUTING',
'-s %(range)s -d %(range)s '
'-m conntrack ! --ctstate DNAT '
'-j ACCEPT' %
{'range': ip_range})
iptables_manager.apply()... | 64 | 64 | 73 | 12 | 52 | bopopescu/nested_quota | nova/network/linux_net.py | Python | send_arp_for_ip | send_arp_for_ip | 720 | 727 | 720 | 720 | a275a6741eece23a73097cbf009e8c7f3fcd60f2 | bigcode/the-stack | train |
c94dfae7c97aa44758f216e5 | train | function | def ensure_metadata_ip():
"""Sets up local metadata ip."""
_execute('ip', 'addr', 'add', '169.254.169.254/32',
'scope', 'link', 'dev', 'lo',
run_as_root=True, check_exit_code=[0, 2, 254])
| def ensure_metadata_ip():
| """Sets up local metadata ip."""
_execute('ip', 'addr', 'add', '169.254.169.254/32',
'scope', 'link', 'dev', 'lo',
run_as_root=True, check_exit_code=[0, 2, 254])
| , device):
"""Unbind a public ip from public interface."""
_execute('ip', 'addr', 'del', str(floating_ip) + '/32',
'dev', device,
run_as_root=True, check_exit_code=[0, 2, 254])
def ensure_metadata_ip():
| 64 | 64 | 67 | 5 | 59 | bopopescu/nested_quota | nova/network/linux_net.py | Python | ensure_metadata_ip | ensure_metadata_ip | 747 | 751 | 747 | 747 | 1b41452a4ccfbd065f1947879809a557963692c0 | bigcode/the-stack | train |
84b882cc068162e82818e8d6 | train | function | def get_dhcp_leases(context, network_ref):
"""Return a network's hosts config in dnsmasq leasefile format."""
hosts = []
host = None
if network_ref['multi_host']:
host = CONF.host
for fixedip in objects.FixedIPList.get_by_network(context,
... | def get_dhcp_leases(context, network_ref):
| """Return a network's hosts config in dnsmasq leasefile format."""
hosts = []
host = None
if network_ref['multi_host']:
host = CONF.host
for fixedip in objects.FixedIPList.get_by_network(context,
network_ref,
... | _arp_for_ha_count)
if CONF.use_ipv6:
_execute('ip', '-f', 'inet6', 'addr',
'change', network_ref['cidr_v6'],
'dev', dev, run_as_root=True)
def get_dhcp_leases(context, network_ref):
| 64 | 64 | 122 | 11 | 53 | bopopescu/nested_quota | nova/network/linux_net.py | Python | get_dhcp_leases | get_dhcp_leases | 891 | 905 | 891 | 891 | fc7a877a8e21693ee168a1c304ec2e8e47c52544 | bigcode/the-stack | train |
f269ee02273861a9344e5fd5 | train | function | def _ip_bridge_cmd(action, params, device):
"""Build commands to add/del ips to bridges/devices."""
cmd = ['ip', 'addr', action]
cmd.extend(params)
cmd.extend(['dev', device])
return cmd
| def _ip_bridge_cmd(action, params, device):
| """Build commands to add/del ips to bridges/devices."""
cmd = ['ip', 'addr', action]
cmd.extend(params)
cmd.extend(['dev', device])
return cmd
| machine has rebooted pid might be incorrect (caller should check).
"""
pid_file = _ra_file(dev, 'pid')
if os.path.exists(pid_file):
with open(pid_file, 'r') as f:
return int(f.read())
def _ip_bridge_cmd(action, params, device):
| 64 | 64 | 53 | 11 | 53 | bopopescu/nested_quota | nova/network/linux_net.py | Python | _ip_bridge_cmd | _ip_bridge_cmd | 1,285 | 1,290 | 1,285 | 1,285 | c0ce0c6b38f1dddccc82d2162456d4d970cdca6b | bigcode/the-stack | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.