prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>dcf.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python import sys sys.path.append('/var/www/html/valumodel.com/scripts/dcf') from calc_dcf import calc_dcf def create_dcf(req, tax_rate, growth_rate_1_year_out, sga_of_sales, da_of_sales, capex_of_sales, nwc_of_sales, levered_beta, current_yield, exit_multiple, ticker): <|fim_middle|> <|fim▁end|>
assumptions = {} try: assumptions['Tax Rate'] = float(tax_rate)/100.0 assumptions['Growth Rate 1 year out'] = float(growth_rate_1_year_out)/100.0 assumptions['SGA % of sales'] = float(sga_of_sales)/100.0 assumptions['D&A % of sales'] = float(da_of_sales)/100.0 assumptions['CAPEX % of sales'] = float(capex_of_sales)/100.0 assumptions['NWC % of sales'] = float(nwc_of_sales)/100.0 assumptions['Levered Beta'] = float(levered_beta) assumptions['Current Yield'] = float(current_yield)/100.0 assumptions['Exit Multiple'] = float(exit_multiple) except ValueError: return '<!doctype html><html><body><h1>Invalid DCF Input. Please try again.</h1></body></html>' ticker = ticker.split(' ')[0] if not ticker.isalnum(): return '<!doctype html><html><body><h1>Invalid Ticker. Please try again.</h1></body></html>' return calc_dcf(assumptions, ticker.upper())
<|file_name|>dcf.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python import sys sys.path.append('/var/www/html/valumodel.com/scripts/dcf') from calc_dcf import calc_dcf def create_dcf(req, tax_rate, growth_rate_1_year_out, sga_of_sales, da_of_sales, capex_of_sales, nwc_of_sales, levered_beta, current_yield, exit_multiple, ticker): assumptions = {} try: assumptions['Tax Rate'] = float(tax_rate)/100.0 assumptions['Growth Rate 1 year out'] = float(growth_rate_1_year_out)/100.0 assumptions['SGA % of sales'] = float(sga_of_sales)/100.0 assumptions['D&A % of sales'] = float(da_of_sales)/100.0 assumptions['CAPEX % of sales'] = float(capex_of_sales)/100.0 assumptions['NWC % of sales'] = float(nwc_of_sales)/100.0 assumptions['Levered Beta'] = float(levered_beta) assumptions['Current Yield'] = float(current_yield)/100.0 assumptions['Exit Multiple'] = float(exit_multiple) except ValueError: return '<!doctype html><html><body><h1>Invalid DCF Input. Please try again.</h1></body></html>' ticker = ticker.split(' ')[0] if not ticker.isalnum(): <|fim_middle|> return calc_dcf(assumptions, ticker.upper()) <|fim▁end|>
return '<!doctype html><html><body><h1>Invalid Ticker. Please try again.</h1></body></html>'
<|file_name|>dcf.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python import sys sys.path.append('/var/www/html/valumodel.com/scripts/dcf') from calc_dcf import calc_dcf def <|fim_middle|>(req, tax_rate, growth_rate_1_year_out, sga_of_sales, da_of_sales, capex_of_sales, nwc_of_sales, levered_beta, current_yield, exit_multiple, ticker): assumptions = {} try: assumptions['Tax Rate'] = float(tax_rate)/100.0 assumptions['Growth Rate 1 year out'] = float(growth_rate_1_year_out)/100.0 assumptions['SGA % of sales'] = float(sga_of_sales)/100.0 assumptions['D&A % of sales'] = float(da_of_sales)/100.0 assumptions['CAPEX % of sales'] = float(capex_of_sales)/100.0 assumptions['NWC % of sales'] = float(nwc_of_sales)/100.0 assumptions['Levered Beta'] = float(levered_beta) assumptions['Current Yield'] = float(current_yield)/100.0 assumptions['Exit Multiple'] = float(exit_multiple) except ValueError: return '<!doctype html><html><body><h1>Invalid DCF Input. Please try again.</h1></body></html>' ticker = ticker.split(' ')[0] if not ticker.isalnum(): return '<!doctype html><html><body><h1>Invalid Ticker. Please try again.</h1></body></html>' return calc_dcf(assumptions, ticker.upper()) <|fim▁end|>
create_dcf
<|file_name|>0006_sapelliproject_sapelli_fingerprint.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations class Migration(migrations.Migration): dependencies = [ ('geokey_sapelli', '0005_sapellifield_truefalse'), ] operations = [ migrations.AddField( model_name='sapelliproject', name='sapelli_fingerprint', field=models.IntegerField(default=-1), preserve_default=False, ),<|fim▁hole|><|fim▁end|>
]
<|file_name|>0006_sapelliproject_sapelli_fingerprint.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations class Migration(migrations.Migration): <|fim_middle|> <|fim▁end|>
dependencies = [ ('geokey_sapelli', '0005_sapellifield_truefalse'), ] operations = [ migrations.AddField( model_name='sapelliproject', name='sapelli_fingerprint', field=models.IntegerField(default=-1), preserve_default=False, ), ]
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|>import os import json import collections import datetime from flask import Flask, request, current_app, make_response, session, escape, Response, jsonify from flask_jwt_extended import JWTManager, jwt_required, create_access_token, get_jwt_identity from flask_socketio import SocketIO from neo4j.v1 import GraphDatabase, basic_auth from lib.crossDomain import crossdomain import simplekv.memory import eventlet #eventlet.monkey_patch() # if sys.version_info < (3, 0): # sys.stdout.write("Sorry, requires Python 3.x, not Python 2.x\n") # sys.exit(1) config = json.load(open('./config.json')); # Init UPLOAD_FOLDER = os.path.dirname(os.path.realpath(__file__)) + "/uploads" <|fim▁hole|> app.debug = True app.config['SECRET_KEY'] = config['auth_secret'] app.config['JWT_BLACKLIST_ENABLED'] = False app.config['JWT_BLACKLIST_STORE'] = simplekv.memory.DictStore() app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = 'all' app.config['JWT_ACCESS_TOKEN_EXPIRES'] = datetime.timedelta(minutes=15) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER driver = GraphDatabase.driver(config['database_url'], auth=basic_auth(config['database_user'],config['database_pass'])) db_session = driver.session() # start jwt service jwt = JWTManager(app) # Import blueprints from auth import auth_blueprint from banner import banner_blueprint from people import people_blueprint from organizations import organizations_blueprint from repos import repositories_blueprint from schema import schema_blueprint from data import data_blueprint from search import search_blueprint from upload import upload_blueprint from export import export_blueprint from list import list_blueprint from .sockets import sockets as socket_blueprint # register API modules app.register_blueprint(banner_blueprint) app.register_blueprint(auth_blueprint) app.register_blueprint(people_blueprint) app.register_blueprint(organizations_blueprint) app.register_blueprint(repositories_blueprint) app.register_blueprint(schema_blueprint) app.register_blueprint(search_blueprint) app.register_blueprint(data_blueprint) app.register_blueprint(upload_blueprint) app.register_blueprint(socket_blueprint) app.register_blueprint(export_blueprint) app.register_blueprint(list_blueprint) x_socketio.init_app(app) return app, jwt<|fim▁end|>
x_socketio = SocketIO() def create_app(): app = Flask(__name__)
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|>import os import json import collections import datetime from flask import Flask, request, current_app, make_response, session, escape, Response, jsonify from flask_jwt_extended import JWTManager, jwt_required, create_access_token, get_jwt_identity from flask_socketio import SocketIO from neo4j.v1 import GraphDatabase, basic_auth from lib.crossDomain import crossdomain import simplekv.memory import eventlet #eventlet.monkey_patch() # if sys.version_info < (3, 0): # sys.stdout.write("Sorry, requires Python 3.x, not Python 2.x\n") # sys.exit(1) config = json.load(open('./config.json')); # Init UPLOAD_FOLDER = os.path.dirname(os.path.realpath(__file__)) + "/uploads" x_socketio = SocketIO() def create_app(): <|fim_middle|> <|fim▁end|>
app = Flask(__name__) app.debug = True app.config['SECRET_KEY'] = config['auth_secret'] app.config['JWT_BLACKLIST_ENABLED'] = False app.config['JWT_BLACKLIST_STORE'] = simplekv.memory.DictStore() app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = 'all' app.config['JWT_ACCESS_TOKEN_EXPIRES'] = datetime.timedelta(minutes=15) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER driver = GraphDatabase.driver(config['database_url'], auth=basic_auth(config['database_user'],config['database_pass'])) db_session = driver.session() # start jwt service jwt = JWTManager(app) # Import blueprints from auth import auth_blueprint from banner import banner_blueprint from people import people_blueprint from organizations import organizations_blueprint from repos import repositories_blueprint from schema import schema_blueprint from data import data_blueprint from search import search_blueprint from upload import upload_blueprint from export import export_blueprint from list import list_blueprint from .sockets import sockets as socket_blueprint # register API modules app.register_blueprint(banner_blueprint) app.register_blueprint(auth_blueprint) app.register_blueprint(people_blueprint) app.register_blueprint(organizations_blueprint) app.register_blueprint(repositories_blueprint) app.register_blueprint(schema_blueprint) app.register_blueprint(search_blueprint) app.register_blueprint(data_blueprint) app.register_blueprint(upload_blueprint) app.register_blueprint(socket_blueprint) app.register_blueprint(export_blueprint) app.register_blueprint(list_blueprint) x_socketio.init_app(app) return app, jwt
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|>import os import json import collections import datetime from flask import Flask, request, current_app, make_response, session, escape, Response, jsonify from flask_jwt_extended import JWTManager, jwt_required, create_access_token, get_jwt_identity from flask_socketio import SocketIO from neo4j.v1 import GraphDatabase, basic_auth from lib.crossDomain import crossdomain import simplekv.memory import eventlet #eventlet.monkey_patch() # if sys.version_info < (3, 0): # sys.stdout.write("Sorry, requires Python 3.x, not Python 2.x\n") # sys.exit(1) config = json.load(open('./config.json')); # Init UPLOAD_FOLDER = os.path.dirname(os.path.realpath(__file__)) + "/uploads" x_socketio = SocketIO() def <|fim_middle|>(): app = Flask(__name__) app.debug = True app.config['SECRET_KEY'] = config['auth_secret'] app.config['JWT_BLACKLIST_ENABLED'] = False app.config['JWT_BLACKLIST_STORE'] = simplekv.memory.DictStore() app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = 'all' app.config['JWT_ACCESS_TOKEN_EXPIRES'] = datetime.timedelta(minutes=15) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER driver = GraphDatabase.driver(config['database_url'], auth=basic_auth(config['database_user'],config['database_pass'])) db_session = driver.session() # start jwt service jwt = JWTManager(app) # Import blueprints from auth import auth_blueprint from banner import banner_blueprint from people import people_blueprint from organizations import organizations_blueprint from repos import repositories_blueprint from schema import schema_blueprint from data import data_blueprint from search import search_blueprint from upload import upload_blueprint from export import export_blueprint from list import list_blueprint from .sockets import sockets as socket_blueprint # register API modules app.register_blueprint(banner_blueprint) app.register_blueprint(auth_blueprint) app.register_blueprint(people_blueprint) app.register_blueprint(organizations_blueprint) app.register_blueprint(repositories_blueprint) app.register_blueprint(schema_blueprint) app.register_blueprint(search_blueprint) app.register_blueprint(data_blueprint) app.register_blueprint(upload_blueprint) app.register_blueprint(socket_blueprint) app.register_blueprint(export_blueprint) app.register_blueprint(list_blueprint) x_socketio.init_app(app) return app, jwt <|fim▁end|>
create_app
<|file_name|>outfits.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- def outfit(): collection = [] for _ in range(0, 5): collection.append("Item{}".format(_))<|fim▁hole|> return { "data": collection, } api = [ ('/outfit', 'outfit', outfit), ]<|fim▁end|>
<|file_name|>outfits.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- def outfit(): <|fim_middle|> api = [ ('/outfit', 'outfit', outfit), ] <|fim▁end|>
collection = [] for _ in range(0, 5): collection.append("Item{}".format(_)) return { "data": collection, }
<|file_name|>outfits.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- def <|fim_middle|>(): collection = [] for _ in range(0, 5): collection.append("Item{}".format(_)) return { "data": collection, } api = [ ('/outfit', 'outfit', outfit), ] <|fim▁end|>
outfit
<|file_name|>hws_cascaded_configer.py<|end_file_name|><|fim▁begin|># -*- coding:utf-8 -*- __author__ = 'q00222219@huawei' import time from heat.openstack.common import log as logging import heat.engine.resources.cloudmanager.commonutils as commonutils import heat.engine.resources.cloudmanager.constant as constant import heat.engine.resources.cloudmanager.exception as exception import pdb LOG = logging.getLogger(__name__) class CascadedConfiger(object): def __init__(self, public_ip_api, api_ip, domain, user, password, cascading_domain, cascading_api_ip, cascaded_domain, cascaded_api_ip, cascaded_api_subnet_gateway): self.public_ip_api = public_ip_api self.api_ip = api_ip self.domain = domain self.user = user self.password = password self.cascading_domain = cascading_domain self.cascading_api_ip = cascading_api_ip self.cascaded_domain = cascaded_domain self.cascaded_ip = cascaded_api_ip self.gateway = cascaded_api_subnet_gateway def do_config(self): start_time = time.time() #pdb.set_trace() LOG.info("start config cascaded, cascaded: %s" % self.domain) # wait cascaded tunnel can visit commonutils.check_host_status(host=self.public_ip_api, user=self.user, password=self.password, retry_time=500, interval=1) # config cascaded host self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("first config success, cascaded: %s, cost time: %d" % (self.domain, cost_time)) # check config result for i in range(3): try: # check 90s commonutils.check_host_status( host=self.public_ip_api, user=constant.VcloudConstant.ROOT, password=constant.VcloudConstant.ROOT_PWD, retry_time=15, interval=1) LOG.info("cascaded api is ready..") break except exception.CheckHostStatusFailure: if i == 2: LOG.error("check cascaded api failed ...")<|fim▁hole|> "retry config cascaded ...") self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("config cascaded success, cascaded: %s, cost_time: %d" % (self.domain, cost_time)) def _config_az_cascaded(self): LOG.info("start config cascaded host, host: %s" % self.api_ip) # modify dns server address address = "/%(cascading_domain)s/%(cascading_ip)s,/%(cascaded_domain)s/%(cascaded_ip)s" \ % {"cascading_domain": self.cascading_domain, "cascading_ip": self.cascading_api_ip, "cascaded_domain":self.cascaded_domain, "cascaded_ip":self.cascaded_ip} for i in range(30): try: commonutils.execute_cmd_without_stdout( host=self.public_ip_api, user=self.user, password=self.password, cmd='cd %(dir)s; source /root/adminrc; sh %(script)s replace %(address)s' % {"dir": constant.PublicConstant.SCRIPTS_DIR, "script": constant.PublicConstant. MODIFY_DNS_SERVER_ADDRESS, "address": address}) break except exception.SSHCommandFailure as e: LOG.error("modify cascaded dns address error, cascaded: " "%s, error: %s" % (self.domain, e.format_message())) time.sleep(1) LOG.info( "config cascaded dns address success, cascaded: %s" % self.public_ip_api) return True<|fim▁end|>
break LOG.error("check cascaded api error, "
<|file_name|>hws_cascaded_configer.py<|end_file_name|><|fim▁begin|># -*- coding:utf-8 -*- __author__ = 'q00222219@huawei' import time from heat.openstack.common import log as logging import heat.engine.resources.cloudmanager.commonutils as commonutils import heat.engine.resources.cloudmanager.constant as constant import heat.engine.resources.cloudmanager.exception as exception import pdb LOG = logging.getLogger(__name__) class CascadedConfiger(object): <|fim_middle|> <|fim▁end|>
def __init__(self, public_ip_api, api_ip, domain, user, password, cascading_domain, cascading_api_ip, cascaded_domain, cascaded_api_ip, cascaded_api_subnet_gateway): self.public_ip_api = public_ip_api self.api_ip = api_ip self.domain = domain self.user = user self.password = password self.cascading_domain = cascading_domain self.cascading_api_ip = cascading_api_ip self.cascaded_domain = cascaded_domain self.cascaded_ip = cascaded_api_ip self.gateway = cascaded_api_subnet_gateway def do_config(self): start_time = time.time() #pdb.set_trace() LOG.info("start config cascaded, cascaded: %s" % self.domain) # wait cascaded tunnel can visit commonutils.check_host_status(host=self.public_ip_api, user=self.user, password=self.password, retry_time=500, interval=1) # config cascaded host self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("first config success, cascaded: %s, cost time: %d" % (self.domain, cost_time)) # check config result for i in range(3): try: # check 90s commonutils.check_host_status( host=self.public_ip_api, user=constant.VcloudConstant.ROOT, password=constant.VcloudConstant.ROOT_PWD, retry_time=15, interval=1) LOG.info("cascaded api is ready..") break except exception.CheckHostStatusFailure: if i == 2: LOG.error("check cascaded api failed ...") break LOG.error("check cascaded api error, " "retry config cascaded ...") self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("config cascaded success, cascaded: %s, cost_time: %d" % (self.domain, cost_time)) def _config_az_cascaded(self): LOG.info("start config cascaded host, host: %s" % self.api_ip) # modify dns server address address = "/%(cascading_domain)s/%(cascading_ip)s,/%(cascaded_domain)s/%(cascaded_ip)s" \ % {"cascading_domain": self.cascading_domain, "cascading_ip": self.cascading_api_ip, "cascaded_domain":self.cascaded_domain, "cascaded_ip":self.cascaded_ip} for i in range(30): try: commonutils.execute_cmd_without_stdout( host=self.public_ip_api, user=self.user, password=self.password, cmd='cd %(dir)s; source /root/adminrc; sh %(script)s replace %(address)s' % {"dir": constant.PublicConstant.SCRIPTS_DIR, "script": constant.PublicConstant. MODIFY_DNS_SERVER_ADDRESS, "address": address}) break except exception.SSHCommandFailure as e: LOG.error("modify cascaded dns address error, cascaded: " "%s, error: %s" % (self.domain, e.format_message())) time.sleep(1) LOG.info( "config cascaded dns address success, cascaded: %s" % self.public_ip_api) return True
<|file_name|>hws_cascaded_configer.py<|end_file_name|><|fim▁begin|># -*- coding:utf-8 -*- __author__ = 'q00222219@huawei' import time from heat.openstack.common import log as logging import heat.engine.resources.cloudmanager.commonutils as commonutils import heat.engine.resources.cloudmanager.constant as constant import heat.engine.resources.cloudmanager.exception as exception import pdb LOG = logging.getLogger(__name__) class CascadedConfiger(object): def __init__(self, public_ip_api, api_ip, domain, user, password, cascading_domain, cascading_api_ip, cascaded_domain, cascaded_api_ip, cascaded_api_subnet_gateway): <|fim_middle|> def do_config(self): start_time = time.time() #pdb.set_trace() LOG.info("start config cascaded, cascaded: %s" % self.domain) # wait cascaded tunnel can visit commonutils.check_host_status(host=self.public_ip_api, user=self.user, password=self.password, retry_time=500, interval=1) # config cascaded host self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("first config success, cascaded: %s, cost time: %d" % (self.domain, cost_time)) # check config result for i in range(3): try: # check 90s commonutils.check_host_status( host=self.public_ip_api, user=constant.VcloudConstant.ROOT, password=constant.VcloudConstant.ROOT_PWD, retry_time=15, interval=1) LOG.info("cascaded api is ready..") break except exception.CheckHostStatusFailure: if i == 2: LOG.error("check cascaded api failed ...") break LOG.error("check cascaded api error, " "retry config cascaded ...") self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("config cascaded success, cascaded: %s, cost_time: %d" % (self.domain, cost_time)) def _config_az_cascaded(self): LOG.info("start config cascaded host, host: %s" % self.api_ip) # modify dns server address address = "/%(cascading_domain)s/%(cascading_ip)s,/%(cascaded_domain)s/%(cascaded_ip)s" \ % {"cascading_domain": self.cascading_domain, "cascading_ip": self.cascading_api_ip, "cascaded_domain":self.cascaded_domain, "cascaded_ip":self.cascaded_ip} for i in range(30): try: commonutils.execute_cmd_without_stdout( host=self.public_ip_api, user=self.user, password=self.password, cmd='cd %(dir)s; source /root/adminrc; sh %(script)s replace %(address)s' % {"dir": constant.PublicConstant.SCRIPTS_DIR, "script": constant.PublicConstant. MODIFY_DNS_SERVER_ADDRESS, "address": address}) break except exception.SSHCommandFailure as e: LOG.error("modify cascaded dns address error, cascaded: " "%s, error: %s" % (self.domain, e.format_message())) time.sleep(1) LOG.info( "config cascaded dns address success, cascaded: %s" % self.public_ip_api) return True <|fim▁end|>
self.public_ip_api = public_ip_api self.api_ip = api_ip self.domain = domain self.user = user self.password = password self.cascading_domain = cascading_domain self.cascading_api_ip = cascading_api_ip self.cascaded_domain = cascaded_domain self.cascaded_ip = cascaded_api_ip self.gateway = cascaded_api_subnet_gateway
<|file_name|>hws_cascaded_configer.py<|end_file_name|><|fim▁begin|># -*- coding:utf-8 -*- __author__ = 'q00222219@huawei' import time from heat.openstack.common import log as logging import heat.engine.resources.cloudmanager.commonutils as commonutils import heat.engine.resources.cloudmanager.constant as constant import heat.engine.resources.cloudmanager.exception as exception import pdb LOG = logging.getLogger(__name__) class CascadedConfiger(object): def __init__(self, public_ip_api, api_ip, domain, user, password, cascading_domain, cascading_api_ip, cascaded_domain, cascaded_api_ip, cascaded_api_subnet_gateway): self.public_ip_api = public_ip_api self.api_ip = api_ip self.domain = domain self.user = user self.password = password self.cascading_domain = cascading_domain self.cascading_api_ip = cascading_api_ip self.cascaded_domain = cascaded_domain self.cascaded_ip = cascaded_api_ip self.gateway = cascaded_api_subnet_gateway def do_config(self): <|fim_middle|> def _config_az_cascaded(self): LOG.info("start config cascaded host, host: %s" % self.api_ip) # modify dns server address address = "/%(cascading_domain)s/%(cascading_ip)s,/%(cascaded_domain)s/%(cascaded_ip)s" \ % {"cascading_domain": self.cascading_domain, "cascading_ip": self.cascading_api_ip, "cascaded_domain":self.cascaded_domain, "cascaded_ip":self.cascaded_ip} for i in range(30): try: commonutils.execute_cmd_without_stdout( host=self.public_ip_api, user=self.user, password=self.password, cmd='cd %(dir)s; source /root/adminrc; sh %(script)s replace %(address)s' % {"dir": constant.PublicConstant.SCRIPTS_DIR, "script": constant.PublicConstant. MODIFY_DNS_SERVER_ADDRESS, "address": address}) break except exception.SSHCommandFailure as e: LOG.error("modify cascaded dns address error, cascaded: " "%s, error: %s" % (self.domain, e.format_message())) time.sleep(1) LOG.info( "config cascaded dns address success, cascaded: %s" % self.public_ip_api) return True <|fim▁end|>
start_time = time.time() #pdb.set_trace() LOG.info("start config cascaded, cascaded: %s" % self.domain) # wait cascaded tunnel can visit commonutils.check_host_status(host=self.public_ip_api, user=self.user, password=self.password, retry_time=500, interval=1) # config cascaded host self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("first config success, cascaded: %s, cost time: %d" % (self.domain, cost_time)) # check config result for i in range(3): try: # check 90s commonutils.check_host_status( host=self.public_ip_api, user=constant.VcloudConstant.ROOT, password=constant.VcloudConstant.ROOT_PWD, retry_time=15, interval=1) LOG.info("cascaded api is ready..") break except exception.CheckHostStatusFailure: if i == 2: LOG.error("check cascaded api failed ...") break LOG.error("check cascaded api error, " "retry config cascaded ...") self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("config cascaded success, cascaded: %s, cost_time: %d" % (self.domain, cost_time))
<|file_name|>hws_cascaded_configer.py<|end_file_name|><|fim▁begin|># -*- coding:utf-8 -*- __author__ = 'q00222219@huawei' import time from heat.openstack.common import log as logging import heat.engine.resources.cloudmanager.commonutils as commonutils import heat.engine.resources.cloudmanager.constant as constant import heat.engine.resources.cloudmanager.exception as exception import pdb LOG = logging.getLogger(__name__) class CascadedConfiger(object): def __init__(self, public_ip_api, api_ip, domain, user, password, cascading_domain, cascading_api_ip, cascaded_domain, cascaded_api_ip, cascaded_api_subnet_gateway): self.public_ip_api = public_ip_api self.api_ip = api_ip self.domain = domain self.user = user self.password = password self.cascading_domain = cascading_domain self.cascading_api_ip = cascading_api_ip self.cascaded_domain = cascaded_domain self.cascaded_ip = cascaded_api_ip self.gateway = cascaded_api_subnet_gateway def do_config(self): start_time = time.time() #pdb.set_trace() LOG.info("start config cascaded, cascaded: %s" % self.domain) # wait cascaded tunnel can visit commonutils.check_host_status(host=self.public_ip_api, user=self.user, password=self.password, retry_time=500, interval=1) # config cascaded host self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("first config success, cascaded: %s, cost time: %d" % (self.domain, cost_time)) # check config result for i in range(3): try: # check 90s commonutils.check_host_status( host=self.public_ip_api, user=constant.VcloudConstant.ROOT, password=constant.VcloudConstant.ROOT_PWD, retry_time=15, interval=1) LOG.info("cascaded api is ready..") break except exception.CheckHostStatusFailure: if i == 2: LOG.error("check cascaded api failed ...") break LOG.error("check cascaded api error, " "retry config cascaded ...") self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("config cascaded success, cascaded: %s, cost_time: %d" % (self.domain, cost_time)) def _config_az_cascaded(self): <|fim_middle|> <|fim▁end|>
LOG.info("start config cascaded host, host: %s" % self.api_ip) # modify dns server address address = "/%(cascading_domain)s/%(cascading_ip)s,/%(cascaded_domain)s/%(cascaded_ip)s" \ % {"cascading_domain": self.cascading_domain, "cascading_ip": self.cascading_api_ip, "cascaded_domain":self.cascaded_domain, "cascaded_ip":self.cascaded_ip} for i in range(30): try: commonutils.execute_cmd_without_stdout( host=self.public_ip_api, user=self.user, password=self.password, cmd='cd %(dir)s; source /root/adminrc; sh %(script)s replace %(address)s' % {"dir": constant.PublicConstant.SCRIPTS_DIR, "script": constant.PublicConstant. MODIFY_DNS_SERVER_ADDRESS, "address": address}) break except exception.SSHCommandFailure as e: LOG.error("modify cascaded dns address error, cascaded: " "%s, error: %s" % (self.domain, e.format_message())) time.sleep(1) LOG.info( "config cascaded dns address success, cascaded: %s" % self.public_ip_api) return True
<|file_name|>hws_cascaded_configer.py<|end_file_name|><|fim▁begin|># -*- coding:utf-8 -*- __author__ = 'q00222219@huawei' import time from heat.openstack.common import log as logging import heat.engine.resources.cloudmanager.commonutils as commonutils import heat.engine.resources.cloudmanager.constant as constant import heat.engine.resources.cloudmanager.exception as exception import pdb LOG = logging.getLogger(__name__) class CascadedConfiger(object): def __init__(self, public_ip_api, api_ip, domain, user, password, cascading_domain, cascading_api_ip, cascaded_domain, cascaded_api_ip, cascaded_api_subnet_gateway): self.public_ip_api = public_ip_api self.api_ip = api_ip self.domain = domain self.user = user self.password = password self.cascading_domain = cascading_domain self.cascading_api_ip = cascading_api_ip self.cascaded_domain = cascaded_domain self.cascaded_ip = cascaded_api_ip self.gateway = cascaded_api_subnet_gateway def do_config(self): start_time = time.time() #pdb.set_trace() LOG.info("start config cascaded, cascaded: %s" % self.domain) # wait cascaded tunnel can visit commonutils.check_host_status(host=self.public_ip_api, user=self.user, password=self.password, retry_time=500, interval=1) # config cascaded host self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("first config success, cascaded: %s, cost time: %d" % (self.domain, cost_time)) # check config result for i in range(3): try: # check 90s commonutils.check_host_status( host=self.public_ip_api, user=constant.VcloudConstant.ROOT, password=constant.VcloudConstant.ROOT_PWD, retry_time=15, interval=1) LOG.info("cascaded api is ready..") break except exception.CheckHostStatusFailure: if i == 2: <|fim_middle|> LOG.error("check cascaded api error, " "retry config cascaded ...") self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("config cascaded success, cascaded: %s, cost_time: %d" % (self.domain, cost_time)) def _config_az_cascaded(self): LOG.info("start config cascaded host, host: %s" % self.api_ip) # modify dns server address address = "/%(cascading_domain)s/%(cascading_ip)s,/%(cascaded_domain)s/%(cascaded_ip)s" \ % {"cascading_domain": self.cascading_domain, "cascading_ip": self.cascading_api_ip, "cascaded_domain":self.cascaded_domain, "cascaded_ip":self.cascaded_ip} for i in range(30): try: commonutils.execute_cmd_without_stdout( host=self.public_ip_api, user=self.user, password=self.password, cmd='cd %(dir)s; source /root/adminrc; sh %(script)s replace %(address)s' % {"dir": constant.PublicConstant.SCRIPTS_DIR, "script": constant.PublicConstant. MODIFY_DNS_SERVER_ADDRESS, "address": address}) break except exception.SSHCommandFailure as e: LOG.error("modify cascaded dns address error, cascaded: " "%s, error: %s" % (self.domain, e.format_message())) time.sleep(1) LOG.info( "config cascaded dns address success, cascaded: %s" % self.public_ip_api) return True <|fim▁end|>
LOG.error("check cascaded api failed ...") break
<|file_name|>hws_cascaded_configer.py<|end_file_name|><|fim▁begin|># -*- coding:utf-8 -*- __author__ = 'q00222219@huawei' import time from heat.openstack.common import log as logging import heat.engine.resources.cloudmanager.commonutils as commonutils import heat.engine.resources.cloudmanager.constant as constant import heat.engine.resources.cloudmanager.exception as exception import pdb LOG = logging.getLogger(__name__) class CascadedConfiger(object): def <|fim_middle|>(self, public_ip_api, api_ip, domain, user, password, cascading_domain, cascading_api_ip, cascaded_domain, cascaded_api_ip, cascaded_api_subnet_gateway): self.public_ip_api = public_ip_api self.api_ip = api_ip self.domain = domain self.user = user self.password = password self.cascading_domain = cascading_domain self.cascading_api_ip = cascading_api_ip self.cascaded_domain = cascaded_domain self.cascaded_ip = cascaded_api_ip self.gateway = cascaded_api_subnet_gateway def do_config(self): start_time = time.time() #pdb.set_trace() LOG.info("start config cascaded, cascaded: %s" % self.domain) # wait cascaded tunnel can visit commonutils.check_host_status(host=self.public_ip_api, user=self.user, password=self.password, retry_time=500, interval=1) # config cascaded host self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("first config success, cascaded: %s, cost time: %d" % (self.domain, cost_time)) # check config result for i in range(3): try: # check 90s commonutils.check_host_status( host=self.public_ip_api, user=constant.VcloudConstant.ROOT, password=constant.VcloudConstant.ROOT_PWD, retry_time=15, interval=1) LOG.info("cascaded api is ready..") break except exception.CheckHostStatusFailure: if i == 2: LOG.error("check cascaded api failed ...") break LOG.error("check cascaded api error, " "retry config cascaded ...") self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("config cascaded success, cascaded: %s, cost_time: %d" % (self.domain, cost_time)) def _config_az_cascaded(self): LOG.info("start config cascaded host, host: %s" % self.api_ip) # modify dns server address address = "/%(cascading_domain)s/%(cascading_ip)s,/%(cascaded_domain)s/%(cascaded_ip)s" \ % {"cascading_domain": self.cascading_domain, "cascading_ip": self.cascading_api_ip, "cascaded_domain":self.cascaded_domain, "cascaded_ip":self.cascaded_ip} for i in range(30): try: commonutils.execute_cmd_without_stdout( host=self.public_ip_api, user=self.user, password=self.password, cmd='cd %(dir)s; source /root/adminrc; sh %(script)s replace %(address)s' % {"dir": constant.PublicConstant.SCRIPTS_DIR, "script": constant.PublicConstant. MODIFY_DNS_SERVER_ADDRESS, "address": address}) break except exception.SSHCommandFailure as e: LOG.error("modify cascaded dns address error, cascaded: " "%s, error: %s" % (self.domain, e.format_message())) time.sleep(1) LOG.info( "config cascaded dns address success, cascaded: %s" % self.public_ip_api) return True <|fim▁end|>
__init__
<|file_name|>hws_cascaded_configer.py<|end_file_name|><|fim▁begin|># -*- coding:utf-8 -*- __author__ = 'q00222219@huawei' import time from heat.openstack.common import log as logging import heat.engine.resources.cloudmanager.commonutils as commonutils import heat.engine.resources.cloudmanager.constant as constant import heat.engine.resources.cloudmanager.exception as exception import pdb LOG = logging.getLogger(__name__) class CascadedConfiger(object): def __init__(self, public_ip_api, api_ip, domain, user, password, cascading_domain, cascading_api_ip, cascaded_domain, cascaded_api_ip, cascaded_api_subnet_gateway): self.public_ip_api = public_ip_api self.api_ip = api_ip self.domain = domain self.user = user self.password = password self.cascading_domain = cascading_domain self.cascading_api_ip = cascading_api_ip self.cascaded_domain = cascaded_domain self.cascaded_ip = cascaded_api_ip self.gateway = cascaded_api_subnet_gateway def <|fim_middle|>(self): start_time = time.time() #pdb.set_trace() LOG.info("start config cascaded, cascaded: %s" % self.domain) # wait cascaded tunnel can visit commonutils.check_host_status(host=self.public_ip_api, user=self.user, password=self.password, retry_time=500, interval=1) # config cascaded host self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("first config success, cascaded: %s, cost time: %d" % (self.domain, cost_time)) # check config result for i in range(3): try: # check 90s commonutils.check_host_status( host=self.public_ip_api, user=constant.VcloudConstant.ROOT, password=constant.VcloudConstant.ROOT_PWD, retry_time=15, interval=1) LOG.info("cascaded api is ready..") break except exception.CheckHostStatusFailure: if i == 2: LOG.error("check cascaded api failed ...") break LOG.error("check cascaded api error, " "retry config cascaded ...") self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("config cascaded success, cascaded: %s, cost_time: %d" % (self.domain, cost_time)) def _config_az_cascaded(self): LOG.info("start config cascaded host, host: %s" % self.api_ip) # modify dns server address address = "/%(cascading_domain)s/%(cascading_ip)s,/%(cascaded_domain)s/%(cascaded_ip)s" \ % {"cascading_domain": self.cascading_domain, "cascading_ip": self.cascading_api_ip, "cascaded_domain":self.cascaded_domain, "cascaded_ip":self.cascaded_ip} for i in range(30): try: commonutils.execute_cmd_without_stdout( host=self.public_ip_api, user=self.user, password=self.password, cmd='cd %(dir)s; source /root/adminrc; sh %(script)s replace %(address)s' % {"dir": constant.PublicConstant.SCRIPTS_DIR, "script": constant.PublicConstant. MODIFY_DNS_SERVER_ADDRESS, "address": address}) break except exception.SSHCommandFailure as e: LOG.error("modify cascaded dns address error, cascaded: " "%s, error: %s" % (self.domain, e.format_message())) time.sleep(1) LOG.info( "config cascaded dns address success, cascaded: %s" % self.public_ip_api) return True <|fim▁end|>
do_config
<|file_name|>hws_cascaded_configer.py<|end_file_name|><|fim▁begin|># -*- coding:utf-8 -*- __author__ = 'q00222219@huawei' import time from heat.openstack.common import log as logging import heat.engine.resources.cloudmanager.commonutils as commonutils import heat.engine.resources.cloudmanager.constant as constant import heat.engine.resources.cloudmanager.exception as exception import pdb LOG = logging.getLogger(__name__) class CascadedConfiger(object): def __init__(self, public_ip_api, api_ip, domain, user, password, cascading_domain, cascading_api_ip, cascaded_domain, cascaded_api_ip, cascaded_api_subnet_gateway): self.public_ip_api = public_ip_api self.api_ip = api_ip self.domain = domain self.user = user self.password = password self.cascading_domain = cascading_domain self.cascading_api_ip = cascading_api_ip self.cascaded_domain = cascaded_domain self.cascaded_ip = cascaded_api_ip self.gateway = cascaded_api_subnet_gateway def do_config(self): start_time = time.time() #pdb.set_trace() LOG.info("start config cascaded, cascaded: %s" % self.domain) # wait cascaded tunnel can visit commonutils.check_host_status(host=self.public_ip_api, user=self.user, password=self.password, retry_time=500, interval=1) # config cascaded host self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("first config success, cascaded: %s, cost time: %d" % (self.domain, cost_time)) # check config result for i in range(3): try: # check 90s commonutils.check_host_status( host=self.public_ip_api, user=constant.VcloudConstant.ROOT, password=constant.VcloudConstant.ROOT_PWD, retry_time=15, interval=1) LOG.info("cascaded api is ready..") break except exception.CheckHostStatusFailure: if i == 2: LOG.error("check cascaded api failed ...") break LOG.error("check cascaded api error, " "retry config cascaded ...") self._config_az_cascaded() cost_time = time.time() - start_time LOG.info("config cascaded success, cascaded: %s, cost_time: %d" % (self.domain, cost_time)) def <|fim_middle|>(self): LOG.info("start config cascaded host, host: %s" % self.api_ip) # modify dns server address address = "/%(cascading_domain)s/%(cascading_ip)s,/%(cascaded_domain)s/%(cascaded_ip)s" \ % {"cascading_domain": self.cascading_domain, "cascading_ip": self.cascading_api_ip, "cascaded_domain":self.cascaded_domain, "cascaded_ip":self.cascaded_ip} for i in range(30): try: commonutils.execute_cmd_without_stdout( host=self.public_ip_api, user=self.user, password=self.password, cmd='cd %(dir)s; source /root/adminrc; sh %(script)s replace %(address)s' % {"dir": constant.PublicConstant.SCRIPTS_DIR, "script": constant.PublicConstant. MODIFY_DNS_SERVER_ADDRESS, "address": address}) break except exception.SSHCommandFailure as e: LOG.error("modify cascaded dns address error, cascaded: " "%s, error: %s" % (self.domain, e.format_message())) time.sleep(1) LOG.info( "config cascaded dns address success, cascaded: %s" % self.public_ip_api) return True <|fim▁end|>
_config_az_cascaded
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None<|fim▁hole|> try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e)))<|fim▁end|>
def get_commit(self): self._check_git_repo()
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): <|fim_middle|> <|fim▁end|>
def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e)))
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): <|fim_middle|> def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): <|fim_middle|> def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command)
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): <|fim_middle|> def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
return self.run("rev-parse --show-toplevel")
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): <|fim_middle|> def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): <|fim_middle|> def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false"))
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): <|fim_middle|> def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): <|fim_middle|> def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): <|fim_middle|> def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): <|fim_middle|> def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): <|fim_middle|> get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e)))
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): <|fim_middle|> def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
try: self.run("status") except Exception: raise ConanException("Not a valid git repository")
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): <|fim_middle|> <|fim▁end|>
self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e)))
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): <|fim_middle|> self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
os.makedirs(self.folder)
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: <|fim_middle|> else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
return subprocess.check_output(command, shell=True).decode().strip()
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: <|fim_middle|> def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
return self._runner(command)
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: <|fim_middle|> if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
return url
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: <|fim_middle|> user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
return url
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): <|fim_middle|> if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
url = url.replace("\\", "/") # Windows local directory
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): <|fim_middle|> else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch)
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: <|fim_middle|> output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder)
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: <|fim_middle|> return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify()
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: <|fim_middle|> # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule)
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": <|fim_middle|> elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
output += self.run("submodule sync") output += self.run("submodule update --init")
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": <|fim_middle|> else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive")
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: <|fim_middle|> # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule)
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: <|fim_middle|> except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
return url
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def <|fim_middle|>(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
__init__
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def <|fim_middle|>(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
run
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def <|fim_middle|>(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
get_repo_root
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def <|fim_middle|>(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
get_url_with_credentials
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def <|fim_middle|>(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
_configure_ssl_verify
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def <|fim_middle|>(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
clone
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def <|fim_middle|>(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
checkout
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def <|fim_middle|>(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
excluded_files
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def <|fim_middle|>(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
get_remote_url
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def <|fim_middle|>(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
get_commit
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def <|fim_middle|>(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def get_branch(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
_check_git_repo
<|file_name|>scm.py<|end_file_name|><|fim▁begin|>import os import re import subprocess from six.moves.urllib.parse import urlparse, quote_plus from subprocess import CalledProcessError, PIPE, STDOUT from conans.client.tools.env import no_op, environment_append from conans.client.tools.files import chdir from conans.errors import ConanException from conans.util.files import decode_text, to_file_bytes class Git(object): def __init__(self, folder=None, verify_ssl=True, username=None, password=None, force_english=True, runner=None): self.folder = folder or os.getcwd() if not os.path.exists(self.folder): os.makedirs(self.folder) self._verify_ssl = verify_ssl self._force_eng = force_english self._username = username self._password = password self._runner = runner def run(self, command): command = "git %s" % command with chdir(self.folder) if self.folder else no_op(): with environment_append({"LC_ALL": "en_US.UTF-8"}) if self._force_eng else no_op(): if not self._runner: return subprocess.check_output(command, shell=True).decode().strip() else: return self._runner(command) def get_repo_root(self): return self.run("rev-parse --show-toplevel") def get_url_with_credentials(self, url): if not self._username or not self._password: return url if urlparse(url).password: return url user_enc = quote_plus(self._username) pwd_enc = quote_plus(self._password) url = url.replace("://", "://" + user_enc + ":" + pwd_enc + "@", 1) return url def _configure_ssl_verify(self): return self.run("config http.sslVerify %s" % ("true" if self._verify_ssl else "false")) def clone(self, url, branch=None): url = self.get_url_with_credentials(url) if os.path.exists(url): url = url.replace("\\", "/") # Windows local directory if os.path.exists(self.folder) and os.listdir(self.folder): if not branch: raise ConanException("The destination folder '%s' is not empty, " "specify a branch to checkout (not a tag or commit) " "or specify a 'subfolder' " "attribute in the 'scm'" % self.folder) output = self.run("init") output += self._configure_ssl_verify() output += self.run('remote add origin "%s"' % url) output += self.run("fetch ") output += self.run("checkout -t origin/%s" % branch) else: branch_cmd = "--branch %s" % branch if branch else "" output = self.run('clone "%s" . %s' % (url, branch_cmd)) output += self._configure_ssl_verify() return output def checkout(self, element, submodule=None): self._check_git_repo() output = self.run('checkout "%s"' % element) if submodule: if submodule == "shallow": output += self.run("submodule sync") output += self.run("submodule update --init") elif submodule == "recursive": output += self.run("submodule sync --recursive") output += self.run("submodule update --init --recursive") else: raise ConanException("Invalid 'submodule' attribute value in the 'scm'. " "Unknown value '%s'. Allowed values: ['shallow', 'recursive']" % submodule) # Element can be a tag, branch or commit return output def excluded_files(self): try: file_paths = [os.path.normpath(os.path.join(os.path.relpath(folder, self.folder), el)).replace("\\", "/") for folder, dirpaths, fs in os.walk(self.folder) for el in fs + dirpaths] p = subprocess.Popen(['git', 'check-ignore', '--stdin'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, cwd=self.folder) paths = to_file_bytes("\n".join(file_paths)) grep_stdout = decode_text(p.communicate(input=paths)[0]) tmp = grep_stdout.splitlines() except CalledProcessError: tmp = [] return tmp def get_remote_url(self, remote_name=None): self._check_git_repo() remote_name = remote_name or "origin" try: remotes = self.run("remote -v") for remote in remotes.splitlines(): try: name, url = remote.split(None, 1) url, _ = url.rsplit(None, 1) if name == remote_name: return url except Exception: pass except subprocess.CalledProcessError: pass return None def get_commit(self): self._check_git_repo() try: commit = self.run("rev-parse HEAD") commit = commit.strip() return commit except Exception as e: raise ConanException("Unable to get git commit from %s\n%s" % (self.folder, str(e))) get_revision = get_commit def _check_git_repo(self): try: self.run("status") except Exception: raise ConanException("Not a valid git repository") def <|fim_middle|>(self): self._check_git_repo() try: status = self.run("status -bs --porcelain") # ## feature/scm_branch...myorigin/feature/scm_branch branch = status.splitlines()[0].split("...")[0].strip("#").strip() return branch except Exception as e: raise ConanException("Unable to get git branch from %s\n%s" % (self.folder, str(e))) <|fim▁end|>
get_branch
<|file_name|>setup.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from distutils.core import setup import os.path classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "Operating System :: OS Independent", "Topic :: Software Development :: Libraries :: Python Modules", ]<|fim▁hole|> def read(fname): fname = os.path.join(os.path.dirname(__file__), fname) return open(fname).read().strip() def read_files(*fnames): return '\r\n\r\n\r\n'.join(map(read, fnames)) setup( name = 'icall', version = '0.3.4', py_modules = ['icall'], description = 'Parameters call function, :-)', long_description = read_files('README.rst', 'CHANGES.rst'), author = 'huyx', author_email = '[email protected]', url = 'https://github.com/huyx/icall', keywords = ['functools', 'function', 'call'], classifiers = classifiers, )<|fim▁end|>
<|file_name|>setup.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from distutils.core import setup import os.path classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "Operating System :: OS Independent", "Topic :: Software Development :: Libraries :: Python Modules", ] def read(fname): <|fim_middle|> def read_files(*fnames): return '\r\n\r\n\r\n'.join(map(read, fnames)) setup( name = 'icall', version = '0.3.4', py_modules = ['icall'], description = 'Parameters call function, :-)', long_description = read_files('README.rst', 'CHANGES.rst'), author = 'huyx', author_email = '[email protected]', url = 'https://github.com/huyx/icall', keywords = ['functools', 'function', 'call'], classifiers = classifiers, ) <|fim▁end|>
fname = os.path.join(os.path.dirname(__file__), fname) return open(fname).read().strip()
<|file_name|>setup.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from distutils.core import setup import os.path classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "Operating System :: OS Independent", "Topic :: Software Development :: Libraries :: Python Modules", ] def read(fname): fname = os.path.join(os.path.dirname(__file__), fname) return open(fname).read().strip() def read_files(*fnames): <|fim_middle|> setup( name = 'icall', version = '0.3.4', py_modules = ['icall'], description = 'Parameters call function, :-)', long_description = read_files('README.rst', 'CHANGES.rst'), author = 'huyx', author_email = '[email protected]', url = 'https://github.com/huyx/icall', keywords = ['functools', 'function', 'call'], classifiers = classifiers, ) <|fim▁end|>
return '\r\n\r\n\r\n'.join(map(read, fnames))
<|file_name|>setup.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from distutils.core import setup import os.path classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "Operating System :: OS Independent", "Topic :: Software Development :: Libraries :: Python Modules", ] def <|fim_middle|>(fname): fname = os.path.join(os.path.dirname(__file__), fname) return open(fname).read().strip() def read_files(*fnames): return '\r\n\r\n\r\n'.join(map(read, fnames)) setup( name = 'icall', version = '0.3.4', py_modules = ['icall'], description = 'Parameters call function, :-)', long_description = read_files('README.rst', 'CHANGES.rst'), author = 'huyx', author_email = '[email protected]', url = 'https://github.com/huyx/icall', keywords = ['functools', 'function', 'call'], classifiers = classifiers, ) <|fim▁end|>
read
<|file_name|>setup.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- from distutils.core import setup import os.path classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "Operating System :: OS Independent", "Topic :: Software Development :: Libraries :: Python Modules", ] def read(fname): fname = os.path.join(os.path.dirname(__file__), fname) return open(fname).read().strip() def <|fim_middle|>(*fnames): return '\r\n\r\n\r\n'.join(map(read, fnames)) setup( name = 'icall', version = '0.3.4', py_modules = ['icall'], description = 'Parameters call function, :-)', long_description = read_files('README.rst', 'CHANGES.rst'), author = 'huyx', author_email = '[email protected]', url = 'https://github.com/huyx/icall', keywords = ['functools', 'function', 'call'], classifiers = classifiers, ) <|fim▁end|>
read_files
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer):<|fim▁hole|> media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected)<|fim▁end|>
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): <|fim_middle|> class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
media_type = 'application/json; api-version="1.0"'
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): <|fim_middle|> @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
media_type = 'application/json; api-version="2.0"'
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): <|fim_middle|> @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): <|fim_middle|> @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): <|fim_middle|> @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): <|fim_middle|> @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
raise exceptions.PermissionDenied()
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): <|fim_middle|> @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
abort(status.HTTP_403_FORBIDDEN)
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): <|fim_middle|> @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
return {}
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): <|fim_middle|> class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
return {'accepted_media_type': str(request.accepted_media_type)}
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): <|fim_middle|> <|fim▁end|>
def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected)
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): <|fim_middle|> def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected)
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): <|fim_middle|> def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected)
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): <|fim_middle|> def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected)
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): <|fim_middle|> def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected)
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): <|fim_middle|> def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): <|fim_middle|> def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data()
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): <|fim_middle|> <|fim▁end|>
with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected)
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def <|fim_middle|>(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
set_status_and_headers
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def <|fim_middle|>(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
set_headers
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def <|fim_middle|>(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
make_response_view
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def <|fim_middle|>(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
api_exception
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def <|fim_middle|>(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
abort_view
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def <|fim_middle|>(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
options_view
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def <|fim_middle|>(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
accepted_media_type
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def <|fim_middle|>(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
test_set_status_and_headers
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def <|fim_middle|>(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
test_set_headers
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def <|fim_middle|>(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
test_make_response
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def <|fim_middle|>(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
test_api_exception
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def <|fim_middle|>(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
test_abort_view
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def <|fim_middle|>(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def test_accepted_media_type_property(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
test_options_view
<|file_name|>test_app.py<|end_file_name|><|fim▁begin|># coding: utf8 from __future__ import unicode_literals from flask import abort, make_response, request from flask_api.decorators import set_renderers from flask_api import exceptions, renderers, status, FlaskAPI import json import unittest app = FlaskAPI(__name__) app.config['TESTING'] = True class JSONVersion1(renderers.JSONRenderer): media_type = 'application/json; api-version="1.0"' class JSONVersion2(renderers.JSONRenderer): media_type = 'application/json; api-version="2.0"' @app.route('/set_status_and_headers/') def set_status_and_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, status.HTTP_201_CREATED, headers @app.route('/set_headers/') def set_headers(): headers = {'Location': 'http://example.com/456'} return {'example': 'content'}, headers @app.route('/make_response_view/') def make_response_view(): response = make_response({'example': 'content'}) response.headers['Location'] = 'http://example.com/456' return response @app.route('/api_exception/') def api_exception(): raise exceptions.PermissionDenied() @app.route('/abort_view/') def abort_view(): abort(status.HTTP_403_FORBIDDEN) @app.route('/options/') def options_view(): return {} @app.route('/accepted_media_type/') @set_renderers([JSONVersion2, JSONVersion1]) def accepted_media_type(): return {'accepted_media_type': str(request.accepted_media_type)} class AppTests(unittest.TestCase): def test_set_status_and_headers(self): with app.test_client() as client: response = client.get('/set_status_and_headers/') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_set_headers(self): with app.test_client() as client: response = client.get('/set_headers/') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_make_response(self): with app.test_client() as client: response = client.get('/make_response_view/') self.assertEqual(response.content_type, 'application/json') self.assertEqual(response.headers['Location'], 'http://example.com/456') self.assertEqual(response.content_type, 'application/json') expected = '{"example": "content"}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_api_exception(self): with app.test_client() as client: response = client.get('/api_exception/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.content_type, 'application/json') expected = '{"message": "You do not have permission to perform this action."}' self.assertEqual(response.get_data().decode('utf8'), expected) def test_abort_view(self): with app.test_client() as client: response = client.get('/abort_view/') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) def test_options_view(self): with app.test_client() as client: response = client.options('/options/') # Errors if `response.response` is `None` response.get_data() def <|fim_middle|>(self): with app.test_client() as client: # Explicitly request the "api-version 1.0" renderer. headers = {'Accept': 'application/json; api-version="1.0"'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="1.0"'} self.assertEqual(data, expected) # Request the default renderer, which is "api-version 2.0". headers = {'Accept': '*/*'} response = client.get('/accepted_media_type/', headers=headers) data = json.loads(response.get_data().decode('utf8')) expected = {'accepted_media_type': 'application/json; api-version="2.0"'} self.assertEqual(data, expected) <|fim▁end|>
test_accepted_media_type_property
<|file_name|>fifa_spider.py<|end_file_name|><|fim▁begin|>from scrapy.spiders import Spider from scrapy.selector import Selector from scrapy.http import HtmlResponse from FIFAscrape.items import PlayerItem from urlparse import urlparse, urljoin from scrapy.http.request import Request from scrapy.conf import settings import random import time class fifaSpider(Spider): name = "fifa" allowed_domains = ["futhead.com"] start_urls = [ "http://www.futhead.com/16/players/?level=all_nif&bin_platform=ps" ] def parse(self, response): #obtains links from page to page and passes links to parse_playerURL sel = Selector(response) #define selector based on response object (points to urls in start_urls by default) url_list = sel.xpath('//a[@class="display-block padding-0"]/@href') #obtain a list of href links that contain relative links of players for i in url_list: relative_url = self.clean_str(i.extract()) #i is a selector and hence need to extract it to obtain unicode object print urljoin(response.url, relative_url) #urljoin is able to merge absolute and relative paths to form 1 coherent link req = Request(urljoin(response.url, relative_url),callback=self.parse_playerURL) #pass on request with new urls to parse_playerURL req.headers["User-Agent"] = self.random_ua() yield req next_url=sel.xpath('//div[@class="right-nav pull-right"]/a[@rel="next"]/@href').extract_first() if(next_url): #checks if next page exists clean_next_url = self.clean_str(next_url) reqNext = Request(urljoin(response.url, clean_next_url),callback=self.parse) #calls back this function to repeat process on new list of links yield reqNext def parse_playerURL(self, response): #parses player specific data into items list site = Selector(response) items = [] item = PlayerItem() item['1name'] = (response.url).rsplit("/")[-2].replace("-"," ") title = self.clean_str(site.xpath('/html/head/title/text()').extract_first()) item['OVR'] = title.partition("FIFA 16 -")[1].split("-")[0] item['POS'] = self.clean_str(site.xpath('//div[@class="playercard-position"]/text()').extract_first()) #stats = site.xpath('//div[@class="row player-center-container"]/div/a') stat_names = site.xpath('//span[@class="player-stat-title"]') stat_values = site.xpath('//span[contains(@class, "player-stat-value")]') for index in range(len(stat_names)): attr_name = stat_names[index].xpath('.//text()').extract_first() item[attr_name] = stat_values[index].xpath('.//text()').extract_first() <|fim▁hole|> items.append(item) return items def clean_str(self,ustring): #removes wierd unicode chars (/u102 bla), whitespaces, tabspaces, etc to form clean string return str(ustring.encode('ascii', 'replace')).strip() def random_ua(self): #randomise user-agent from list to reduce chance of being banned ua = random.choice(settings.get('USER_AGENT_LIST')) if ua: ua='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2226.0 Safari/537.36' return ua<|fim▁end|>
<|file_name|>fifa_spider.py<|end_file_name|><|fim▁begin|>from scrapy.spiders import Spider from scrapy.selector import Selector from scrapy.http import HtmlResponse from FIFAscrape.items import PlayerItem from urlparse import urlparse, urljoin from scrapy.http.request import Request from scrapy.conf import settings import random import time class fifaSpider(Spider): <|fim_middle|> <|fim▁end|>
name = "fifa" allowed_domains = ["futhead.com"] start_urls = [ "http://www.futhead.com/16/players/?level=all_nif&bin_platform=ps" ] def parse(self, response): #obtains links from page to page and passes links to parse_playerURL sel = Selector(response) #define selector based on response object (points to urls in start_urls by default) url_list = sel.xpath('//a[@class="display-block padding-0"]/@href') #obtain a list of href links that contain relative links of players for i in url_list: relative_url = self.clean_str(i.extract()) #i is a selector and hence need to extract it to obtain unicode object print urljoin(response.url, relative_url) #urljoin is able to merge absolute and relative paths to form 1 coherent link req = Request(urljoin(response.url, relative_url),callback=self.parse_playerURL) #pass on request with new urls to parse_playerURL req.headers["User-Agent"] = self.random_ua() yield req next_url=sel.xpath('//div[@class="right-nav pull-right"]/a[@rel="next"]/@href').extract_first() if(next_url): #checks if next page exists clean_next_url = self.clean_str(next_url) reqNext = Request(urljoin(response.url, clean_next_url),callback=self.parse) #calls back this function to repeat process on new list of links yield reqNext def parse_playerURL(self, response): #parses player specific data into items list site = Selector(response) items = [] item = PlayerItem() item['1name'] = (response.url).rsplit("/")[-2].replace("-"," ") title = self.clean_str(site.xpath('/html/head/title/text()').extract_first()) item['OVR'] = title.partition("FIFA 16 -")[1].split("-")[0] item['POS'] = self.clean_str(site.xpath('//div[@class="playercard-position"]/text()').extract_first()) #stats = site.xpath('//div[@class="row player-center-container"]/div/a') stat_names = site.xpath('//span[@class="player-stat-title"]') stat_values = site.xpath('//span[contains(@class, "player-stat-value")]') for index in range(len(stat_names)): attr_name = stat_names[index].xpath('.//text()').extract_first() item[attr_name] = stat_values[index].xpath('.//text()').extract_first() items.append(item) return items def clean_str(self,ustring): #removes wierd unicode chars (/u102 bla), whitespaces, tabspaces, etc to form clean string return str(ustring.encode('ascii', 'replace')).strip() def random_ua(self): #randomise user-agent from list to reduce chance of being banned ua = random.choice(settings.get('USER_AGENT_LIST')) if ua: ua='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2226.0 Safari/537.36' return ua
<|file_name|>fifa_spider.py<|end_file_name|><|fim▁begin|>from scrapy.spiders import Spider from scrapy.selector import Selector from scrapy.http import HtmlResponse from FIFAscrape.items import PlayerItem from urlparse import urlparse, urljoin from scrapy.http.request import Request from scrapy.conf import settings import random import time class fifaSpider(Spider): name = "fifa" allowed_domains = ["futhead.com"] start_urls = [ "http://www.futhead.com/16/players/?level=all_nif&bin_platform=ps" ] def parse(self, response): #obtains links from page to page and passes links to parse_playerURL <|fim_middle|> def parse_playerURL(self, response): #parses player specific data into items list site = Selector(response) items = [] item = PlayerItem() item['1name'] = (response.url).rsplit("/")[-2].replace("-"," ") title = self.clean_str(site.xpath('/html/head/title/text()').extract_first()) item['OVR'] = title.partition("FIFA 16 -")[1].split("-")[0] item['POS'] = self.clean_str(site.xpath('//div[@class="playercard-position"]/text()').extract_first()) #stats = site.xpath('//div[@class="row player-center-container"]/div/a') stat_names = site.xpath('//span[@class="player-stat-title"]') stat_values = site.xpath('//span[contains(@class, "player-stat-value")]') for index in range(len(stat_names)): attr_name = stat_names[index].xpath('.//text()').extract_first() item[attr_name] = stat_values[index].xpath('.//text()').extract_first() items.append(item) return items def clean_str(self,ustring): #removes wierd unicode chars (/u102 bla), whitespaces, tabspaces, etc to form clean string return str(ustring.encode('ascii', 'replace')).strip() def random_ua(self): #randomise user-agent from list to reduce chance of being banned ua = random.choice(settings.get('USER_AGENT_LIST')) if ua: ua='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2226.0 Safari/537.36' return ua <|fim▁end|>
sel = Selector(response) #define selector based on response object (points to urls in start_urls by default) url_list = sel.xpath('//a[@class="display-block padding-0"]/@href') #obtain a list of href links that contain relative links of players for i in url_list: relative_url = self.clean_str(i.extract()) #i is a selector and hence need to extract it to obtain unicode object print urljoin(response.url, relative_url) #urljoin is able to merge absolute and relative paths to form 1 coherent link req = Request(urljoin(response.url, relative_url),callback=self.parse_playerURL) #pass on request with new urls to parse_playerURL req.headers["User-Agent"] = self.random_ua() yield req next_url=sel.xpath('//div[@class="right-nav pull-right"]/a[@rel="next"]/@href').extract_first() if(next_url): #checks if next page exists clean_next_url = self.clean_str(next_url) reqNext = Request(urljoin(response.url, clean_next_url),callback=self.parse) #calls back this function to repeat process on new list of links yield reqNext